- or download this
# File: AngularDifference.pm
...
}
1;
- or download this
# File: AngularDifference.t
...
# multiples of 360-degrees shouldn't matter
my ($a,$b) = (360 * 2, 360 * 4);
is( angdiff($a,$b+23),23, "$a,$b+23 -> 23" ); # case 6
- or download this
$ perl AngularDifference.t
1..6
...
# expected: '90'
ok 6 - 720,1440+23 -> 23
# Looks like you failed 1 tests of 6.
- or download this
sub angdiff($$) {
my ($a, $b) = @_;
return abs($a - $b) % 180;
}
- or download this
$ perl AngularDifference.t
1..6
...
ok 4 - 45,0 -> 45
ok 5 - 0,270 -> 90, not 270
ok 6 - 720,1440+23 -> 23
- or download this
is( angdiff( 90, 90), 0, "zero at 90" ); # case 2
- or download this
# File: AngularDifference.l.t
...
##[ a <- Int, diff <- Int(range=>[-180,180]) ]##
angdiff($a, $a + $diff) == abs($diff)
}, name => "angdiff holds to defn of angular difference";
- or download this
##[ a <- Int, diff <- Int(range=>[-180,180]) ]##
- or download this
angdiff($a, $a + $diff) == abs($diff)
- or download this
$ perl AngularDifference.l.t
1..1
...
# Counterexample:
# $a = 148;
# $diff = 180;
- or download this
When $a = 0
...
190 170 10 <-- Oops
200 160 20 <-- Oops
210 150 30 <-- Oops
- or download this
sub angdiff($$) {
my ($a, $b) = @_;
my $delta = ($a - $b) % 360;
return $delta > 180 ? 360 - $delta : $delta;
}
- or download this
$ perl AngularDifference.l.t
1..1
ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
- or download this
Property {
...
angdiff($a, $a + $diff) == abs($diff)
}, name => "angdiff holds to defn of angular difference";
- or download this
1..1
ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
# 58% 1 to 90
# 41% 91 to 180
# 0% zero
- or download this
Property {
...
angdiff($a, $b) == abs($diff)
}, name => "angdiff holds to defn of angular difference";
- or download this
1..1
ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
# 98% > 360
# 0% 181 to 360
# 0% 1 to 90
- or download this
n <- OneOf( Int(range=>[-1,1]), Int )
- or download this
Property {
...
angdiff($a, $b) == abs($diff)
}, name => "angdiff holds to defn of angular difference";
- or download this
1..1
ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
...
# 9% 1 to 90
# 6% 91 to 180
# 0% zero
- or download this
n <- Frequency( [20,Int(range=>[-1,1])], [1,Int] )
- or download this
1..1
ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
...
# 18% 1 to 90
# 10% 91 to 180
# 0% zero