File: 1-basic.t

package info (click to toggle)
libmath-convexhull-perl 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 84 kB
  • sloc: perl: 114; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More tests => 8;

use lib 'lib';
use_ok('Math::ConvexHull');
use Math::ConvexHull qw/convex_hull/;

my $start = [[1,0],[1,1],[0.1,0.05],[0.9,0.5],[0,0]];
my $t = convex_hull($start);
ok(1, 'convex_hull() did not complain');

my %results = (map {($_, undef)} @$start);
ok(
	(
		@$t == 3
			and
		(map {delete $results{$_}} @$t)
			and
		(
			exists $results{$start->[2]} and
			exists $results{$start->[3]}
		)
	),
	'convex_hull returned correct result.'
);



{
  # another one
  my $from = [[0,0], [1,0],[0.2,0.9], [0.2,0.5], [0.2,0.5], [0,1], [1,1],]; 
  #my $from = [[0,0], [1,0], [0.2,0.5], [0.2,0.5], [0.2,0.9], [0,1], [1,1]];
  my $to   = [[0,0], [1,0], [1,1], [0,1]];
  my $res = convex_hull($from);
  ok(@$res == @$to, "convex_hull returns correct number of points");
  for (0..3) {
    ok(
      _feq($res->[$_][0], $to->[$_][0]) && _feq($res->[$_][1], $to->[$_][1]),
      "Point number $_ in hull is correct"
    );
  }
}

sub _feq {
  return 1 if ($_[0]+1e-15 > $_[1]) && ($_[0]-1e-15 < $_[1]);
  return 0;
}