/
06-find-min.t
54 lines (47 loc) · 1.28 KB
/
06-find-min.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
use v6;
use Test;
use Algorithm::MinMaxHeap;
{
my $heap = Algorithm::MinMaxHeap[Int].new;
$heap.insert(0);
$heap.insert(1);
$heap.insert(2);
$heap.insert(3);
$heap.insert(4);
$heap.insert(5);
$heap.insert(6);
$heap.insert(7);
$heap.insert(8);
is $heap.find-min, 0;
}
{
my class State {
also does Algorithm::MinMaxHeap::Comparable[State];
has Int $.value;
has $.payload;
submethod BUILD(:$!value) { }
method compare-to(State $s) {
if (self.value == $s.value) {
return Order::Same;
}
if (self.value > $s.value) {
return Order::More;
}
if (self.value < $s.value) {
return Order::Less;
}
}
}
my $heap = Algorithm::MinMaxHeap[Algorithm::MinMaxHeap::Comparable].new;
$heap.insert(State.new(value => 0));
$heap.insert(State.new(value => 1));
$heap.insert(State.new(value => 2));
$heap.insert(State.new(value => 3));
$heap.insert(State.new(value => 4));
$heap.insert(State.new(value => 5));
$heap.insert(State.new(value => 6));
$heap.insert(State.new(value => 7));
$heap.insert(State.new(value => 8));
is $heap.find-min.value, 0;
}
done-testing;