-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
min_test.go
48 lines (42 loc) · 827 Bytes
/
min_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
package linq_test
import (
"math"
"testing"
"github.com/makiuchi-d/linq/v2"
)
func TestMin(t *testing.T) {
src := []byte{
189, 47, 155, 170, 155, 99, 136, 3, 161, 231,
}
r, err := linq.Min(linq.FromSlice(src))
if err != nil {
t.Fatalf("%v", err)
}
exp := byte(3)
if r != exp {
t.Fatalf("%v, wants %v", r, exp)
}
r, err = linq.MinBy(linq.FromSlice(src), func(v byte) (float64, error) {
return math.Abs(float64(v) - 100), nil
})
if err != nil {
t.Fatalf("%v", err)
}
exp = byte(99)
if r != exp {
t.Fatalf("%v, wants %v", r, exp)
}
r, err = linq.MinByFunc(linq.FromSlice(src), func(a, b byte) (bool, error) {
if a%2 != b%2 {
return a%2 == 0, nil
}
return a < b, nil
})
if err != nil {
t.Fatalf("%v", err)
}
exp = byte(136)
if r != exp {
t.Fatalf("%v, wants %v", r, exp)
}
}