-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·92 lines (73 loc) · 2.55 KB
/
tests.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
#!/usr/bin/env python
# -*- coding: utf8 -*-
__author__ = "Max Kovgan <[email protected]>,"
from openuhw import OpenUHWResult, OpenUHWSolver
import unittest
class TestOpenUHWResult(unittest.TestCase):
def Setup(self):
pass
def test_instantiation(self):
res = OpenUHWResult()
self.assertEqual(res.title, '')
self.assertEqual(res.answers, [])
def test_title_setting(self):
res = OpenUHWResult()
test_val = "new title"
res.title = test_val
self.assertEqual(res.title, test_val)
def test_answer_setting(self):
res = OpenUHWResult()
test_val1 = "item 1"
test_val2 = "item 2"
res.answers.append(test_val1)
self.assertEqual(res.answers, [test_val1])
res.answers.append(test_val2)
self.assertEqual(res.answers, [test_val1, test_val2, ])
def test_str_converter(self):
res = OpenUHWResult(title="test_x")
test_val1 = dict(descr='x^2', result=4, )
test_val2 = dict(descr='x^3', result=8.3234, )
test_val3 = dict(descr='x^x', result=u"shjsss", )
s1 = u"Answers for test_x:"
self.assertEqual(s1, res.__str__())
s1 = u"Answers for test_x:\nx^2=4"
res.answers.append(test_val1)
self.assertEqual(s1, res.__str__())
s1 = u"Answers for test_x:\nx^2=4\nx^3=8.3234"
res.answers.append(test_val2)
self.assertEqual(s1, res.__str__())
s1 = u"Answers for test_x:\nx^2=4\nx^3=8.3234\nx^x=shjsss"
res.answers.append(test_val3)
self.assertEqual(s1, res.__str__())
class TestOpenUHW(unittest.TestCase):
def Setup(self):
pass
def test_make_hr_line(self):
ou_hw = OpenUHWSolver()
def_str = '=' * 40
self.assertEqual(ou_hw.make_hr_line(ch='=', length=40), def_str)
special_str = '~' * 0
self.assertEqual(ou_hw.make_hr_line(ch='~', length=0), special_str)
normal_str = '-' * 80
self.assertEqual(ou_hw.make_hr_line(ch='-', length=80), normal_str)
def test_add_solver(self):
ou_hw = OpenUHWSolver()
def solver_x():
return dict(
title="kuku",
answer=[
dict(descr='lala', result=0),
dict(descr='lulu', result=1),
]
)
ou_hw.add_solver(solver_x)
def test_main():
suite = unittest.TestSuite(
tests=(
TestOpenUHWResult,
)
)
result = unittest.TestResult
suite.run(result)
if __name__ == '__main__':
test_main()