-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_test.go
More file actions
43 lines (35 loc) · 782 Bytes
/
string_test.go
File metadata and controls
43 lines (35 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package isodd
import "testing"
func TestString(t *testing.T) {
type testcase struct {
num string
isOdd bool
err error
}
testCases := []testcase{
{"1", true, nil},
{"0", false, nil},
{"2", false, nil},
{"-200000", false, nil},
{"-999999", true, nil},
}
for _, test := range testCases {
isOdd, err := String(test.num)
if isOdd != test.isOdd || err != test.err {
t.Fatalf("[TestString] {string: %s, err: %v} failed", test.num, err)
}
}
testCasesErr := []testcase{
{num: "1.232"},
{num: "asdasds"},
{num: "1-"},
{num: "xx1"},
{num: " 1232"},
}
for _, test := range testCasesErr {
isOdd, err := String(test.num)
if isOdd != false || err == nil {
t.Fatalf("[TestString] {string: %s, err: %v} failed", test.num, err)
}
}
}