-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_table.mojo
121 lines (95 loc) · 2.49 KB
/
test_table.mojo
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
from table import Table
from hashtable import NOT_FOUND_ERROR
from testing import assert_equal, assert_not_equal, assert_true, assert_false
fn test_table_with_many_types() raises -> Bool:
var table = Table()
if not table.set("a", True):
print_no_newline("E")
return False
else:
print_no_newline(".")
if not table.set("b", 2):
print_no_newline("E")
return False
else:
print_no_newline(".")
if not table.set("c", 3.3):
print_no_newline("E")
return False
else:
print_no_newline(".")
if not table.set("d", "4"):
print_no_newline("E")
return False
else:
print_no_newline(".")
var a: Bool = False
_ = table.get("a", a)
if assert_equal(a, True):
print_no_newline(".")
else:
print_no_newline("E")
return False
var b: Int = -1
_ = table.get("b", b)
if assert_equal(b, 2):
print_no_newline(".")
else:
print_no_newline("E")
return False
var c: Float32 = -1.0
_ = table.get("c", c)
if assert_equal(c, 3.3):
print_no_newline(".")
else:
print_no_newline("E")
return False
var d: StringRef = ""
_ = table.get("d", d)
if assert_equal(d, "4"):
print_no_newline(".")
else:
print_no_newline("E")
return False
var e: StringRef = ""
if not table.get("e", e) and assert_equal(e, NOT_FOUND_ERROR):
print_no_newline(".")
else:
print_no_newline("E")
return False
var e2: Float32 = -1.0
if not table.get("e", e2) and assert_equal(e2, -1.0):
print_no_newline(".")
else:
print_no_newline("E")
return False
return True
fn test_table_delete_items() raises -> Bool:
var table = Table()
_ = table.set("a", True)
_ = table.set("b", True)
_ = table.set("c", True)
_ = table.set("d", True)
if assert_equal(table.count(), 4):
print_no_newline(".")
else:
print_no_newline("E")
return False
_ = table.delete("a")
if assert_equal(table.bools.count, 3):
print_no_newline(".")
else:
print_no_newline("E")
return False
if assert_equal(table.count(), 3):
print_no_newline(".")
else:
print_no_newline("E")
return False
var value = False
if table.get("a", value):
print_no_newline("E")
return False
else:
print_no_newline(".")
return True