Proper boundary checks & tests for them
[algorithm-bit-xs.git] / t / Algorithm-BIT-XS.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 24;
6 BEGIN { use_ok('Algorithm::BIT::XS') };
7 BEGIN { use_ok('Algorithm::BIT2D::XS') };
8
9 my $bit = Algorithm::BIT::XS->new(25);
10 ok !eval{$bit->query(26); 1}, 'query(26) fails';
11 ok !eval{$bit->update(26, 5); 1}, 'update(26, 5) fails';
12 is $bit->query(5), 0;
13 $bit->update(4, 2);
14 $bit->update(5, 3);
15 is $bit->query(3), 0;
16 is $bit->query(4), 2;
17 is $bit->query(5), 5;
18 is $bit->query(6), 5;
19 is $bit->query(0), 0;
20
21 $bit->update(5, -3);
22 is $bit->query(5), 2;
23
24 $bit->update(17, 50);
25 is $bit->query(25), 52;
26 is $bit->get(25), 0;
27
28 $bit->set(17, 30);
29 is $bit->query(25), 32;
30 is $bit->get(17), 30;
31
32 $bit->clear;
33 $bit->set(16,10);
34 is $bit->query(15), 0;
35 is $bit->query(16), 10;
36
37
38 my $bit2d = Algorithm::BIT2D::XS->new(10, 5);
39 ok !eval{$bit2d->query(11, 5); 1}, 'query(11, 5) fails';
40 ok !eval{$bit2d->query(10, 6); 1}, 'query(10, 6) fails';
41 ok !eval{$bit2d->update(11, 5, 2); 1}, 'update(11, 5, 2) fails';
42 ok !eval{$bit2d->update(10, 6, 2); 1}, 'update(10, 6, 2) fails';
43 is $bit2d->query(5, 5), 0;
44 $bit2d->update(4, 4, 2);
45 $bit2d->update(5, 1, 3);
46 is $bit2d->query(5, 5), 5;
47 is $bit2d->query(5, 2), 3;
This page took 0.025035 seconds and 4 git commands to generate.