|
1 | 1 | from ltypes import i32
|
2 | 2 |
|
3 | 3 | def test_ord():
|
4 |
| - i: i32 |
5 | 4 | s: str
|
6 |
| - s = "1" |
7 |
| - i = ord(s) |
8 |
| - assert i == 49 |
9 |
| - assert ord("1") == 49 |
| 5 | + |
| 6 | + exclamation_unicode: i32 |
| 7 | + s = '!' |
| 8 | + exclamation_unicode = ord(s) |
| 9 | + assert(ord('!') == 33) # testing compile time implementation |
| 10 | + assert(exclamation_unicode == 33) # testing runtime implementation |
| 11 | + |
| 12 | + dollar_unicode: i32 |
| 13 | + s = '$' |
| 14 | + dollar_unicode = ord(s) |
| 15 | + assert(ord('$') == 36) # testing compile time implementation |
| 16 | + assert(dollar_unicode == 36) # testing runtime implementation |
| 17 | + |
| 18 | + left_parenthesis_unicode: i32 |
| 19 | + s = '(' |
| 20 | + left_parenthesis_unicode = ord(s) |
| 21 | + assert(ord('(') == 40) # testing compile time implementation |
| 22 | + assert(left_parenthesis_unicode == 40) # testing runtime implementation |
| 23 | + |
| 24 | + plus_unicode: i32 |
| 25 | + s = '+' |
| 26 | + plus_unicode = ord(s) |
| 27 | + assert(ord('+') == 43) # testing compile time implementation |
| 28 | + assert(plus_unicode == 43) # testing runtime implementation |
| 29 | + |
| 30 | + zero_unicode: i32 |
| 31 | + s = '0' |
| 32 | + zero_unicode = ord(s) |
| 33 | + assert(ord('0') == 48) # testing compile time implementation |
| 34 | + assert(zero_unicode == 48) # testing runtime implementation |
| 35 | + |
| 36 | + nine_unicode: i32 |
| 37 | + s = '9' |
| 38 | + nine_unicode = ord(s) |
| 39 | + assert(ord('9') == 57) # testing compile time implementation |
| 40 | + assert(nine_unicode == 57) # testing runtime implementation |
| 41 | + |
| 42 | + semicolon_unicode: i32 |
| 43 | + s = ';' |
| 44 | + semicolon_unicode = ord(s) |
| 45 | + assert(ord(';') == 59) # testing compile time implementation |
| 46 | + assert(semicolon_unicode == 59) # testing runtime implementation |
| 47 | + |
| 48 | + capital_a_unicode: i32 |
| 49 | + s = 'A' |
| 50 | + capital_a_unicode = ord(s) |
| 51 | + assert(ord('A') == 65) # testing compile time implementation |
| 52 | + assert(capital_a_unicode == 65) # testing runtime implementation |
| 53 | + |
| 54 | + capital_z_unicode: i32 |
| 55 | + s = 'Z' |
| 56 | + capital_z_unicode = ord(s) |
| 57 | + assert(ord('Z') == 90) # testing compile time implementation |
| 58 | + assert(capital_z_unicode == 90) # testing runtime implementation |
| 59 | + |
| 60 | + right_bracket_unicode: i32 |
| 61 | + s = ']' |
| 62 | + right_bracket_unicode = ord(s) |
| 63 | + assert(ord(']') == 93) # testing compile time implementation |
| 64 | + assert(right_bracket_unicode == 93) # testing runtime implementation |
| 65 | + |
| 66 | + small_a_unicode: i32 |
| 67 | + s = 'a' |
| 68 | + small_a_unicode = ord(s) |
| 69 | + assert(ord('a') == 97) # testing compile time implementation |
| 70 | + assert(small_a_unicode == 97) # testing runtime implementation |
| 71 | + |
| 72 | + small_z_unicode: i32 |
| 73 | + s = 'z' |
| 74 | + small_z_unicode = ord(s) |
| 75 | + assert(ord('z') == 122) # testing compile time implementation |
| 76 | + assert(small_z_unicode == 122) # testing runtime implementation |
| 77 | + |
| 78 | + right_brace_unicode: i32 |
| 79 | + s = '}' |
| 80 | + right_brace_unicode = ord(s) |
| 81 | + assert(ord('}') == 125) # testing compile time implementation |
| 82 | + assert(right_brace_unicode == 125) # testing runtime implementation |
10 | 83 |
|
11 | 84 |
|
12 | 85 | def test_chr():
|
13 |
| - i: i32 |
14 |
| - i = 48 |
15 |
| - s: str |
16 |
| - s = chr(i) |
17 |
| - assert s == "0" |
18 |
| - assert chr(48) == "0" |
| 86 | + i: i32 |
| 87 | + |
| 88 | + exclamation: str |
| 89 | + i = 33 |
| 90 | + exclamation = chr(i) |
| 91 | + assert(chr(33) == '!') # testing compile time implementation |
| 92 | + assert(exclamation == '!') # testing runtime implementation |
| 93 | + |
| 94 | + dollar: str |
| 95 | + i = 36 |
| 96 | + dollar = chr(i) |
| 97 | + assert(chr(36) == '$') # testing compile time implementation |
| 98 | + assert(dollar == '$') # testing runtime implementation |
| 99 | + |
| 100 | + left_parenthesis: str |
| 101 | + i = 40 |
| 102 | + left_parenthesis = chr(i) |
| 103 | + assert(chr(40) == '(') # testing compile time implementation |
| 104 | + assert(left_parenthesis == '(') # testing runtime implementation |
| 105 | + |
| 106 | + plus: str |
| 107 | + i = 43 |
| 108 | + plus = chr(i) |
| 109 | + assert(chr(43) == '+') # testing compile time implementation |
| 110 | + assert(plus == '+') # testing runtime implementation |
| 111 | + |
| 112 | + zero: str |
| 113 | + i = 48 |
| 114 | + zero = chr(i) |
| 115 | + assert(chr(48) == '0') # testing compile time implementation |
| 116 | + assert(zero == '0') # testing runtime implementation |
| 117 | + |
| 118 | + nine: str |
| 119 | + i = 57 |
| 120 | + nine = chr(i) |
| 121 | + assert(chr(57) == '9') # testing compile time implementation |
| 122 | + assert(nine == '9') # testing runtime implementation |
| 123 | + |
| 124 | + semicolon: str |
| 125 | + i = 59 |
| 126 | + semicolon = chr(i) |
| 127 | + assert(chr(59) == ';') # testing compile time implementation |
| 128 | + assert(semicolon == ';') # testing runtime implementation |
| 129 | + |
| 130 | + capital_a: str |
| 131 | + i = 65 |
| 132 | + capital_a = chr(i) |
| 133 | + assert(chr(65) == 'A') # testing compile time implementation |
| 134 | + assert(capital_a == 'A') # testing runtime implementation |
| 135 | + |
| 136 | + capital_z: str |
| 137 | + i = 90 |
| 138 | + capital_z = chr(i) |
| 139 | + assert(chr(90) == 'Z') # testing compile time implementation |
| 140 | + assert(capital_z == 'Z') # testing runtime implementation |
| 141 | + |
| 142 | + right_bracket: str |
| 143 | + i = 93 |
| 144 | + right_bracket = chr(i) |
| 145 | + assert(chr(93) == ']') # testing compile time implementation |
| 146 | + assert(right_bracket == ']') # testing runtime implementation |
| 147 | + |
| 148 | + small_a: str |
| 149 | + i = 97 |
| 150 | + small_a = chr(i) |
| 151 | + assert(chr(97) == 'a') # testing compile time implementation |
| 152 | + assert(small_a == 'a') # testing runtime implementation |
| 153 | + |
| 154 | + small_z: str |
| 155 | + i = 122 |
| 156 | + small_z = chr(i) |
| 157 | + assert(chr(122) == 'z') # testing compile time implementation |
| 158 | + assert(small_z == 'z') # testing runtime implementation |
| 159 | + |
| 160 | + right_brace: str |
| 161 | + i = 125 |
| 162 | + right_brace = chr(i) |
| 163 | + assert(chr(125) == '}') # testing compile time implementation |
| 164 | + assert(right_brace == '}') # testing runtime implementation |
19 | 165 |
|
20 | 166 |
|
21 | 167 | test_ord()
|
22 | 168 | test_chr()
|
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
0 commit comments