-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_boolean_opposites.py
108 lines (89 loc) · 4.33 KB
/
test_boolean_opposites.py
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
import pytest
from shlomobot_pytest.utils import (
create_custom_error_json, check_pattern,
)
@pytest.fixture
def file_path(tmp_path):
path = "boolean_opposites.txt"
return path
PATTERN_NOT_KEYWORD = ["""(?:^|\s)not(?:\s|$)"""]
PATTERN_SOLUTION_1 = ["""(?i)a\s*<=\s*b"""]
PATTERN_SOLUTION_2 = ["""(?i)a\s*<\s*b"""]
PATTERN_SOLUTION_3 = ["""(?i)a\s*<\s*18\s+or\s+day\s*!=\s*3"""]
PATTERN_SOLUTION_4 = ["""(?i)a\s*<\s*18\s+and\s+day\s*==\s*3"""]
# Question-specific Test Functions
# ------------------------------------------------------------------------
def test_for_not(file_path):
"""
Test to see if the 'not' keyword is within boolean_opposites.txt
"""
custom_error_message_not_in_solution = create_custom_error_json(
feedback="keyword 'Not' is detected in the .txt file.\n " +
"Please follow the exercise requirements.\n",
points_per_error=100,
max_points_deducted=100,
number_of_errors=1,
)
assert not check_pattern(PATTERN_NOT_KEYWORD, file_path), custom_error_message_not_in_solution
def test_for_part_1(file_path):
"""
Test to see if solution 1's regex is within boolean_opposites.txt
"""
custom_error_message_no_pattern_1 = create_custom_error_json(
feedback = "Correct solution for 1 is not detected.\n" +
"The solution should look like: 'a [comparison operator(s)] b' (without the quotes) " +
"Do ensure you submitted the correct structure also.\n" +
"Example structure 1: 'a [!=] b' (without the quotes) \n " +
"Example structure 2: 'a [>] b' (without the quotes) \n",
points_per_error=10,
max_points_deducted=10,
number_of_errors=1,
)
#regex is case-insensitive and does not check for start or end of a line.
assert check_pattern(PATTERN_SOLUTION_1, file_path), custom_error_message_no_pattern_1
def test_for_part_2(file_path):
"""
Test to see if solution 2's regex is within boolean_opposites.txt
"""
custom_error_message_no_pattern_2 = create_custom_error_json(
feedback = "Correct solution for 2 is not detected.\n" +
"The solution should look like: 'a [comparison operator(s)] b' (without the quotes) " +
"Do ensure you submitted the correct structure also.\n" +
"Example structure 1: 'a [>] b' (without the quotes) \n " +
"Example structure 2: 'a [==] b' (without the quotes) \n",
points_per_error=10,
max_points_deducted=10,
number_of_errors=1,
)
#regex is case-insensitive and does not check for start or end of a line.
assert check_pattern(PATTERN_SOLUTION_2, file_path), custom_error_message_no_pattern_2
def test_for_part_3(file_path):
"""
Test to see if solution 3's regex is within boolean_opposites.txt
"""
custom_error_message_no_pattern_3 = create_custom_error_json(
feedback = "Correct solution for 3 is not detected.\n" +
"Hint: The solution should comprise of 'a [comparison operator(s)] 18 [logical operator(s)] day [comparison operator(s)] 3'\n" +
"Example structure: a [!=] 18 [AND/OR] day [<=] 3 \n " +
"There are many possibilities to try, good luck!",
points_per_error=10,
max_points_deducted=10,
number_of_errors=1,
)
#regex is case-insensitive and does not check for start or end of a line.
assert check_pattern(PATTERN_SOLUTION_3, file_path), custom_error_message_no_pattern_3
def test_for_part_4(file_path):
"""
Test to see if solution 4's regex is within boolean_opposites.txt
"""
custom_error_message_no_pattern_4 = create_custom_error_json(
feedback = "Correct solution for 4 is not detected.\n" +
"Hint: The solution should comprise of 'a [comparison operator(s)] 18 [logical operator] day [comparison operator(s)] 3'\n" +
"Example structure: a [==] 18 [AND/OR] day [>=] 3 \n " +
"There are many possibilities to try, good luck!",
points_per_error=10,
max_points_deducted=10,
number_of_errors=1,
)
#regex is case-insensitive and does not check for start or end of a line.
assert check_pattern(PATTERN_SOLUTION_4, file_path), custom_error_message_no_pattern_4