This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
priorityqtest.mini
63 lines (54 loc) · 1.58 KB
/
priorityqtest.mini
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
/*
* Copyright 2020, Offchain Labs, Inc. All rights reserved.
*/
use std2::priorityq::priorityq_new;
use std2::priorityq::priorityq_isEmpty;
use std2::priorityq::priorityq_insert;
use std2::priorityq::priorityq_get;
throw write func main() {
asm(tests().1) { log };
}
throw func tests() -> string {
let q = priorityq_new::<string>();
if ( ! priorityq_isEmpty::<string>(q)) {
return "new queue isn't empty";
}
let q = priorityq_new::<uint>();
q = priorityq_insert::<uint>(q, 97, 3);
if (priorityq_isEmpty::<uint>(q)) {
return "queue with insert looks empty";
}
q = priorityq_new::<uint>();
let pq = priorityq_insert::<uint>(q, 97, 3);
if (pq == q) {
return "new queue is equal to one with contents";
}
q = priorityq_new::<uint>();
q = priorityq_insert::<uint>(q, 97, 3);
q = priorityq_insert::<uint>(q, 98, 2);
q = priorityq_insert::<uint>(q, 96, 4);
if let Some(res) = priorityq_get::<uint>(q) {
if (res.0 != 96) {
return "queue didn't place 96 at the front";
}
} else {
return "queue is somehow empty";
}
q = priorityq_new::<uint>();
let i = 0;
while (i < 58) {
q = priorityq_insert::<uint>(q, i+30, i+100);
i = i+1;
}
q = priorityq_insert::<uint>(q, 97, 293);
q = priorityq_insert::<uint>(q, 98, 292);
q = priorityq_insert::<uint>(q, 96, 294);
if let Some(res) = priorityq_get::<uint>(q) {
if (res.0 != 96) {
return "stress-tested queue didn't place 96 at the front";
}
} else {
return "stress-tested queue is somehow empty";
}
return "";
}