11import flat_tree.*
2- import tape.*
2+ import datkt. tape.*
33
4- const val TAP_VERSION = 13
5- const val TAP_HEADER = " TAP version ${ TAP_VERSION } "
4+ fun main ( args : Array < String >) {
5+ val tree = Tree ()
66
7- typealias OK = (ok: Boolean? , comment: String? ) -> Unit?
7+ test(" base blocks" , fun (t : Test ) {
8+ println (" init" )
9+ t.assert (0L == ft_index(0L , 0L ), AssertionOptions ( message = " 0L == ft_index(0L, 0L)" ))
10+ t.assert (2L == ft_index(0L , 1L ), AssertionOptions ( message = " 2L == ft_index(0L, 1L)" ))
11+ t.assert (4L == ft_index(0L , 2L ), AssertionOptions ( message = " 4L == ft_index(0L, 2L)" ))
812
9- fun main (args : Array <String >) {
10- println (TAP_HEADER )
11-
12- val iterator = Iterator (0L )
13-
14- println (" _" )
15- println (iterator.index)
16- println (iterator.offset)
17- println (iterator.factor)
18- iterator.seek(107L )
19-
20- println (" _" )
21- println ( truthy(true == iterator.isLeft()) )
22- println ( truthy(false == iterator.isRight()) )
23- println (iterator.index)
24- println (iterator.offset)
25- println (iterator.factor)
26- iterator.seek(1L )
27-
28- println (" _" )
29- println ( truthy(true == iterator.isLeft()) )
30- println ( truthy(false == iterator.isRight()) )
31- println (iterator.index)
32- println (iterator.offset)
33- println (iterator.factor)
34-
35- println (" hi" )
36- }
13+ t.end()
14+ })
15+
16+ test(" tree.parents" , fun (t : Test ) {
17+ t.assert (1L == ft_index(1L , 0L ), AssertionOptions ( message = " 1L == ft_index(1L, 0L)" ))
18+ t.assert (5L == ft_index(1L , 1L ), AssertionOptions ( message = " 5L == ft_index(1L, 1L)" ))
19+ t.assert (3L == ft_index(2L , 0L ), AssertionOptions ( message = " 3L == ft_index(2L, 0L)" ))
20+
21+ t.assert (1L == tree.parent(0L , 0L ), AssertionOptions ( message = " 1L == tree.parent(0L, 0L)" ))
22+ t.assert (1L == tree.parent(2L , 0L ), AssertionOptions ( message = " 1L == tree.parent(2L, 0L)" ))
23+ t.assert (3L == tree.parent(1L , 0L ), AssertionOptions ( message = " 3L == tree.parent(1L, 0L)" ))
24+
25+ t.end()
26+ })
27+
28+ test(" tree.children" , fun (t : Test ) {
29+ t.assert (null == tree.children(0L , null ), AssertionOptions ( message = " null == tree.children(0L, null)" ))
30+ t.assert (arrayOf(0L , 2L ) == tree.children(1L , null ), AssertionOptions ( message = " arrayOf(0L, 2L) == tree.children(1L, null)" ))
31+ t.assert (arrayOf(1L , 5L ) == tree.children(3L , null ), AssertionOptions ( message = " arrayOf(1L, 5L) == tree.children(3L, null)" ))
32+ t.assert (arrayOf(8L , 10L ) == tree.children(9L , null ), AssertionOptions ( message = " arrayOf(8L, 10L) == tree.children(9L, null)" ))
33+
34+ t.end()
35+ })
36+
37+ test(" tree.leftChild" , fun (t : Test ) {
38+ t.assert (- 1L == tree.leftChild(0L , null ), AssertionOptions ( message = " -1L == tree.leftChild(0L, null)" ))
39+ t.assert (0L == tree.leftChild(1L , null ), AssertionOptions ( message = " 0L == tree.leftChild(1L, null)" ))
40+ t.assert (1L == tree.leftChild(3L , null ), AssertionOptions ( message = " 1L == tree.leftChild(3L, null)" ))
41+
42+ t.end()
43+ })
44+
45+ test(" tree.rightChild" , fun (t : Test ) {
46+ t.assert (- 1L == tree.rightChild(0L , null ), AssertionOptions ( message = " -1L == tree.rightChild(0L, null)" ))
47+ t.assert (2L == tree.rightChild(1L , null ), AssertionOptions ( message = " 2L == tree.rightChild(1L, null)" ))
48+ t.assert (5L == tree.rightChild(3L , null ), AssertionOptions ( message = " 5L == tree.rightChild(3L, null)" ))
49+
50+ t.end()
51+ })
52+
53+ test(" tree.siblings" , fun (t : Test ) {
54+ t.assert (2L == tree.sibling(0L , null ), AssertionOptions ( message = " 2L == tree.sibling(0L, null)" ))
55+ t.assert (0L == tree.sibling(2L , null ), AssertionOptions ( message = " 0L == tree.sibling(2L, null)" ))
56+ t.assert (5L == tree.sibling(1L , null ), AssertionOptions ( message = " 5L == tree.sibling(1L, null)" ))
57+ t.assert (1L == tree.sibling(5L , null ), AssertionOptions ( message = " 1L == tree.sibling(5L, null)" ))
58+
59+ t.end()
60+ })
61+
62+ // test.skip("fullRoots", fun(t: Test) {
63+ // t.assert(arrayOf<Long>() == tree.fullRoots(0L, null), AssertionOptions( message = "arrayOf<Long>() == tree.fullRoots(0L, null)" ))
64+ // t.assert(arrayOf(0L) == tree.fullRoots(2L, null), AssertionOptions( message = "arrayOf(0L) == tree.fullRoots(2L, null)" ))
65+ // t.assert(arrayOf(3L) == tree.fullRoots(8L, null), AssertionOptions( message = "arrayOf(3L) == tree.fullRoots(8L, null)" ))
66+ // t.assert(arrayOf(7L, 17L) == tree.fullRoots(20L, null), AssertionOptions( message = "arrayOf(7L, 17L) == tree.fullRoots(20L, null)" ))
67+ // t.assert(arrayOf(7L, 16L) == tree.fullRoots(18L, null), AssertionOptions( message = "arrayOf(7L, 16L) == tree.fullRoots(18L, null)" ))
68+ // t.assert(arrayOf(7L) == tree.fullRoots(16L, null), AssertionOptions( message = "arrayOf(7L) == tree.fullRoots(16L, null)" ))
69+
70+ // t.end()
71+ // })
72+
73+ test(" ft_depth" , fun (t : Test ) {
74+ t.assert (0L == ft_depth(0L ), AssertionOptions ( message = " 0L == ft_depth(0L)" ))
75+ t.assert (1L == ft_depth(1L ), AssertionOptions ( message = " 1L == ft_depth(1L)" ))
76+ t.assert (0L == ft_depth(2L ), AssertionOptions ( message = " 0L == ft_depth(2L)" ))
77+ t.assert (2L == ft_depth(3L ), AssertionOptions ( message = " 2L == ft_depth(3L)" ))
78+ t.assert (0L == ft_depth(4L ), AssertionOptions ( message = " 0L == ft_depth(4L)" ))
79+
80+ t.end()
81+ })
82+
83+ test(" ft_offset" , fun (t : Test ) {
84+ t.assert (0L == ft_offset(0L , null ), AssertionOptions ( message = " 0L == ft_offset(0L, null)" ))
85+ t.assert (0L == ft_offset(1L , null ), AssertionOptions ( message = " 0L == ft_offset(1L, null)" ))
86+ t.assert (1L == ft_offset(2L , null ), AssertionOptions ( message = " 1L == ft_offset(2L, null)" ))
87+ t.assert (0L == ft_offset(3L , null ), AssertionOptions ( message = " 0L == ft_offset(3L, null)" ))
88+ t.assert (2L == ft_offset(4L , null ), AssertionOptions ( message = " 2L == ft_offset(4L, null)" ))
89+
90+ t.end()
91+ })
92+
93+ test(" tree.spans" , fun (t : Test ) {
94+ t.assert (arrayOf(0L , 0L ) == tree.spans(0L , null ), AssertionOptions ( message = " arrayOf(0L, 0L) == tree.spans(0L, null)" ))
95+ t.assert (arrayOf(0L , 2L ) == tree.spans(1L , null ), AssertionOptions ( message = " arrayOf(0L, 2L) == tree.spans(1L, null)" ))
96+ t.assert (arrayOf(0L , 6L ) == tree.spans(3L , null ), AssertionOptions ( message = " arrayOf(0L, 6L) == tree.spans(3L, null)" ))
97+ t.assert (arrayOf(16L , 30L ) == tree.spans(23L , null ), AssertionOptions ( message = " arrayOf(16L, 30L) == tree.spans(23L, null)" ))
98+ t.assert (arrayOf(24L , 30L ) == tree.spans(27L , null ), AssertionOptions ( message = " arrayOf(24L, 30L) == tree.spans(27L, null)" ))
99+
100+ t.end()
101+ })
102+
103+ test(" tree.leftSpan" , fun (t : Test ) {
104+ t.assert (0L == tree.leftSpan(0L , null ), AssertionOptions ( message = " 0L == tree.leftSpan(0L, null)" ))
105+ t.assert (0L == tree.leftSpan(1L , null ), AssertionOptions ( message = " 0L == tree.leftSpan(1L, null)" ))
106+ t.assert (0L == tree.leftSpan(3L , null ), AssertionOptions ( message = " 0L == tree.leftSpan(3L, null)" ))
107+ t.assert (16L == tree.leftSpan(23L , null ), AssertionOptions ( message = " 16L == tree.leftSpan(23L, null)" ))
108+ t.assert (24L == tree.leftSpan(27L , null ), AssertionOptions ( message = " 24L == tree.leftSpan(27L)" ))
109+
110+ t.end()
111+ })
112+
113+ test(" tree.rightSpan" , fun (t : Test ) {
114+ t.assert (0L == tree.rightSpan(0L , null ), AssertionOptions ( message = " 0L == tree.rightSpan(0L, null)" ))
115+ t.assert (2L == tree.rightSpan(1L , null ), AssertionOptions ( message = " 2L == tree.rightSpan(1L, null)" ))
116+ t.assert (6L == tree.rightSpan(3L , null ), AssertionOptions ( message = " 6L == tree.rightSpan(3L, null)" ))
117+ t.assert (30L == tree.rightSpan(23L , null ), AssertionOptions ( message = " 30L == tree.rightSpan(23L, null)" ))
118+ t.assert (30L == tree.rightSpan(27L , null ), AssertionOptions ( message = " 30L == tree.rightSpan(27L, null)" ))
119+
120+ t.end()
121+ })
122+
123+ test(" tree.count" , fun (t : Test ) {
124+ t.assert (1L == tree.count(0L , null ), AssertionOptions ( message = " 1L == tree.count(0L, null)" ))
125+ t.assert (3L == tree.count(1L , null ), AssertionOptions ( message = " 3L == tree.count(1L, null)" ))
126+ t.assert (7L == tree.count(3L , null ), AssertionOptions ( message = " 7L == tree.count(3L, null)" ))
127+ t.assert (3L == tree.count(5L , null ), AssertionOptions ( message = " 3L == tree.count(5L, null)" ))
128+ t.assert (15L == tree.count(23L , null ), AssertionOptions ( message = " 15L == tree.count(23L, null)" ))
129+ t.assert (7L == tree.count(27L , null ), AssertionOptions ( message = " 7L == tree.count(27L, null)" ))
130+
131+ t.end()
132+ })
133+
134+ test(" parent > int32" , fun (t : Test ) {
135+ t.assert (10000000001L == tree.parent(10000000000L , null ), AssertionOptions ( message = " 10000000001L == tree.parent(10000000000L)" ))
136+ t.end()
137+ })
138+
139+ test(" child to parent to child" , fun (t : Test ) {
140+ var child: Long = 0
141+ for (i in 0 .. 50 ) child = tree.parent(child, null )
142+ t.assert (1125899906842623L == child, AssertionOptions ( message = " 1125899906842623L == child" ))
143+ for (j in 0 .. 50 ) child = tree.leftChild(child, null )
144+ t.assert (0L == child, AssertionOptions ( message = " 0L == child" ))
145+
146+ t.end()
147+ })
148+
149+ test(" iterator" , fun (t : Test ) {
150+ val iterator = Iterator (0L )
151+
152+ t.assert (0L == iterator.index, AssertionOptions ( message = " 0L == iterator.index" ))
153+ t.assert (1L == iterator.parent(), AssertionOptions ( message = " 1L == iterator.parent()" ))
154+ t.assert (3L == iterator.parent(), AssertionOptions ( message = " 3L == iterator.parent()" ))
155+ t.assert (7L == iterator.parent(), AssertionOptions ( message = " 7L == iterator.parent()" ))
156+ t.assert (11L == iterator.rightChild(), AssertionOptions ( message = " 11L == iterator.rightChild()" ))
157+ t.assert (9L == iterator.leftChild(), AssertionOptions ( message = " 9L == iterator.leftChild()" ))
158+ println (" iterator.next()" )
159+ println (iterator.next())
160+ t.assert (13L == iterator.next(), AssertionOptions ( message = " 13L == iterator.next()" ))
161+ t.assert (12L == iterator.leftSpan(), AssertionOptions ( message = " 12L == iterator.leftSpan()" ))
162+
163+ t.end()
164+ })
165+
166+ test(" iterator, non-leaf start" , fun (t : Test ) {
167+ val iterator = Iterator (1L )
168+
169+ t.assert (1L == iterator.index, AssertionOptions ( message = " 1L == iterator.index" ))
170+ t.assert (3L == iterator.parent(), AssertionOptions ( message = " 3L == iterator.parent()" ))
171+ t.assert (7L == iterator.parent(), AssertionOptions ( message = " 7L == iterator.parent()" ))
172+ t.assert (11L == iterator.rightChild(), AssertionOptions ( message = " 11L == iterator.rightChild()" ))
173+ t.assert (9L == iterator.leftChild(), AssertionOptions ( message = " 9L == iterator.leftChild()" ))
174+ t.assert (13L == iterator.next(), AssertionOptions ( message = " 13L == iterator.next()" ))
175+ t.assert (12L == iterator.leftSpan(), AssertionOptions ( message = " 12L == iterator.leftSpan()" ))
176+
177+ t.end()
178+ })
179+
180+ datkt.tape.collect()
181+ }
0 commit comments