-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathbs_stack_test.js
163 lines (145 loc) · 3.75 KB
/
bs_stack_test.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Mt = require("./mt.js");
var Caml_option = require("../../lib/js/caml_option.js");
var Js_undefined = require("../../lib/js/js_undefined.js");
var Belt_MutableQueue = require("../../lib/js/belt_MutableQueue.js");
var Belt_MutableStack = require("../../lib/js/belt_MutableStack.js");
var suites = {
contents: /* [] */0
};
var test_id = {
contents: 0
};
function eq(loc, x, y) {
Mt.eq_suites(test_id, suites, loc, x, y);
}
function inOrder(v) {
var current = v;
var s = {
root: undefined
};
var q = {
length: 0,
first: undefined,
last: undefined
};
while(current !== undefined) {
var v$1 = current;
Belt_MutableStack.push(s, v$1);
current = v$1.left;
};
while(s.root !== undefined) {
current = Belt_MutableStack.popUndefined(s);
var v$2 = current;
Belt_MutableQueue.add(q, v$2.value);
current = v$2.right;
while(current !== undefined) {
var v$3 = current;
Belt_MutableStack.push(s, v$3);
current = v$3.left;
};
};
return Belt_MutableQueue.toArray(q);
}
function inOrder3(v) {
var current = v;
var s = {
root: undefined
};
var q = {
length: 0,
first: undefined,
last: undefined
};
while(current !== undefined) {
var v$1 = current;
Belt_MutableStack.push(s, v$1);
current = v$1.left;
};
Belt_MutableStack.dynamicPopIter(s, (function (popped) {
Belt_MutableQueue.add(q, popped.value);
var current = popped.right;
while(current !== undefined) {
var v = current;
Belt_MutableStack.push(s, v);
current = v.left;
};
}));
return Belt_MutableQueue.toArray(q);
}
function inOrder2(v) {
var todo = true;
var cursor = v;
var s = {
root: undefined
};
var q = {
length: 0,
first: undefined,
last: undefined
};
while(todo) {
if (cursor !== undefined) {
var v$1 = cursor;
Belt_MutableStack.push(s, v$1);
cursor = v$1.left;
} else if (s.root !== undefined) {
cursor = Belt_MutableStack.popUndefined(s);
var current = cursor;
Belt_MutableQueue.add(q, current.value);
cursor = current.right;
} else {
todo = false;
}
};
}
function n(l, r, a) {
return {
value: a,
left: Js_undefined.fromOption(l),
right: Js_undefined.fromOption(r)
};
}
var test1 = n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), Caml_option.some(n(undefined, undefined, 5)), 2)), Caml_option.some(n(undefined, undefined, 3)), 1);
function pushAllLeft(st1, s1) {
var current = st1;
while(current !== undefined) {
var v = current;
Belt_MutableStack.push(s1, v);
current = v.left;
};
}
var test2 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), undefined, 1)), undefined, 3);
var test3 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), Caml_option.some(n(undefined, undefined, 3)), 1);
eq("File \"bs_stack_test.res\", line 98, characters 3-10", inOrder(test1), [
4,
2,
5,
1,
3
]);
eq("File \"bs_stack_test.res\", line 99, characters 3-10", inOrder3(test1), [
4,
2,
5,
1,
3
]);
Mt.from_pair_suites("bs_stack_test.res", suites.contents);
var S;
var Q;
exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.S = S;
exports.Q = Q;
exports.inOrder = inOrder;
exports.inOrder3 = inOrder3;
exports.inOrder2 = inOrder2;
exports.n = n;
exports.test1 = test1;
exports.pushAllLeft = pushAllLeft;
exports.test2 = test2;
exports.test3 = test3;
/* test1 Not a pure module */