-
Notifications
You must be signed in to change notification settings - Fork 147
/
t_searching_test.go
54 lines (46 loc) · 1.17 KB
/
t_searching_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
// Copyright 2016 The Gosl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package utl
import (
"testing"
"github.com/cpmech/gosl/chk"
"github.com/cpmech/gosl/io"
)
func Test_search01(tst *testing.T) {
//verbose()
chk.PrintTitle("search01")
a := []string{"66", "644", "666", "653", "10", "0", "1", "1", "1"}
idx := StrIndexSmall(a, "666")
io.Pf("a = %v\n", a)
io.Pf("idx of '666' = %v\n", idx)
if idx != 2 {
tst.Errorf("idx is wrong")
return
}
idx = StrIndexSmall(a, "1")
io.Pf("idx of '1' = %v\n", idx)
if idx != 6 {
tst.Errorf("idx is wrong")
return
}
b := []int{66, 644, 666, 653, 10, 0, 1, 1, 1}
idx = IntIndexSmall(b, 666)
io.Pf("b = %v\n", b)
io.Pf("idx of 666 = %v\n", idx)
if idx != 2 {
tst.Errorf("idx is wrong")
return
}
idx = IntIndexSmall(b, 1)
io.Pf("idx of 1 = %v\n", idx)
if idx != 6 {
tst.Errorf("idx is wrong")
return
}
// TODO: finish this
//jdx, bsorted := IntIndexSorted(b, 666, nil)
//io.Pforan("\njdx = %v\n", jdx)
//io.Pforan("bsorted = %v\n", bsorted)
//chk.Ints(tst, "bsorted", bsorted, []int{0, 1, 1, 1, 10, 66, 644, 653, 666})
}