blob: b5921cc339261b62bbc859cd5f2fed1b73696c16 [file] [log] [blame]
Akron1622dd92015-12-09 22:34:26 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
6use_ok('KorAP::Tokenizer::Range');
7
8my $range = KorAP::Tokenizer::Range->new;
9
10# Set a gap from 0 to 2, refering to position 0
11$range->gap(0, 2, 0);
12
13# Set a range from 3 to 14, refering to position 0
14$range->set(3, 14, 0);
15
16is($range->lookup(3), 0, 'Lookup is fine');
17
18# Set a gap from 15 to 16, refering to position 1
19$range->gap(15, 16, 1);
20$range->set(17, 20, 1);
21$range->set(21, 28, 2);
22
23is($range->lookup(3), 0, 'Lookup is fine');
24
25is($range->lookup(6), 0, 'Lookup is fine');
26is($range->lookup(14), 0, 'Lookup is fine');
27
28ok(!$range->lookup(1), 'Lookup is fine');
29ok(!$range->lookup(16), 'Lookup is fine');
30
31is($range->before(0), 0, 'Before is fine');
32is($range->before(1), 0, 'Before is fine');
33is($range->before(2), 0, 'Before is fine');
34is($range->before(3), 0, 'Before is fine');
35is($range->before(4), 0, 'Before is fine');
36is($range->before(15), 0, 'Before is fine');
37is($range->before(23), 1, 'Before is fine');
38ok(!$range->before(590), 'No range here');
39
40is($range->after(0), 0, 'After is fine');
41is($range->after(1), 0, 'After is fine');
42is($range->after(2), 0, 'After is fine');
43is($range->after(3), 0, 'After is fine');
44is($range->after(14), 0, 'After is fine');
45is($range->after(15), 1, 'After is fine');
46
47is($range->to_string,
48 '[0,2,!-1:0][3,14,0][15,16,!0:1][17,20,1][21,28,2][29,100,...]...',
49 'ToString is fine');
50done_testing;
51__END__