-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.sml
72 lines (54 loc) · 1.66 KB
/
testing.sml
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
structure TestingSctructure =
struct
structure IntCompare : COMPARE =
struct
datatype order = LESS | EQUAL | GREATER
type t = int
fun compare (x, y) =
if (x < y) then LESS
else if (x = y) then EQUAL
else GREATER
end
structure H = BinomialHeap(IntCompare)
val testHeap1 = H.insert (H.insert (H.insert (H.insert(H.insert (H.createHeap) 5) 1) 8) 3) 8
val testHeap1' = H.insert (H.insert (H.insert (H.insert (H.insert (H.createHeap) 8) 3) 1) 5) 8
val testHeap2 = H.insert (H.insert (H.insert (H.insert (H.createHeap) 14) 7) 8) 2
val testHeap2' = H.insert (H.insert (H.insert (H.insert (H.createHeap) 2) 8) 7) 14
val mergedHeap = H.merge testHeap1 testHeap2
(*
testHeap 1 = testHeap1':
8 1
/ |
3 5
|
8
testHeap 2 = testHeap2':
2
/ |
7 8
|
14
mergedHeap:
8 1
/ | \
2 3 5
/ | |
7 8 8
|
14
*)
val true = H.isEmpty (H.createHeap)
val false = H.isEmpty (mergedHeap)
val 5 = H.size testHeap1
val 4 = H.size testHeap2
val 9 = H.size mergedHeap
val 1 = H.findMin testHeap1
val 2 = H.findMin testHeap2
val 1 = H.findMin mergedHeap
val testHeap1 = (H.insert (H.insert(H.insert (H.createHeap) 5) 1) 8)
val testHeap1' = (H.insert (H.insert (H.insert (H.createHeap) 1) 5) 8)
val testHeap1 = (H.insert (H.insert (H.insert(H.insert (H.createHeap) 5) 1) 8) 3)
val testHeap1' = (H.insert (H.insert (H.insert (H.insert (H.createHeap) 3) 8) 1) 5)
val true = H.heapEqual (testHeap1, testHeap1')
val true = H.heapEqual (testHeap2, testHeap2')
end