]> git.imager.perl.org - imager.git/blame - t/t81hlines.t
Test::More is now a pre-requisite for Imager, so remove it from the
[imager.git] / t / t81hlines.t
CommitLineData
a8652edf
TC
1#!perl -w
2use strict;
3use Test::More;
4use Imager;
5
6# this script tests an internal set of functions for Imager, they
7# aren't intended to be used at the perl level.
8# these functions aren't present in all Imager builds
9
10unless (Imager::Internal::Hlines::testing()) {
11 plan skip_all => 'Imager not built to run this test';
12}
13
14plan tests => 15;
15
16my $hline = Imager::Internal::Hlines::new(0, 100, 0, 100);
17my $base_text = 'start_y: 0 limit_y: 100 start_x: 0 limit_x: 100';
18ok($hline, "made hline");
19is($hline->dump, "$base_text\n", "check values");
20$hline->add(5, -5, 7);
21is($hline->dump, <<EOS, "check (-5, 7) added");
22$base_text
23 5 (1): [0, 2)
24EOS
25$hline->add(5, 8, 4);
26is($hline->dump, <<EOS, "check (8, 4) added");
27$base_text
28 5 (2): [0, 2) [8, 12)
29EOS
30$hline->add(5, 3, 3);
31is($hline->dump, <<EOS, "check (3, 3) added");
32$base_text
33 5 (3): [0, 2) [3, 6) [8, 12)
34EOS
35$hline->add(5, 2, 6);
36is($hline->dump, <<EOS, "check (2, 6) added");
37$base_text
38 5 (1): [0, 12)
39EOS
40# adding out of range should do nothing
41my $current = <<EOS;
42$base_text
43 5 (1): [0, 12)
44EOS
45$hline->add(6, -5, 5);
46is($hline->dump, $current, "check (6, -5, 5) not added");
47$hline->add(6, 100, 5);
48is($hline->dump, $current, "check (6, 100, 5) not added");
49$hline->add(-1, 5, 2);
50is($hline->dump, $current, "check (-1, 5, 2) not added");
51$hline->add(100, 5, 2);
52is($hline->dump, $current, "check (10, 5, 2) not added");
53
54# overlapped add check
55$hline->add(6, 2, 6);
56$hline->add(6, 3, 4);
57is($hline->dump, <<EOS, "check internal overlap merged");
58$base_text
59 5 (1): [0, 12)
60 6 (1): [2, 8)
61EOS
62
63# white box test: try to force reallocation of an entry
64for my $i (0..20) {
65 $hline->add(7, $i*2, 1);
66}
67is($hline->dump, <<EOS, "lots of segments");
68$base_text
69 5 (1): [0, 12)
70 6 (1): [2, 8)
71 7 (21): [0, 1) [2, 3) [4, 5) [6, 7) [8, 9) [10, 11) [12, 13) [14, 15) [16, 17) [18, 19) [20, 21) [22, 23) [24, 25) [26, 27) [28, 29) [30, 31) [32, 33) [34, 35) [36, 37) [38, 39) [40, 41)
72EOS
73# now merge them
74$hline->add(7, 1, 39);
75is($hline->dump, <<EOS, "merge lots of segments");
76$base_text
77 5 (1): [0, 12)
78 6 (1): [2, 8)
79 7 (1): [0, 41)
80EOS
81
82# clean object
83$hline = Imager::Internal::Hlines::new(50, 50, 50, 50);
84$base_text = 'start_y: 50 limit_y: 100 start_x: 50 limit_x: 100';
85
86# left merge
87$hline->add(51, 45, 10);
88$hline->add(51, 55, 4);
89is($hline->dump, <<EOS, "left merge");
90$base_text
91 51 (1): [50, 59)
92EOS
93
94# right merge
95$hline->add(52, 90, 5);
96$hline->add(52, 87, 5);
97is($hline->dump, <<EOS, "right merge");
98$base_text
99 51 (1): [50, 59)
100 52 (1): [87, 95)
101EOS
102
103undef $hline;