-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
719ef7d
commit 5d5190a
Showing
4 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[flake8] | ||
exclude = venv/**,./.git | ||
max-line-length = 150 | ||
max-complexity = 30 | ||
extend-ignore = W605, E722, F821 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import math | ||
import unittest | ||
|
||
from run import MathWorksheetGenerator as Mg | ||
|
||
|
||
class TestStringMethods(unittest.TestCase): | ||
|
||
def test_generate_question_addition(self): | ||
g = Mg(type_='+', max_number=9, question_count=10) | ||
question = g.generate_question() | ||
self.assertEqual(question[0] + question[2], question[3]) | ||
|
||
def test_generate_question_subtraction(self): | ||
g = Mg(type_='-', max_number=9, question_count=10) | ||
question = g.generate_question() | ||
self.assertEqual(question[0] - question[2], question[3]) | ||
# answer should be greater than 0 | ||
self.assertGreaterEqual(question[3], 0) | ||
|
||
def test_generate_question_multiplication(self): | ||
g = Mg(type_='x', max_number=9, question_count=10) | ||
question = g.generate_question() | ||
self.assertEqual(question[0] * question[2], question[3]) | ||
|
||
def test_generate_question_unsupport_type_(self): | ||
g = Mg(type_='p', max_number=9, question_count=10) | ||
with self.assertRaisesRegex(RuntimeError, expected_regex=r"Question main_type p not supported"): | ||
g.generate_question() | ||
|
||
def test_get_list_of_questions_correct_count(self): | ||
g = Mg(type_='x', max_number=9, question_count=10) | ||
question_list = g.get_list_of_questions(g.question_count) | ||
self.assertEqual(len(question_list), g.question_count) | ||
|
||
def test_make_question_page_page_count(self): | ||
g = Mg(type_='x', max_number=9, question_count=2) | ||
question_info = [[1, '+', 1, 2]] * g.question_count | ||
g.make_question_page(question_info) | ||
total_page = math.ceil(g.question_count / (g.num_x_cell * g.num_y_cell)) | ||
self.assertEqual(total_page, g.pdf.page) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |