-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordsplitter_test.go
86 lines (75 loc) · 1.92 KB
/
wordsplitter_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
package wordsplitter
import (
"reflect"
"testing"
)
func TestReadWordFile(t *testing.T) {
words, err := readWordFile("words.txt")
if err != nil {
t.Error(err)
}
if len(words) == 0 {
t.Errorf("Expected at least words %d word(s) ", 1)
}
}
func TestReverseFloatSlice(t *testing.T) {
s1 := []float64{1, 2, 3, 4, 5}
reversedS1 := ReverseFloatSlice(s1)
for i, j := 0, len(s1)-1; i < len(s1); i, j = i+1, j-1 {
if s1[i] != reversedS1[j] {
t.Errorf("Expected %f but got %f at index %d of the reversed slice", s1[i], reversedS1[j], j)
}
}
}
func TestSplitRegularString(t *testing.T) {
type test struct {
input string
want []string
}
tests := []test{
{input: "Howareyoudoingtoday?", want: []string{"How", "are", "you", "doing", "today", "?"}},
{input: "persistenceiskey", want: []string{"persistence", "is", "key"}},
{input: "welcometomycity", want: []string{"welcome", "to", "my", "city"}},
{input: "hundred", want: []string{"hundred"}},
}
for _, tc := range tests {
result := Split(tc.input)
if !reflect.DeepEqual(result, tc.want) {
t.Errorf("Expected %s but got %s", tc.want, result)
}
}
}
func TestIsInteger(t *testing.T) {
s := "tayo12"
isInteger(s[4])
}
func TestSplitDigitString(t *testing.T) {
type test struct {
input string
want []string
}
tests := []test{
{input: "2020isthecurrentyear", want: []string{"2020", "is", "the", "current", "year"}},
}
for _, tc := range tests {
result := Split(tc.input)
if !reflect.DeepEqual(result, tc.want) {
t.Errorf("Expected %s but got %s", tc.want, result)
}
}
}
func TestSplitApostropheString(t *testing.T) {
type test struct {
input string
want []string
}
tests := []test{
{input: "google'sprogramminglanguage", want: []string{"google's", "programming", "language"}},
}
for _, tc := range tests {
result := Split(tc.input)
if !reflect.DeepEqual(result, tc.want) {
t.Errorf("Expected %s but got %s", tc.want, result)
}
}
}