forked from timdrysdale/parselearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparselearn_test.go
More file actions
145 lines (107 loc) · 4.58 KB
/
Copy pathparselearn_test.go
File metadata and controls
145 lines (107 loc) · 4.58 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
package parselearn
import (
"bufio"
"fmt"
"os"
"testing"
)
// 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 TestProcessName(t *testing.T) {
sub := Submission{}
processName("Name: Donald The Duck (sxxxxxxx)", &sub)
assertEqual(t, sub.FirstName, "-")
fmt.Printf("[%s]\n[%s]\n", sub.LastName, "Donald The Duck")
assertEqual(t, sub.LastName, "Donald The Duck")
assertEqual(t, sub.Matriculation, "sxxxxxxx")
}
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 = `FirstName,LastName,Matriculation,Assignment,DateSubmitted,SubmissionField,Comments,OriginalFilename,Filename,ExamNumber,MatriculationError,ExamNumberError,FiletypeError,FilenameError,NumberOfPages,FilesizeMB,NumberOfFiles`
var expected2 = `-,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 = `-,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`
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)
}
subs := []Submission{sub1, sub2}
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)
}