-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
algebra_test.py
executable file
·143 lines (121 loc) · 3.98 KB
/
algebra_test.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
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
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from parser_test_helper import *
import sys
sys.path.append('/Users/me/angle/')
sys.path.append('/Users/me/angle/core/')
class AlgebraTest(ParserBaseTest):
def setUp(self):
context.use_tree = False
# super(AlgebraTest, self).setUp()
def test_algebra1(self):
assert_result_is('two minus 1', 1)
assert_result_is('3 minus one', 2)
init('4.0')
assert_equals(parser.fraction(), 4)
init('4.0+3.0')
parser.do_interpret()
assert_equals(parser.algebra(), 7)
assert_result_is('4.0+3.0', 7.0)
def test_root(self):
assert_result_is('√9', 3)
assert_result_is('√9+1', 4)
# assert_result_is('√9*2', 6)
def test_algebra_POW(self):
assert_result_is('2^10', 1024)
assert_result_is('2**10', 1024)
assert_result_is('2 ^ 10', 1024)
# assert_result_is('2^^10', 1024) Not tokenized correctly
# assert_result_is('2 ^^ 10', 1024)
assert_result_is('2 ** 10', 1024)
assert_result_is('2 pow 10', 1024)
assert_result_is('2 power 10', 1024)
# assert_result_is('2 to the power 10', 1024)
# assert_result_is('2 to the power of 10', 1024)
def test_algebra_POW2(self):
assert_result_is('⦠pow 3, 4', 81) # how, lol
assert_result_is(u'⦠pow 2, 10', 1024)
def test_algebra_NOW(self):
# skip('test_algebra_NOW, DONT SKIP!')
assert_result_is('4+3/4', 7 / 4.)
assert_result_is('4+(3/4)', 7 / 4.)
assert_result_is('4.0+3/4.0', 7 / 4.)
assert_result_is('4.0+(3/4.0)', 7 / 4.)
assert_result_is('4+3/4.0', 7 / 4.)
def test_algebra(self):
ok = parse('2*(3+10)')
print((('Parsed input as ' + str(ok)) + '!'))
assert_equals(ok, 26)
# skip()
# assert(self.current_node!=(None))
# full_value = self.current_node.full_value()
# val = eval(full_value)
# assert_equals(val, 26)
# val = self.current_node.eval_node(self.variableValues)
# assert_equals(val, 26)
# def setUp(self):
# parser=parser(self) #HYH>?
# parser.do_interpret()
# context.use_tree=False
# super(AlgebraTest, self).setUp()
def test_prefix(self):
assert_result_is('2++', 3)
assert_result_is('++2', 3)
def test_algebra1(self):
assert_result_is('two minus 1', 1)
assert_result_is('3 minus one', 2)
init('4.0')
assert_equals(parser.fraction(), 4)
init('4.0+3.0')
parser.do_interpret()
assert_equals(parser.algebra(), 7)
assert_result_is('4.0+3.0', 7.0)
def test_algebra_NOW(self):
# skip('test_algebra_NOW, DONT SKIP!')
assert_result_is('1.0+3/4.0', 7 / 4.)
assert_result_is('1.0+(3/4.0)', 7 / 4.)
assert_result_is('1+3/4.0', 7 / 4.)
def test_logic(self):
# skip('test_algebra_NOW, DONT SKIP!')
assert_result_is('¬1', False) # alt l on mac
assert_result_is('!0', True)
assert_result_is('not 0', True)
assert_result_is('not False', True)
assert_result_is('¬ 0', True)
assert_result_is('¬ False', True)
assert_result_is('! False', True)
assert_result_is('¬0', True)
assert_result_is('¬False', True)
assert_result_is('!False', True)
assert_result_is('!1', False)
assert_result_is('not 1', False)
assert_result_is('not True', False)
assert_result_is('¬ True', False)
assert_result_is('! True', False)
assert_result_is('¬True', False)
assert_result_is('!True', False)
def test_tau_pi(self):
assert_that('tau / 2 = pi')
# assert_result_is('tau / 2 ', math.pi)
# assert_result_is('†/2', math.pi)# alt+t on mac
# assert_result_is('τ / 2 = π', True)
def test_algebra_NOW2(self):
skip('test_algebra_NOW, DONT SKIP!')
assert_result_is('1+(3/4)', 7 / 4.)
assert_result_is('1+3/4', 7 / 4.)
def test_prescendence(self):
assert_result_is("1+2*3", 7)
assert_result_is("1+2*3-4/2", 5)
def test_algebra(self):
ok = parse('2*(3+10)')
print((('Parsed input as ' + str(ok)) + '!'))
assert_equals(ok, 26)
# skip()
# assert(self.current_node!=(None))
# full_value = self.current_node.full_value()
# val = eval(full_value)
# assert_equals(val, 26)
# val = self.current_node.eval_node(self.variableValues)
# assert_equals(val, 26)
if __name__ == '__main__':
unittest.main()