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
pub enum WeblabAttribute {
    Test,
    Library,
    Solution,
}
pub struct ProgrammingAssignment {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub library_visible: bool,
    pub spectest_stdout_visible: bool,
    pub test: &'static str,
    pub solution: &'static str,
    pub library: Option<&'static str>,
    pub test_template: &'static str,
    pub solution_template: &'static str,
    pub checklist: Option<Checklist>,
}
pub struct WeblabFolder {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub assignments: &'static [WeblabAssignment],
}
pub struct Checklist {
    pub items: Vec<&'static str>,
}
pub struct OpenQuestion {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub expected_answer: &'static str,
    pub checklist: Option<Checklist>,
}
pub struct InlineQuestionList {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub assignments: &'static [WeblabAssignment],
}
pub struct MCOption {
    pub text: &'static str,
    pub is_correct: bool,
}
#[derive(Copy, Clone)]
pub enum MCStyle {
    AllThatApply,
    NumCorrect(usize),
}
impl Default for MCStyle {
    fn default() -> Self {
        Self::NumCorrect(1)
    }
}
pub struct MCQuestion {
    pub title: &'static str,
    pub assignment_text: &'static str,
    pub options: &'static [MCOption],
    pub randomize: bool,
    pub style: MCStyle,
}
pub enum WeblabAssignment {
    Programming(ProgrammingAssignment),
    Open(OpenQuestion),
    MultipleChoice(MCQuestion),
    Folder(WeblabFolder),
    InlineQuestionList(InlineQuestionList),
}
impl WeblabAssignment {
    pub fn title(&self) -> &str {
        match self {
            WeblabAssignment::Programming(ProgrammingAssignment { title, .. }) => title,
            WeblabAssignment::Open(OpenQuestion { title, .. }) => title,
            WeblabAssignment::MultipleChoice(MCQuestion { title, .. }) => title,
            WeblabAssignment::Folder(WeblabFolder { title, .. }) => title,
            WeblabAssignment::InlineQuestionList(InlineQuestionList { title, .. }) => title,
        }
    }
    pub fn assignment_text(&self) -> &str {
        match self {
            WeblabAssignment::Programming(ProgrammingAssignment {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::Open(OpenQuestion {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::MultipleChoice(MCQuestion {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::Folder(WeblabFolder {
                assignment_text, ..
            }) => assignment_text,
            WeblabAssignment::InlineQuestionList(InlineQuestionList {
                assignment_text, ..
            }) => assignment_text,
        }
    }
}