Skip to content

Instantly share code, notes, and snippets.

@eexit
Created July 7, 2020 20:19
Show Gist options
  • Save eexit/3ac22b378991a879282a9d9bd5c6baf4 to your computer and use it in GitHub Desktop.
Save eexit/3ac22b378991a879282a9d9bd5c6baf4 to your computer and use it in GitHub Desktop.

Revisions

  1. eexit created this gist Jul 7, 2020.
    15 changes: 15 additions & 0 deletions out.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    === RUN Test_remove
    === RUN Test_remove/want_and_list_are_empty
    === RUN Test_remove/list_is_empty
    === RUN Test_remove/list_contains_only_one_occurence_of_wanted
    === RUN Test_remove/list_contains_only_occurences_of_wanted
    === RUN Test_remove/list_contains_one_occurence_of_wanted
    === RUN Test_remove/list_does_not_contain_occurence_of_wanted
    --- PASS: Test_remove (0.00s)
    --- PASS: Test_remove/want_and_list_are_empty (0.00s)
    --- PASS: Test_remove/list_is_empty (0.00s)
    --- PASS: Test_remove/list_contains_only_one_occurence_of_wanted (0.00s)
    --- PASS: Test_remove/list_contains_only_occurences_of_wanted (0.00s)
    --- PASS: Test_remove/list_contains_one_occurence_of_wanted (0.00s)
    --- PASS: Test_remove/list_does_not_contain_occurence_of_wanted (0.00s)
    PASS
    12 changes: 12 additions & 0 deletions remove.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    package remove

    // remove loops over a slice of strings and remove want
    func remove(want string, list []string) []string {
    out := []string{}
    for _, e := range list {
    if e != want {
    out = append(out, e)
    }
    }
    return out
    }
    56 changes: 56 additions & 0 deletions remove_test.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    package remove

    import (
    "reflect"
    "testing"
    )

    func Test_remove(t *testing.T) {
    type args struct {
    want string
    list []string
    }
    tests := []struct {
    name string
    args args
    want []string
    }{
    {
    name: "want and list are empty",
    args: args{want: "", list: []string{}},
    want: []string{},
    },
    {
    name: "list is empty",
    args: args{want: "a", list: []string{}},
    want: []string{},
    },
    {
    name: "list contains only one occurence of wanted",
    args: args{want: "a", list: []string{"a"}},
    want: []string{},
    },
    {
    name: "list contains only occurences of wanted",
    args: args{want: "a", list: []string{"a", "a", "a"}},
    want: []string{},
    },
    {
    name: "list contains one occurence of wanted",
    args: args{want: "a", list: []string{"b", "a", "c"}},
    want: []string{"b", "c"},
    },
    {
    name: "list does not contain occurence of wanted",
    args: args{want: "a", list: []string{"b", "c", "d"}},
    want: []string{"b", "c", "d"},
    },
    }
    for _, tt := range tests {
    t.Run(tt.name, func(t *testing.T) {
    if got := remove(tt.args.want, tt.args.list); !reflect.DeepEqual(got, tt.want) {
    t.Errorf("remove() = %v, want %v", got, tt.want)
    }
    })
    }
    }