/
testForm.go
90 lines (77 loc) · 2.55 KB
/
testForm.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
package testparts
import (
"github.com/daichi-m/go18ds/lists/arraylist"
"github.com/daichi-m/go18ds/sets/hashset"
)
func (w *WordMatchSt) TestForm(gf *GoogleFormSt, student uint) error {
words := w.getWords(student)
points := w.Points / uint(words.Size())
questions := QuestionSetSt{List: arraylist.New[*QuestionsSt]()}
wordDef, _ := w.Get(int(student))
wordDef.Each(
func(_ int, wDef *WordDefSt) {
choice := hashset.New(wDef.Word.string)
for choice.Size() < 5 {
choice.Add(words.getRandom())
}
def, _ := w.getDefs(student).Get(int(wDef.Answer.string[0] - 'A'))
questions.Add(
&QuestionsSt{
Question: def,
Answers: WordsSt{List: arraylist.New("", wDef.Word.string)},
Choices: WordsSt{List: arraylist.New(choice.Values()...)},
},
)
},
)
if err := gf.AddSection(w.SectionTitle, w.FormInstructions); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (c *CompQuestionsSt) TestForm(gf *GoogleFormSt, student uint) error {
questions, _ := c.Questions.Get(int(student))
points := c.Points / uint(questions.Size())
if err := gf.AddSection(c.SectionTitle, c.Text); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (w *WordProblemSt) TestForm(gf *GoogleFormSt, student uint) error {
questions, _ := w.Questions.Get(int(student))
points := w.Points / uint(questions.Size())
if err := gf.AddSection(w.SectionTitle, w.Text); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (m *MultipleChoiceSt) TestForm(gf *GoogleFormSt, student uint) error {
questions, _ := m.Questions.Get(int(student))
points := m.Points / uint(questions.Size())
if err := gf.AddSection(m.SectionTitle, m.FormInstructions); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (r *ReadingCompSt) TestForm(gf *GoogleFormSt, student uint) error {
questions, _ := r.Questions.Get(int(student))
points := r.Points / uint(questions.Size())
if err := gf.AddSection(r.SectionTitle, r.Text); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (q *QuizSt) TestForm(gf *GoogleFormSt, student uint) error {
questions, _ := q.Questions.Get(int(student))
points := q.Points / uint(questions.Size())
if err := gf.AddSection(q.SectionTitle, q.Text); err != nil {
return err
}
return gf.AddQuestions(questions, int64(points))
}
func (c *CustomSt) TestForm(gf *GoogleFormSt, student uint) error {
return nil
}
func (p *PassageCompletionSt) TestForm(gf *GoogleFormSt, student uint) error {
return nil
}