Skip to content

Commit

Permalink
Add a unit test for the random unit vector generator code. It doesn't…
Browse files Browse the repository at this point in the history
… verify the randomness though.
  • Loading branch information
Max Maischein committed Jun 4, 2011
1 parent 9f29be1 commit 194944e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions t/01-random-unit-vector.t
@@ -0,0 +1,21 @@
#!perl -w
use strict;
use Test::More;
use Random::PoissonDisc;

my $tests = 100;
my $dimensions = 10;

plan tests => $tests*$dimensions;

# Sample $tests vectors and check their length

for my $dim (1..$dimensions) {
for (1..$tests) {
my $v = Random::PoissonDisc::random_unit_vector($dim);
my $n = Random::PoissonDisc::norm(@$v);

cmp_ok abs($n-1), '<=', 0.0001, "Dimension $dim"
or diag "Dimension $dim: Generated @$v with norm $n";
};
};

0 comments on commit 194944e

Please sign in to comment.