-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_tree.t
62 lines (52 loc) · 1.65 KB
/
test_tree.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
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local tree = require("tree")
local alloc = require("alloc")
local io = terralib.includec("stdio.h")
local DefaultAllocator = alloc.DefaultAllocator()
import "terratest/terratest"
for _, T in pairs{float, double, int32, int64, uint64} do
local btree = tree.BinaryTree(T)
testenv(T) "Tree construction" do
terracode
var A: alloc.DefaultAllocator()
end
testset "Grow left" do
terracode
var t = btree.new(&A, 1, nil)
t:grow_left(&A, 2)
end
test t.data == 1
test t.left.data == 2
test t.left.right.ptr == nil
test t.left.left.ptr == nil
test t.right.ptr == nil
end
testset "Grow right" do
terracode
var t = btree.new(&A, 1, nil)
t:grow_right(&A, 2)
end
test t.data == 1
test t.right.data == 2
test t.right.left.ptr == nil
test t.right.right.ptr == nil
test t.left.ptr == nil
end
testset "Grow" do
terracode
var t = btree.new(&A, 1, nil)
t:grow(&A, 2, 3)
end
test t.data == 1
test t.left.data == 2
test t.left.right.ptr == nil
test t.left.left.ptr == nil
test t.right.data == 3
test t.right.left.ptr == nil
test t.right.right.ptr == nil
end
end
end