-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynthesis_test.go
79 lines (69 loc) · 2.29 KB
/
synthesis_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package qkit_test
import (
"fmt"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
qkit "github.com/clubpay/qlubkit-go"
)
func TestCoalesce(t *testing.T) {
type testCase[T comparable] struct {
in []T
out T
}
Convey("String Coalesce", t, func(c C) {
cases := []testCase[string]{
{in: []string{""}, out: ""},
{in: []string{"1st"}, out: "1st"},
{in: []string{"", ""}, out: ""},
{in: []string{"1st", ""}, out: "1st"},
{in: []string{"1st", "2nd"}, out: "1st"},
{in: []string{"", "2nd"}, out: "2nd"},
{in: []string{"", "", ""}, out: ""},
{in: []string{"1st", "", ""}, out: "1st"},
{in: []string{"1st", "2nd", ""}, out: "1st"},
{in: []string{"1st", "2nd", "3rd"}, out: "1st"},
{in: []string{"1st", "", "3rd"}, out: "1st"},
{in: []string{"", "2nd", ""}, out: "2nd"},
{in: []string{"", "2nd", "3rd"}, out: "2nd"},
{in: []string{"", "", "3rd"}, out: "3rd"},
}
for _, tc := range cases {
c.SoMsg(fmt.Sprintf("%+v", tc.in), qkit.Coalesce(tc.in...), ShouldEqual, tc.out)
}
})
Convey("Int Coalesce", t, func(c C) {
cases := []testCase[int]{
{in: []int{0}, out: 0},
{in: []int{1}, out: 1},
{in: []int{0, 0}, out: 0},
{in: []int{1, 0}, out: 1},
{in: []int{1, 2}, out: 1},
{in: []int{0, 2}, out: 2},
{in: []int{0, 0, 0}, out: 0},
{in: []int{1, 0, 0}, out: 1},
{in: []int{1, 2, 0}, out: 1},
{in: []int{1, 2, 3}, out: 1},
{in: []int{1, 0, 3}, out: 1},
{in: []int{0, 2, 0}, out: 2},
{in: []int{0, 2, 3}, out: 2},
{in: []int{0, 0, 3}, out: 3},
}
for _, tc := range cases {
c.SoMsg(fmt.Sprintf("%+v", tc.in), qkit.Coalesce(tc.in...), ShouldEqual, tc.out)
}
})
Convey("Duration Coalesce", t, func(c C) {
cases := []testCase[time.Duration]{
{in: []time.Duration{0 * time.Second}, out: 0 * time.Second},
{in: []time.Duration{1 * time.Second}, out: 1 * time.Second},
{in: []time.Duration{0 * time.Second, 0 * time.Second}, out: 0 * time.Second},
{in: []time.Duration{1 * time.Second, 0 * time.Second}, out: 1 * time.Second},
{in: []time.Duration{1 * time.Second, 2 * time.Second}, out: 1 * time.Second},
{in: []time.Duration{0 * time.Second, 2 * time.Second}, out: 2 * time.Second},
}
for _, tc := range cases {
c.SoMsg(fmt.Sprintf("%+v", tc.in), qkit.Coalesce(tc.in...), ShouldEqual, tc.out)
}
})
}