Skip to content

Commit

Permalink
Spec custom parametarization of Rational
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Sep 26, 2017
1 parent b5aff33 commit a236ed9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion S32-num/rat.t
Expand Up @@ -3,7 +3,7 @@ use lib <t/spec/packages>;
use Test;
use Test::Util;

plan 845;
plan 846;

# Basic test functions specific to rational numbers.

Expand Down Expand Up @@ -444,4 +444,31 @@ subtest '.^roles on Rationals does not hang' => {
'custom class :D';
}

subtest 'custom parametarization of Rational' => {
# Prametartion with no args defaults to `Int` for both args
# If only one arg is given, the type of the second arg is the same as the first
plan 12;

my class FakeRat does Rational {}
my class FakeRatU does Rational[UInt ] {}
my class FakeRatUU does Rational[UInt, UInt] {}
my class FakeRatIU does Rational[Int, UInt] {}
my class FakeRatII does Rational[Int, Int] {}

isa-ok FakeRat .new(-1, 1), FakeRat, 'no parametarization; 2 Ints';
isa-ok FakeRatU .new( 1, 1), FakeRatU, '[UInt]; 2 UInts';
isa-ok FakeRatUU.new( 1, 1), FakeRatUU, '[UInt, UInt]; 2 UInts';
isa-ok FakeRatIU.new(-1, 1), FakeRatIU, '[Int, UInt]; Int, UInt';
isa-ok FakeRatII.new(-1, -1), FakeRatII, '[Int, Int]; 2 Ints';

constant E = X::TypeCheck;
throws-like { FakeRat .new: 1e0, 1 }, E, 'no parametarization; Num, Int';
throws-like { FakeRat .new: 1e0, 1e0 }, E, 'no parametarization; 2 Nums';
throws-like { FakeRat .new: 1, 1e0 }, E, 'no parametarization; Int, Num';
throws-like { FakeRatU .new: -1, 1 }, E, '[UInt]; Int, UInt';
throws-like { FakeRatUU.new: 1, -1 }, E, '[UInt, UInt]; UInt, Int';
throws-like { FakeRatIU.new: 1, -1 }, E, '[Int, UInt]; UInt, Int';
throws-like { FakeRatII.new: 1e0, 1e0 }, E, '[Int, Int]; 2 Nums';
}

# vim: ft=perl6

0 comments on commit a236ed9

Please sign in to comment.