Add 2D binary indexed trees
[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 => 17;
6 BEGIN { use_ok('Algorithm::BIT::XS') };
7 BEGIN { use_ok('Algorithm::BIT2D::XS') };
8
9 my $bit = Algorithm::BIT::XS->new(100);
10 is $bit->query(5), 0;
11 $bit->update(4, 2);
12 $bit->update(5, 3);
13 is $bit->query(3), 0;
14 is $bit->query(4), 2;
15 is $bit->query(5), 5;
16 is $bit->query(6), 5;
17
18 $bit->update(5, -3);
19 is $bit->query(5), 2;
20
21 $bit->update(17, 50);
22 is $bit->query(25), 52;
23 is $bit->get(25), 0;
24
25 $bit->set(17, 30);
26 is $bit->query(25), 32;
27 is $bit->get(17), 30;
28
29 $bit->clear;
30 $bit->set(16,10);
31 is $bit->query(15), 0;
32 is $bit->query(16), 10;
33
34
35 my $bit2d = Algorithm::BIT2D::XS->new(100, 50);
36 is $bit2d->query(5, 5), 0;
37 $bit2d->update(4, 4, 2);
38 $bit2d->update(5, 1, 3);
39 is $bit2d->query(5, 5), 5;
40 is $bit2d->query(5, 2), 3;
This page took 0.025282 seconds and 4 git commands to generate.