-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgeneric_test.go
49 lines (39 loc) · 842 Bytes
/
generic_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
package gogu
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// Compare compares two values using as comparator the callback function argument.
func TestCompare(t *testing.T) {
assert := assert.New(t)
res := Compare(1, 2, func(a, b int) bool {
return a < b
})
assert.Equal(1, res)
}
func Example_compare() {
res1 := Compare(1, 2, func(a, b int) bool {
return a < b
})
fmt.Println(res1)
res2 := Compare("a", "b", func(a, b string) bool {
return a > b
})
fmt.Println(res2)
// Output:
// 1
// -1
}
// Equal checks if two values are equal.
func TestEqual(t *testing.T) {
assert := assert.New(t)
assert.True(Equal(1, 1))
assert.False(Equal("a", "b"))
assert.False(Equal("a", "A"))
}
func TestLess(t *testing.T) {
assert := assert.New(t)
assert.True(Less(1, 2))
assert.False(Less("b", "a"))
}