File: 002basic.t

package info (click to toggle)
libmath-convexhull-monotonechain-perl 0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 21; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;
use Test::More;
BEGIN {use_ok('Math::ConvexHull::MonotoneChain');}
Math::ConvexHull::MonotoneChain->import('convex_hull');

my @tests = (
  {
    name => 'empty',
    in => [],
    out => [],
  },
  {
    name => 'one point',
    in => [[1, 2]],
    out => [[1, 2]],
  },
  {
    name => 'two points',
    in => [[1, 2], [3, 1]],
    out => [[1, 2], [3, 1]],
  },
  {
    name => 'simple square',
    in => [
      [0, 0],
      [0, 1],
      [1, 0],
      [0.5, 0.5],
      [1, 1],
    ],
    out => [
      [0, 0],
      [1, 0],
      [1, 1],
      [0, 1],
    ],
  },
  {
    name => 'simple square, dupes',
    in => [
      [0, 0],
      [0, 1],
      [0, 1],
      [1, 0],
      [0.5, 0.5],
      [0.5, 0.5],
      [1, 1],
    ],
    out => [
      [0, 0],
      [1, 0],
      [1, 1],
      [0, 1],
    ],
  },
  {
    name => 'simple square, dupes, almost border',
    in => [
      [0, 0],
      [0, 1],
      [0.5, 0.99],
      [0, 1],
      [1, 0],
      [0.5, 0.5],
      [0.5, 0.5],
      [1, 1],
    ],
    out => [
      [0, 0],
      [1, 0],
      [1, 1],
      [0, 1],
    ],
  },
);

foreach my $test (@tests) {
  my $rv = convex_hull($test->{in});
  is_deeply($rv, $test->{out}, "Test '$test->{name}': output as expected")
    or do {require Data::Dumper; warn Dumper $rv};
}

done_testing;