-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparselearn_test.go
More file actions
175 lines (128 loc) · 5.56 KB
/
Copy pathparselearn_test.go
File metadata and controls
175 lines (128 loc) · 5.56 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package parselearn
import (
"bufio"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
// Example receipt (anonymised)
//Name: First Last (sxxxxxxx)
//Assignment: Practice Exam Drop Box
//Date Submitted: Monday, dd April yyyy hh:mm:ss o'clock BST
//Current Mark: Needs Marking
//
//Submission Field:
//There is no student submission text data for this assignment.
//
//Comments:
//There are no student comments for this assignment.
//
//Files:
// Original filename: OnlineExam-Bxxxxxx.pdf
// Filename: Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_OnlineExam-Bxxxxxx.pdf
func assertEqual(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Fatalf("%s != %s", a, b)
}
}
func TestProcessRevision(t *testing.T) {
sub := Submission{}
processRevision("Revision: 2", &sub)
assertEqual(t, sub.Revision, 2)
}
func TestProcessName(t *testing.T) {
sub := Submission{}
processName("Name: Donald The Duck (sxxxxxxx)", &sub)
assertEqual(t, sub.FirstName, "-")
assertEqual(t, sub.LastName, "Donald The Duck")
assertEqual(t, sub.Matriculation, "sxxxxxxx")
}
func TestProcessAction(t *testing.T) {
sub := Submission{}
processAction("Action: ignore", &sub)
assertEqual(t, sub.Action, "ignore")
}
func TestProcessAssignment(t *testing.T) {
sub := Submission{}
processAssignment("Assignment: Practice Exam Drop Box", &sub)
assertEqual(t, sub.Assignment, "Practice Exam Drop Box")
}
func TestDateSubmitted(t *testing.T) {
sub := Submission{}
processDateSubmitted("Date Submitted: Monday, dd April yyyy hh:mm:ss o'clock BST", &sub)
assertEqual(t, sub.DateSubmitted, "Monday, dd April yyyy hh:mm:ss o'clock BST")
}
func TestSubmissionField(t *testing.T) {
sub := Submission{}
processSubmission("There is no student submission text data for this assignment.", &sub)
assertEqual(t, sub.SubmissionField, "There is no student submission text data for this assignment.")
}
func TestComments(t *testing.T) {
sub := Submission{}
processSubmission("There are no student comments for this assignment", &sub)
assertEqual(t, sub.SubmissionField, "There are no student comments for this assignment")
}
func TestOriginalFilename(t *testing.T) {
sub := Submission{}
processOriginalFilename("Original filename: OnlineExam-Bxxxxxx.pdf", &sub)
assertEqual(t, sub.OriginalFilename, "OnlineExam-Bxxxxxx.pdf")
}
func TestFilename(t *testing.T) {
sub := Submission{}
processFilename("Filename: Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_OnlineExam-Bxxxxxx.pdf", &sub)
assertEqual(t, sub.Filename, "Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_OnlineExam-Bxxxxxx.pdf")
}
func TestParseFile(t *testing.T) {
sub, err := ParseLearnReceipt("./test/receipt2.txt")
if err != nil {
t.Error(err)
}
assertEqual(t, sub.FirstName, "-")
assertEqual(t, sub.LastName, "John Smith")
assertEqual(t, sub.Matriculation, "s00000000")
assertEqual(t, sub.Assignment, "Some Exam Or Other")
assertEqual(t, sub.DateSubmitted, "Tuesday, dd April yyyy hh:mm:ss o'clock BST")
assertEqual(t, sub.SubmissionField, "There is no student submission text data for this assignment.")
assertEqual(t, sub.Comments, "There are no student comments for this assignment.")
assertEqual(t, sub.OriginalFilename, "ENGI1234-Bxxxxxx.pdf")
assertEqual(t, sub.Filename, "Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_ENGI1234-Bxxxxxx.pdf")
}
var expected1 = `Revision,Action,FirstName,LastName,Matriculation,Assignment,DateSubmitted,SubmissionField,Comments,OriginalFilename,Filename,ExamNumber,MatriculationError,ExamNumberError,FiletypeError,FilenameError,NumberOfPages,FilesizeMB,NumberOfFiles`
var expected2 = `0,,-,First Last,sxxxxxxx,Practice Exam Drop Box,"Monday, dd April yyyy hh:mm:ss o'clock BST",There is no student submission text data for this assignment.,There are no student comments for this assignment.,OnlineExam-Bxxxxxx.pdf,Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_OnlineExam-Bxxxxxx.pdf,,,,,,,0,1`
var expected3 = `99,ignore,-,John Smith,s00000000,Some Exam Or Other,"Tuesday, dd April yyyy hh:mm:ss o'clock BST",There is no student submission text data for this assignment.,There are no student comments for this assignment.,ENGI1234-Bxxxxxx.pdf,Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_ENGI1234-Bxxxxxx.pdf,,,,,,,0,1`
var expected4 = `1,,-,First Last,sxxxxxxx,Practice Exam Drop Box,"Monday, dd April yyyy hh:mm:ss o'clock BST",There is no student submission text data for this assignment.,There are no student comments for this assignment.,OnlineExam-Bxxxxxx.pdf,Practice Exam Drop Box_sxxxxxxx_attempt_yyyy-mm-dd-hh-mm-ss_OnlineExam-Bxxxxxx.pdf,,,,,,,0,1`
func TestMarshallToFile(t *testing.T) {
sub1, err := ParseLearnReceipt("./test/receipt1.txt")
if err != nil {
t.Error(err)
}
sub2, err := ParseLearnReceipt("./test/receipt2.txt")
if err != nil {
t.Error(err)
}
sub3, err := ParseLearnReceipt("./test/receipt3.txt")
if err != nil {
t.Error(err)
}
subs := []Submission{sub1, sub2, sub3}
WriteSubmissionsToCSV(subs, "./test/out.csv")
file, err := os.Open("./test/out.csv")
if err != nil {
t.Error(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Scan()
assertEqual(t, scanner.Text(), expected1)
scanner.Scan()
assertEqual(t, scanner.Text(), expected2)
scanner.Scan()
assertEqual(t, scanner.Text(), expected3)
scanner.Scan()
assertEqual(t, scanner.Text(), expected4)
}
func TestGetFiles(t *testing.T) {
list, err := GetFilePaths("./test/receiptmulti.txt")
assert.NoError(t, err)
assert.Equal(t, []string{"A B-C.pdf", "D-D F.pdf", "G H_I J.pdf", "G H_I J Copy.pdf", "G H_I J Copy (2).pdf"}, list)
}