-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_hash.t
84 lines (70 loc) · 1.53 KB
/
test_hash.t
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
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local hash = require("hash")
local string = terralib.includec("string.h")
local HashMap = hash.HashMap(rawstring, int32)
import "terratest/terratest"
testenv "HashMap with strings" do
terracode
var map = HashMap.new()
defer map:free()
end
testset "Setters and Getters" do
terracode
var key = "Alice"
var val = 43
map:set(key, val)
var val_map = map:get(key)
var len = map:size()
end
test val == val_map
test len == 1
end
end
local HashPtr = hash.HashMap(&opaque, int64)
testenv "HashMap with pointers" do
terracode
var map = HashPtr.new()
defer map:free()
var x: double[4]
var y: int[31]
map:set(&x, 4 * 8)
map:set(&y, 31 * 4)
var len = map:size()
end
testset "Size" do
test len == 2
end
testset "Getters" do
terracode
var bytes_double = map:get(&x)
var bytes_int = map:get(&y)
end
test bytes_double == 4 * 8
test bytes_int == 31 * 4
end
end
local HashInt = hash.HashMap(int64, double)
testenv "HashMap with integer indices" do
terracode
var map = HashInt.new()
map:set(10, -123.0)
map:set(-2, 3.14)
map:set(0, 2.71)
var len = map:size()
end
testset "Size" do
test len == 3
end
testset "Getters" do
terracode
var x = arrayof(double, map:get(0), map:get(10), map:get(-2))
var xref = arrayof(double, 2.71, -123.0, 3.14)
end
for i = 1, 3 do
test x[i - 1] == xref[i - 1]
end
end
end