Skip to content

Commit def56cb

Browse files
committed
enable/unfudge parametric role tests
1 parent 2946712 commit def56cb

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

integration/advent2009-day18.t

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use v6;
44
use Test;
5-
plan 6;
5+
plan 7;
66

77
role BatteryPower {
88
has $.battery-type;
@@ -54,25 +54,44 @@ is $mug.WHAT.perl , 'Cup[EggNog]' , 'the $mug is a Cup of EggNog';
5454
is $glass.WHAT.perl , 'Glass[MulledWine]' , 'the $glass is a Glass of MulledWine';
5555
is $valuable.WHAT.perl , 'Tray[Glass[MulledWine]]' , 'the $valuable is a Tray of Glass of MulledWine';
5656

57-
#?rakudo skip 'parse error'
58-
lives_ok 'role DeliveryCalculation[::Calculator] {has $.mass;method calculate($destination) {my $calc = Calculator.new(:$!mass);}}' , 'Refering to $.mass and $!mass';
59-
60-
#TODO: When rakudo can pass the previous test we can add full tests for the role.
61-
#~ role DeliveryCalculation[::Calculator] {
62-
#~ has $.mass;
63-
#~ has $.dimensions;
64-
#~ method calculate($destination) {
65-
#~ my $calc = Calculator.new(
66-
#~ :$!mass,
67-
#~ :$!dimensions
68-
#~ );
69-
#~ return $calc.delivery-to($destination);
70-
#~ }
71-
#~ }
72-
73-
#~ class Furniture does DeliveryCalculation[ByDimension] {
74-
#~ }
75-
#~ class HeavyWater does DeliveryCalculation[ByMass] {
76-
#~ }
57+
role DeliveryCalculation[::Calculator] {
58+
has $.mass;
59+
has $.dimensions;
60+
method calculate($destination) {
61+
my $calc = Calculator.new(
62+
:$!mass,
63+
:$!dimensions
64+
);
65+
return $calc.delivery-to($destination);
66+
}
67+
}
68+
69+
class ByDimension {
70+
has $.mass;
71+
has $.dimensions;
72+
method delivery-to($destination) {
73+
"ship $.dimensions to $destination";
74+
}
75+
}
76+
77+
class ByMass {
78+
has $.mass;
79+
has $.dimensions;
80+
method delivery-to($destination) {
81+
"lug $.mass to $destination";
82+
}
83+
}
84+
85+
class Furniture does DeliveryCalculation[ByDimension] {
86+
}
87+
88+
class HeavyWater does DeliveryCalculation[ByMass] {
89+
}
90+
91+
my $king-sized-bed = Furniture.new(:dimensions<1.8m X 2.0m X 0.5m>, :mass<30kg>);
92+
my $reactor-top-up = HeavyWater.new(:dimensions<1m X 1m X 1m>, :mass<1107Kg>);
93+
94+
is $king-sized-bed.calculate('down-town'), 'ship 1.8m X 2.0m X 0.5m to down-town', 'parametic role;';
95+
is $reactor-top-up.calculate('Springfield'), 'lug 1107Kg to Springfield', 'parametic role;';
7796

7897
done();

0 commit comments

Comments
 (0)