-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
type_test.py
executable file
·143 lines (115 loc) · 3.85 KB
/
type_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
from parser_test_helper import *
class TypeTest(ParserBaseTest,unittest.TestCase):
def test_typed_variable(self):
parse('Int i=7')
assert_equals(the.variables['i'].type, int)
def test_typed_variable2(self):
parse('int i=7')
assert_equals(the.variables['i'].type, int)
def test_typed_variable2(self):
parse('int i=7')
assert_equals(variableTypes['i'], Integer)
#
def test_auto_typed_variable(self):
parse('i=7')
assert_equals(variableTypes['i'], Fixnum)
def test_class11(self):
init('class of 1,2,3')
parser.evaluate_property()
assert_equals(result(), list)
init('class of [1,2,3]')
parser.expression()
assert_equals(result(), list)
def test_class1(self):
# skip()
parse('class of 1,2,3') # [<class 'int'>, 2, 3] SHOULD BE <class 'list'> BUG
assert_equals(result(), list)
def test_class22(self):
parse('x=1;class of x')
assert_equals(result(), int)
def test_class2(self):
parse('x=1,2,3;class of x')
assert_equals(result(), list)
def test_type11(self):
init('type of 1,2,3')
parser.evaluate_property()
assert_equals(result(), list)
init('type of [1,2,3]')
parser.expression()
assert_equals(result(), list)
def test_type1(self):
# skip()
parse('type of 1,2,3') # [<type 'int'>, 2, 3] SHOULD BE <type 'list'> BUG
assert_equals(result(), list)
def test_type22(self):
parse('x=1;type of x')
assert_equals(result(), int)
def test_type2(self):
parse('x=1,2,3;type of x')
assert_equals(result(), list)
def test_type(self):
parse('x=1,2,3;')
assert('type of x is Array')
def test_type3(self):
parse('x be 1,2,3;y= class of x')
assert_equals(the.variables['x'].type , list)
assert_equals(type(the.variableValues['x']) , list)
assert_equals(type(the.variables['x'].value) , list)
assert_equals(the.variableValues['y'], list)
assert_equals(the.variables['y'].value, list)
assert_equals(the.variables['y'].type, type)
def test_type33(self):
parse('x be 1,2,3;y= class of x')
self.do_assert('x is a Array')
self.do_assert('x is an Array')
self.do_assert('x is Array')
self.do_assert('Array == class of x')
self.do_assert('class of x is Array')
self.do_assert('kind of x is Array')
self.do_assert('type of x is Array')
def test_type34(self):
parse('x be 1,2,3;y= class of x')
self.do_assert('Array == y')
self.do_assert('y is Array')
skip()
self.do_assert('y is an Array') # nee
def test_type4(self):
variables['x'] = [[1, 2, 3], ]
self.do_assert('class of x is Array')
self.do_assert('kind of x is Array')
self.do_assert('type of x is Array')
def test_type_cast(self):
# assert_result_is('2.3', None)
parse('int z=2.3 as int')
assert_equals(result(), 2)
def test_no_type_cast(self):
assert_equals(type(parse('2.3 as int'), ), int)
assert_equals(type(parse('2.3'), ), float)
'''
def test_type_hinting_python3_5(self):
from typing import List # , TYPE_CHECKING
def sum_and_stringify(nums: List[int]) -> str:
return str(sum(nums))
print(sum_and_stringify([1, 2]))
def test_type_hinting_python3_5b(self):
def sum_and_stringify(nums: list) -> str:
return str(sum(nums))
print(sum_and_stringify([1,2]))
'''
def test_type_hinting_python3_5b(self):
def sum_and_stringify(nums: list) -> str:
return str(sum(nums))
print(sum_and_stringify([1,2]))
def test_type_hinting_python2_and_python3(self):
def sum_and_stringify(nums):
# type (list) -> str
return sum(nums)
print(sum_and_stringify([1, 2]))
if __name__ == '__main__':
suite = unittest.TestSuite()
method="test_type_hinting_python3_5b"
suite.addTest(TypeTest(method))
runner = unittest.TextTestRunner()
runner.run(suite)
#unittest.main()) #all