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