-
Notifications
You must be signed in to change notification settings - Fork 2
/
tern_test.go
122 lines (108 loc) · 2.26 KB
/
tern_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package tern_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/yyle88/tern"
)
func TestBVV(t *testing.T) {
require.Equal(t, 1, tern.BVV(true, 1, 2))
require.Equal(t, 2, tern.BVV(false, 1, 2))
}
func TestBVF(t *testing.T) {
run := func() string {
return "b"
}
require.Equal(t, "a", tern.BVF(true, "a", run))
require.Equal(t, "b", tern.BVF(false, "a", run))
}
func TestBFV(t *testing.T) {
run := func() float64 {
return 1.0
}
require.Equal(t, 1.0, tern.BFV(true, run, 2.0))
require.Equal(t, 2.0, tern.BFV(false, run, 2.0))
}
func TestBFF(t *testing.T) {
run1 := func() float64 {
return 1.0
}
run2 := func() float64 {
return 2.0
}
require.Equal(t, 1.0, tern.BFF(true, run1, run2))
require.Equal(t, 2.0, tern.BFF(false, run1, run2))
}
func TestFVV(t *testing.T) {
require.Equal(t, 1, tern.FVV(func() bool {
return true
}, 1, 2))
require.Equal(t, 2, tern.FVV(func() bool {
return false
}, 1, 2))
}
func TestFVF(t *testing.T) {
run := func() string {
return "b"
}
require.Equal(t, "a", tern.FVF(func() bool {
return true
}, "a", run))
require.Equal(t, "b", tern.FVF(func() bool {
return false
}, "a", run))
}
func TestFFV(t *testing.T) {
run := func() float64 {
return 1.0
}
require.Equal(t, 1.0, tern.FFV(func() bool {
return true
}, run, 2.0))
require.Equal(t, 2.0, tern.FFV(func() bool {
return false
}, run, 2.0))
}
func TestFFF(t *testing.T) {
run1 := func() float64 {
return 1.0
}
run2 := func() float64 {
return 2.0
}
require.Equal(t, 1.0, tern.FFF(func() bool {
return true
}, run1, run2))
require.Equal(t, 2.0, tern.FFF(func() bool {
return false
}, run1, run2))
}
func TestBV(t *testing.T) {
require.Equal(t, 1, tern.BV(true, 1))
require.Equal(t, 0, tern.BV(false, 1))
}
func TestBF(t *testing.T) {
run := func() string {
return "a"
}
require.Equal(t, "a", tern.BF(true, run))
require.Equal(t, "", tern.BF(false, run))
}
func TestFV(t *testing.T) {
require.Equal(t, 1, tern.FV(func() bool {
return true
}, 1))
require.Equal(t, 0, tern.FV(func() bool {
return false
}, 1))
}
func TestFF(t *testing.T) {
run := func() string {
return "a"
}
require.Equal(t, "a", tern.FF(func() bool {
return true
}, run))
require.Equal(t, "", tern.FF(func() bool {
return false
}, run))
}