Skip to content

Commit

Permalink
Added a bunch more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odino committed Sep 18, 2019
1 parent be6ed0b commit ae2941c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions util/util_test.go
Expand Up @@ -26,3 +26,53 @@ func TestUnaliasPath(t *testing.T) {
}
}
}

func TestUniqueStrings(t *testing.T) {
tests := []struct {
strings []string
len int
}{
{[]string{"a", "b", "c"}, 3},
{[]string{"a", "a", "a"}, 1},
}

for _, tt := range tests {
if len(UniqueStrings(tt.strings)) != tt.len {
t.Fatalf("expected %d, got %d", tt.len, len(UniqueStrings(tt.strings)))
}
}
}

func TestContains(t *testing.T) {
tests := []struct {
strings []string
match string
expected bool
}{
{[]string{"a", "b", "c"}, "a", true},
{[]string{"a", "a", "a"}, "d", false},
}

for _, tt := range tests {
if tt.expected != Contains(tt.strings, tt.match) {
t.Fatalf("expected %v", tt.expected)
}
}
}

func TestIsNumber(t *testing.T) {
tests := []struct {
number string
expected bool
}{
{"12", true},
{"12a", false},
{"12.2", true},
}

for _, tt := range tests {
if tt.expected != IsNumber(tt.number) {
t.Fatalf("expected %v (%s)", tt.expected, tt.number)
}
}
}

0 comments on commit ae2941c

Please sign in to comment.