-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_test.hpp
More file actions
134 lines (120 loc) · 3.26 KB
/
lesson_test.hpp
File metadata and controls
134 lines (120 loc) · 3.26 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
#pragma once
#include <functional>
#include <string>
#include <vector>
namespace lesson_test
{
// 读入 1 行输入 自动去除末尾 \t \n (space)
std::string read();
// 测试类型
enum class test_type
{
practice,
examination
};
// 问题基类
class base_question
{
public:
base_question() = default;
virtual ~base_question() = default;
private:
virtual void test() const = 0;
friend class interact_tester;
protected:
test_type type{test_type::practice};
mutable double score_percent{0};
};
// MCQ = Mutiple Choices Question 选择题
class MCQ : public base_question
{
public:
MCQ(std::string_view question, std::vector<std::pair<std::string_view, bool>> &&options, std::string_view hint,
std::string_view solution);
~MCQ() = default;
MCQ(const MCQ &) = delete;
MCQ(MCQ &&) = delete;
operator base_question *()
{
return this;
}
private:
struct test_info
{
std::string question;
std::vector<std::string> options;
std::string answer;
std::string hint;
std::string solution;
};
test_info info;
void test() const override;
};
// CRP = Code Reading Problem 阅读代码题
class CRP : public base_question
{
public:
CRP() = delete;
CRP(std::string_view source_code);
~CRP() = default;
CRP(const CRP &) = delete;
CRP(CRP &&) = delete;
void add(std::string_view input, std::string_view answer, std::string_view hint = "",
std::string_view solution = "");
void add(std::string_view input, const std::function<void()> &answer, std::string_view hint = "",
std::string_view solution = "");
operator base_question *()
{
return this;
}
private:
struct test_info
{
std::string input;
std::string hint;
std::vector<std::string> answer;
std::string solution;
};
std::vector<std::string> split(std::string_view output) const;
std::string source_code;
std::vector<test_info> infos;
void test() const override;
};
class ICP : public base_question
{
public:
ICP() = delete;
ICP(unsigned char *zip, unsigned int size, std::string_view path, std::string_view key);
~ICP() = default;
ICP(const ICP &) = delete;
ICP(ICP &&) = delete;
private:
struct test_info
{
unsigned char *data;
unsigned int size;
std::string path;
std::string key;
};
test_info info;
void write_zip() const;
void unzip() const;
void test() const override;
};
// 交互测试类
class interact_tester
{
public:
interact_tester(); // 重写 interact_tester 构造函数
interact_tester(std::string_view title); // 设置测试标题的构造函数
~interact_tester() = default;
interact_tester(const interact_tester &&) = delete;
interact_tester(interact_tester &&) = delete;
void add(base_question *question); // 添加题目
void run(test_type type = test_type::practice); // 运行测试
private:
std::string title; // 测试标题
std::vector<base_question *> question_list; // 题目列表
void set_console_utf8(); // 设置控制台编码为 UTF-8
};
}; // namespace lesson_test