This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
/
strings_test.go
109 lines (87 loc) · 2.03 KB
/
strings_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
// Copyright 2016-2018 Shulhan <ms@kilabit.info>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tekstus_test
import (
"github.com/shuLhan/tekstus"
"testing"
)
func TestStringsIsEqual(t *testing.T) {
lss := tekstus.ListStrings{
{"c", "b"},
{"c", "a"},
}
check := []bool{true, false}
for x, ss := range lss {
b := tssExp[0][1].IsEqual(ss)
if b != check[x] {
t.Fatal(tssExp[0][1], " == ", ss, "? ", b)
}
}
}
func TestStringsIsContain(t *testing.T) {
ss := tekstus.Strings{
"a", "b", "c", "d",
}
ss2 := []string{
"a", "b", "c", "d",
}
// Testing true positive
got := tekstus.StringsIsContain(ss, "a")
assert(t, true, got, true)
// Testing true negative
got = tekstus.StringsIsContain(ss, "e")
assert(t, false, got, true)
// Testing true positive
got = tekstus.StringsIsContain(ss2, "a")
assert(t, true, got, true)
// Testing true negative
got = tekstus.StringsIsContain(ss2, "e")
assert(t, false, got, true)
}
func TestPartitioning(t *testing.T) {
lss := tekstus.ListStrings{
{"a", "b", "c"},
}
tssExp := []tekstus.TableStrings{{
{{"a", "b", "c"}},
}, {
{{"a", "b"}, {"c"}},
{{"b"}, {"a", "c"}},
{{"a"}, {"b", "c"}},
}, {
{{"a"}, {"b"}, {"c"}},
},
}
split := []int{1, 2, 3}
for _, ss := range lss {
for k := range split {
setstr := ss.Partitioning(split[k])
b := tssExp[k].IsEqual(setstr)
if !b {
t.Fatal("Expecting ", tssExp[k], " == ",
setstr, "? ", b)
}
}
}
}
func TestPartitioning2(t *testing.T) {
lss := tekstus.ListStrings{
{"a", "b", "c"},
{"a", "b", "c", "d"},
{"a", "b", "c", "d", "e"},
{"a", "b", "c", "d", "e", "f"},
}
for _, ss := range lss {
for i := 1; i <= len(ss); i++ {
_ = ss.Partitioning(i)
}
}
}
func TestStringsSortByIndex(t *testing.T) {
dat := []string{"Z", "X", "C", "V", "B", "N", "M"}
exp := []string{"B", "C", "M", "N", "V", "X", "Z"}
ids := []int{4, 2, 6, 5, 3, 1, 0}
tekstus.StringsSortByIndex(&dat, ids)
assert(t, exp, dat, true)
}