-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
140 lines (118 loc) · 2.54 KB
/
main_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"testing"
)
func TestCheckName(t *testing.T) {
// valid name
err := checkName("marcus")
if err != nil {
t.Fatalf(`checkName("marco") results in error`)
}
// name with space
name := "marcus aurelius "
name = stripSpace(name)
err = checkName(name)
if err != nil {
t.Fatalf(`A name containing spaces results in error`)
}
}
func TestInvalidName(t *testing.T) {
err := checkName("123")
if err == nil {
t.Fatalf(`An invalid numerical name has been allowed`)
}
err = checkName("O'Hanlan")
if err == nil {
t.Fatalf(`An apostrophe has been allowed`)
}
}
func TestRemoveVowels(t *testing.T) {
s := "AEIOUX"
s = removeVowels(s)
if s != "X" {
t.Fatalf(`removeVowels() failure`)
}
}
func TestCheckSex(t *testing.T) {
// valid input
err := checkSex("M")
if err != nil {
t.Fatal("checkSex() failure")
}
err = checkSex("F")
if err != nil {
t.Fatal("checkSex() failure")
}
err = checkSex("")
if err != nil {
t.Fatal("checkSex() failure")
}
// invalid input
err = checkSex("X")
if err == nil {
t.Fatal("checkSex() failure - allows invalid input")
}
err = checkSex("M1")
if err == nil {
t.Fatal("checkSex() failure - allows invalid input")
}
}
func TestFuzzAlphabet(t *testing.T) {
c2 := make(chan [3]string)
go fuzzAlphabet(c2)
}
func TestCheckAges(t *testing.T) {
// valid input
err := checkAges(2, 1)
if err != nil {
t.Fatal("checkAges() failure - allows invalid input")
}
// valid input, ages equal
err = checkAges(2, 2)
if err != nil {
t.Fatal("checkAges() failure - allows invalid input")
}
// max lower than min
err = checkAges(1, 2)
if err == nil {
t.Fatal("checkAges() failure - allows invalid input")
}
}
func TestExtractVowels(t *testing.T) {
name := "AAAAAAAAAAAAAAAAA"
name = extractVowels(name)
if len(name) != 3 {
t.Fatal("extractVowels returns string of length >3")
}
name2 := "MISSISSIPPI"
name2 = extractVowels(name2)
if len(name2) != 3 {
t.Fatal("extractVowels returns vowel string of incorrect length")
}
}
func TestCheckDate(t *testing.T) {
// valid date
d := "2000-12-01"
err := checkDate(d)
if err != nil {
t.Fatal("checkDate() error - valid date not allowed")
}
// invalid date
d = "2000-31-01"
err = checkDate(d)
if err == nil {
t.Fatal("checkDate() error - invalid date allowed")
}
// invalid date
d = "31-01-2000"
err = checkDate(d)
if err == nil {
t.Fatal("checkDate() error - invalid date allowed")
}
// invalid date
d = "31st Jan 2000"
err = checkDate(d)
if err == nil {
t.Fatal("checkDate() error - invalid date allowed")
}
}