-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainfall.pl
71 lines (61 loc) · 1.87 KB
/
rainfall.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Cell;
use Topology;
{ # Tests
use Test::More tests => 4;
{ # 3x3 field
my $topology = Topology->new( rows => 3,
cols => 3,
field => [ [1, 5, 2],
[2, 4, 7],
[3, 6, 9] ]);
my %basin = $topology->basins;
is_deeply(
[sort { $b <=> $a } values %basin],
[7, 2],
'Correctly divided 3x3 field into 2 basins'
);
}
{ # 1x1 field
my $topology = Topology->new( rows => 1,
cols => 1,
field => [ [1] ]);
my %basin = $topology->basins;
is_deeply(
[sort { $b <=> $a } values %basin],
[1],
'Correctly divided 1v1 field into 1 basin'
);
}
{ # 5x5 field
my $topology = Topology->new( rows => 5,
cols => 5,
field => [ [1, 0, 2, 5, 8],
[2, 3, 4, 7, 9],
[3, 5, 7, 8, 9],
[1, 2, 5, 4, 3],
[3, 3, 5, 2, 1] ]);
my %basin = $topology->basins;
is_deeply(
[sort { $b <=> $a } values %basin],
[11, 7, 7],
'Correctly divided 5v5 field into 3 basins'
);
}
{ # Test 4x4 field
my $topology = Topology->new( rows => 4,
cols => 4,
field => [ [0, 2, 1, 3],
[2, 1, 0, 4],
[3, 3, 3, 3],
[5, 5, 2, 1] ]);
my %basin = $topology->basins;
is_deeply(
[sort { $b <=> $a } values %basin],
[7, 5, 4],
'Correctly divided 4v4 field into 3 basins'
);
}
}