-
Notifications
You must be signed in to change notification settings - Fork 10
/
swot_test.go
122 lines (112 loc) · 3.48 KB
/
swot_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
package swot
import (
"bufio"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
)
func Test_IsAcademic(t *testing.T) {
tests := map[string]bool{
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": false,
"[email protected]": false,
"[email protected]": false,
"[email protected]": false,
"stanford.edu": true,
"slac.stanford.edu": true,
"www.stanford.edu": true,
"http://www.stanford.edu": true,
"http://www.stanford.edu:9393": true,
"strath.ac.uk": true,
"soft-eng.strath.ac.uk": true,
"ugr.es": true,
"uottawa.ca": true,
"mother.edu.ru": true,
"ucy.ac.cy": true,
"leerilly.net": false,
"gmail.com": false,
"stanford.edu.com": false,
"strath.ac.uk.com": false,
"": false,
"the": false,
" stanford.edu": true,
"[email protected] ": true,
" gmail.com": false,
"[email protected]": true,
"[email protected]": true,
"[email protected]": true,
"[email protected]": false,
"[email protected]": true,
"[email protected]": false,
"si.edu": false,
"foo.si.edu": false,
"america.edu": false,
"folger.edu": false,
"[email protected]": false,
".com": false,
}
for key, want := range tests {
got := IsAcademic(key)
if got != want {
t.Fatalf("%s, want:%t, got:%t\n", key, want, got)
}
}
}
func Test_GetSchoolName(t *testing.T) {
tests := map[string]string{
"[email protected]": "University of Strathclyde",
"[email protected]": "BRG Fadingerstraße Linz, Austria",
"[email protected]": "University of Nairobi",
"[email protected]": "",
"[email protected]": "",
"harvard.edu": "Harvard University",
"stanford.edu": "Stanford University",
}
for key, want := range tests {
got := GetSchoolName(key)
if strings.Compare(got, want) != 0 {
fmt.Println(strings.Compare(got, want))
t.Fatalf("%s, want:%s, got:%s\n", key, want, got)
}
}
}
func Test_domainFiles(t *testing.T) {
err := filepath.Walk("domains", walkFunc)
if err != nil {
t.Fatal(err)
}
}
func walkFunc(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
//Should contain only text files
if filepath.Ext(info.Name()) != ".txt" {
return errors.New(info.Name() + " should have a .txt extension.")
}
//Each file should contain only a single line of text.
f, err := os.Open(path)
if err != nil {
return err
}
scanner := bufio.NewScanner(f)
lines := 0
for scanner.Scan() {
lines++
}
if lines > 1 {
return errors.New(info.Name() + " should only have a single line of text.")
}
}
return nil
}