-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheliza_test.go
97 lines (73 loc) · 2.6 KB
/
eliza_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
package eliza
import (
// "fmt"
"reflect"
"testing"
)
func TestCheckForQuit(t *testing.T) {
no_quit := []string{"this", "is", "a", "string"}
if CheckForQuit(no_quit) {
t.Errorf("Found a quit statement in a string without one.")
}
quit := []string{"this", "bye", "a", "string"}
if !CheckForQuit(quit) {
t.Errorf("Found no quit statement in a string with one.")
}
}
func TestScriptLoading(t *testing.T) {
// Check that keyword map loading
if _, ok := Keywords["xnone"]; ok != true {
t.Errorf("Keywords not getting loaded. 'xnone' keyword missing.")
}
// Check that preprocessor map loading
if _, ok := Pre["dont"]; ok != true {
t.Errorf("Pre not getting loaded. 'dont' keyword missing.")
}
// Check that postprocessor map loading
if _, ok := Post["am"]; ok != true {
t.Errorf("Post not getting loaded. 'am' keyword missing.")
}
// Check that synonym map loading
if _, ok := SynonymMap["be"]; ok != true {
t.Errorf("SynonymMap not getting loaded. 'be' keyword missing.")
}
}
func TestPreProcess(t *testing.T) {
// Test that PreProcess() finds words for preprocessing
// and returns a new string
orig := "I dont think so."
parsed := ParseInput(orig)
prepd := PreProcess(parsed)
result := []string{"i", "don't", "think", "so"}
if !reflect.DeepEqual(prepd, result) {
t.Errorf("Error with preprocessing. Returned string (%v) did not match expected result (%v).", prepd, result)
}
}
func TestPostProcess(t *testing.T) {
// Test that PreProcess() finds words for postprocessing
// and returns a new string
orig := "I love it when you quote shakespeare."
parsed := ParseInput(orig)
postd := PostProcess(parsed)
result := []string{"you", "love", "it", "when", "I", "quote", "shakespeare"}
if !reflect.DeepEqual(postd, result) {
t.Errorf("Error with post-processing. Returned string (%v) did not match expected result (%v).", postd, result)
}
}
func TestFindSynonym(t *testing.T) {
// Test that PreProcess() finds synonyms for preprocessing
// and returns a new string with the first word in the synonym list
orig := "What you want and what you need."
parsed := ParseInput(orig)
synond := Synonymize(parsed)
result := []string{"what", "you", "desire", "and", "what", "you", "desire"}
if !reflect.DeepEqual(synond, result) {
t.Errorf("Error with post-processing. Returned string (%v) did not match expected result (%v).", synond, result)
}
}
func TestFindKeyword(t *testing.T) {
// Test that it finds a keyword in a string
// Test that it returns 'xnone' when there are no keywords
// Test that it returns the keyword with the highest rank if there are
// multiple keywords in a string
}