Akron | b27f694 | 2015-12-09 22:34:26 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Test::More; |
| 5 | |
| 6 | use_ok('KorAP::Tokenizer::Range'); |
| 7 | |
| 8 | my $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 | |
| 16 | is($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 | |
| 23 | is($range->lookup(3), 0, 'Lookup is fine'); |
| 24 | |
| 25 | is($range->lookup(6), 0, 'Lookup is fine'); |
| 26 | is($range->lookup(14), 0, 'Lookup is fine'); |
| 27 | |
| 28 | ok(!$range->lookup(1), 'Lookup is fine'); |
| 29 | ok(!$range->lookup(16), 'Lookup is fine'); |
| 30 | |
| 31 | is($range->before(0), 0, 'Before is fine'); |
| 32 | is($range->before(1), 0, 'Before is fine'); |
| 33 | is($range->before(2), 0, 'Before is fine'); |
| 34 | is($range->before(3), 0, 'Before is fine'); |
| 35 | is($range->before(4), 0, 'Before is fine'); |
| 36 | is($range->before(15), 0, 'Before is fine'); |
| 37 | is($range->before(23), 1, 'Before is fine'); |
| 38 | ok(!$range->before(590), 'No range here'); |
| 39 | |
| 40 | is($range->after(0), 0, 'After is fine'); |
| 41 | is($range->after(1), 0, 'After is fine'); |
| 42 | is($range->after(2), 0, 'After is fine'); |
| 43 | is($range->after(3), 0, 'After is fine'); |
| 44 | is($range->after(14), 0, 'After is fine'); |
| 45 | is($range->after(15), 1, 'After is fine'); |
| 46 | |
| 47 | is($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'); |
| 50 | done_testing; |
| 51 | __END__ |