This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
75 lines (69 loc) · 1.7 KB
/
utils_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
package ecms_go_filter
import (
"fmt"
"math"
"testing"
)
func TestStrSubSequences(t *testing.T) {
for _, candidate := range []string{
"",
"abc",
} {
t.Run(fmt.Sprintf("StrSubSequences(\"%v\")", candidate), func(t2 *testing.T) {
candidateLen := len(candidate)
result := StrSubSequences(candidate)
resultLen := len(result)
expectedLen := int(math.Pow(2, float64(candidateLen)))
t2.Run(fmt.Sprintf("Expect result length of %v", expectedLen), func(t2 *testing.T) {
if resultLen != expectedLen {
t2.Errorf("Expected %v; Got %v", expectedLen, resultLen)
}
})
// Ensure correct subsequences were generated
for i, x := range result {
name := fmt.Sprintf("Expect lastIndexOf %v to equal %v", x, i)
t2.Run(name, func(t2 *testing.T) {
for j, x2 := range result {
if i != j && x == x2 {
t2.Errorf("Expected last index of %v to equal %v; Got %v", x, i, j)
}
}
})
}
})
}
}
func TestToByteString(t *testing.T) {
for _, x := range []interface{}{
"",
' ',
"abc",
[]byte(""),
[]byte{' '},
[]byte("abc"),
[]rune(""),
[]rune{' '},
[]rune("abc"),
} {
t.Run(fmt.Sprintf("ToByteString(%v)", x), func(t2 *testing.T) {
result := ToByteString(x)
resultStr := string(result)
var expectedStr string
switch x.(type) {
case string:
expectedStr = x.(string)
case []byte:
expectedStr = string(x.([]byte))
case []rune:
expectedStr = string(x.([]rune))
case rune:
expectedStr = string([]rune{x.(rune)})
}
t2.Run(fmt.Sprintf("Expect %v same as %v", result, expectedStr), func(t3 *testing.T) {
if resultStr != expectedStr {
t3.Errorf("Expected %v to %v", resultStr, expectedStr)
}
})
})
}
}