-
-
Notifications
You must be signed in to change notification settings - Fork 654
/
change_test.go
43 lines (40 loc) · 1010 Bytes
/
change_test.go
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 change
import (
"reflect"
"testing"
)
func TestChange(t *testing.T) {
for _, tc := range testCases {
actual, err := Change(tc.coins, tc.target)
if tc.valid {
if err != nil {
t.Fatalf("%s : Change(%v, %d): expected %v, got error %s",
tc.description, tc.coins, tc.target, tc.expectedChange, err.Error())
} else {
if !reflect.DeepEqual(actual, tc.expectedChange) {
t.Fatalf("%s : Change(%v, %d): expected %#v, actual %#v",
tc.description, tc.coins, tc.target, tc.expectedChange, actual)
} else {
t.Logf("PASS: %s", tc.description)
}
}
} else {
if err == nil {
t.Fatalf("%s : Change(%v, %d): expected error, got %v",
tc.description, tc.coins, tc.target, actual)
} else {
t.Logf("PASS: %s", tc.description)
}
}
}
}
func BenchmarkChange(b *testing.B) {
if testing.Short() {
b.Skip("skipping benchmark in short mode.")
}
for i := 0; i < b.N; i++ {
for _, tc := range testCases {
Change(tc.coins, tc.target)
}
}
}