collections_test.go

 1package collections
 2
 3import (
 4	"reflect"
 5	"testing"
 6)
 7
 8func TestUniqueRemovesDuplicates(t *testing.T) {
 9	t.Run("With strings", func(t *testing.T) {
10		got := Unique([]string{"acct-1", "acct-2", "acct-1", "", "acct-3", ""})
11		want := []string{"acct-1", "acct-2", "", "acct-3"}
12		if !reflect.DeepEqual(got, want) {
13			t.Fatalf("Unique() = %#v, want %#v", got, want)
14		}
15	})
16
17	t.Run("With ints", func(t *testing.T) {
18		got := Unique([]int{1, 2, 1, 0, 3, 0})
19		want := []int{1, 2, 0, 3}
20		if !reflect.DeepEqual(got, want) {
21			t.Fatalf("Unique() = %#v, want %#v", got, want)
22		}
23	})
24}
25
26func TestUniqueNonEmptyRemovesZeroValuesAndDuplicates(t *testing.T) {
27	t.Run("With strings", func(t *testing.T) {
28		got := UniqueNonEmpty([]string{"", "acct-1", "acct-2", "acct-1", "", "acct-3"})
29		want := []string{"acct-1", "acct-2", "acct-3"}
30		if !reflect.DeepEqual(got, want) {
31			t.Fatalf("UniqueNonEmpty() = %#v, want %#v", got, want)
32		}
33	})
34
35	t.Run("With ints", func(t *testing.T) {
36		got := UniqueNonEmpty([]int{0, 1, 2, 1, 0, 3})
37		want := []int{1, 2, 3}
38		if !reflect.DeepEqual(got, want) {
39			t.Fatalf("UniqueNonEmpty() = %#v, want %#v", got, want)
40		}
41	})
42}