Skip to content

Commit

Permalink
Mod propspec for normalization of ZDRs
Browse files Browse the repository at this point in the history
These tests are not part of 6.c language.
  • Loading branch information
zoffixznet committed Sep 23, 2018
1 parent 95c19bc commit c4c673c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
29 changes: 13 additions & 16 deletions S32-num/fatrat.t
Expand Up @@ -278,26 +278,23 @@ subtest 'Rational.isNaN' => {
}

subtest '=== with 0-denominator FatRats' => {
plan 15;
plan 11;
sub postfix:<F> (Rat $_ --> FatRat) { FatRat.new: .numerator, .denominator }

# We normalize these Rationals, so only numerator's sign matters
is-deeply <0/0>F === <0/0>F, True, ' 0/0 === 0/0';
is-deeply <2/0>F === <2/0>F, True, ' 2/0 === 2/0';
is-deeply <-2/0>F === <-2/0>F, True, '-2/0 === -2/0';

is-deeply <0/0>F === <-2/0>F, False, ' 0/0 === -2/0';
is-deeply <0/0>F === <2/0>F, False, ' 0/0 === 2/0';
is-deeply <2/0>F === <0/0>F, False, ' 2/0 === 0/0';
is-deeply <5/0>F === <2/0>F, False, ' 5/0 === 2/0';
is-deeply <2/0>F === <5/0>F, False, ' 2/0 === 5/0';
is-deeply <-5/0>F === <-2/0>F, False, '-5/0 === -2/0';
is-deeply <-2/0>F === <-5/0>F, False, '-2/0 === -5/0';

is-deeply <0/0>F === <2/2>F, False, ' 0/0 === 2/2';
is-deeply <2/2>F === <0/0>F, False, ' 2/2 === 0/0';
is-deeply <5/2>F === <2/0>F, False, ' 5/2 === 2/0';
is-deeply <2/0>F === <5/2>F, False, ' 2/0 === 5/2';
is-deeply <-5/2>F === <-2/0>F, False, '-5/2 === -2/0';
is-deeply <-2/0>F === <-5/2>F, False, '-2/0 === -5/2';

is-deeply <-2/0>F === <-2/0>F, True, '-2/0 === -2/0';
is-deeply <-2/0>F === <-4/0>F, True, '-2/0 === -4/0';
is-deeply <-2/0>F === <2/0>F, False, '-2/0 === -2/0';
is-deeply <-2/0>F === <0/0>F, False, '-2/0 === 0/0';

is-deeply <2/0>F === <-2/0>F, False, ' 2/0 === -2/0';
is-deeply <2/0>F === <4/0>F, True, ' 2/0 === 4/0';
is-deeply <2/0>F === <2/0>F, True, ' 2/0 === 2/0';
is-deeply <2/0>F === <0/0>F, False, ' 2/0 === 0/0';
}

# RT#130427
Expand Down
31 changes: 13 additions & 18 deletions S32-num/rat.t
Expand Up @@ -395,25 +395,21 @@ subtest 'Rational.isNaN' => {
}

subtest '=== with 0-denominator Rats' => {
plan 15;
plan 11;

is-deeply <0/0> === <0/0>, True, ' 0/0 === 0/0';
is-deeply <2/0> === <2/0>, True, ' 2/0 === 2/0';
is-deeply <-2/0> === <-2/0>, True, '-2/0 === -2/0';

is-deeply <0/0> === <-2/0>, False, ' 0/0 === -2/0';
is-deeply <0/0> === <2/0>, False, ' 0/0 === 2/0';
is-deeply <2/0> === <0/0>, False, ' 2/0 === 0/0';
is-deeply <5/0> === <2/0>, False, ' 5/0 === 2/0';
is-deeply <2/0> === <5/0>, False, ' 2/0 === 5/0';
is-deeply <-5/0> === <-2/0>, False, '-5/0 === -2/0';
is-deeply <-2/0> === <-5/0>, False, '-2/0 === -5/0';

is-deeply <0/0> === <2/2>, False, ' 0/0 === 2/2';
is-deeply <2/2> === <0/0>, False, ' 2/2 === 0/0';
is-deeply <5/2> === <2/0>, False, ' 5/2 === 2/0';
is-deeply <2/0> === <5/2>, False, ' 2/0 === 5/2';
is-deeply <-5/2> === <-2/0>, False, '-5/2 === -2/0';
is-deeply <-2/0> === <-5/2>, False, '-2/0 === -5/2';

is-deeply <-2/0> === <-2/0>, True, '-2/0 === -2/0';
is-deeply <-2/0> === <-4/0>, True, '-2/0 === -4/0';
is-deeply <-2/0> === <2/0>, False, '-2/0 === -2/0';
is-deeply <-2/0> === <0/0>, False, '-2/0 === 0/0';

is-deeply <2/0> === <-2/0>, False, ' 2/0 === -2/0';
is-deeply <2/0> === <4/0>, True, ' 2/0 === 4/0';
is-deeply <2/0> === <2/0>, True, ' 2/0 === 2/0';
is-deeply <2/0> === <0/0>, False, ' 2/0 === 0/0';
}

# RT #130606
Expand Down Expand Up @@ -633,10 +629,9 @@ subtest 'Rational keeps nu/de in proper types' => {
is-deeply .denominator, Foo.new(2), 'denominator';
}

# 6.d TODO XXX: are we normalizing ZDRs or not normalizing them?
with Bar.new: Foo.new(42), Foo.new: 0 {
# numerator is meant to be normalized, so it'll end up as 1
is-deeply .numerator, Foo.new(42), 'numerator (zero-denom rational)';
is-deeply .numerator, Foo.new(1), 'numerator (zero-denom rational)';
is-deeply .denominator, Foo.new(0), 'denominator (zero-denom rational)';
}
}
Expand Down

0 comments on commit c4c673c

Please sign in to comment.