|
2 | 2 |
|
3 | 3 | use v6;
|
4 | 4 | use Test;
|
5 |
| -plan 6; |
| 5 | +plan 7; |
6 | 6 |
|
7 | 7 | role BatteryPower {
|
8 | 8 | has $.battery-type;
|
@@ -54,25 +54,44 @@ is $mug.WHAT.perl , 'Cup[EggNog]' , 'the $mug is a Cup of EggNog';
|
54 | 54 | is $glass.WHAT.perl , 'Glass[MulledWine]' , 'the $glass is a Glass of MulledWine';
|
55 | 55 | is $valuable.WHAT.perl , 'Tray[Glass[MulledWine]]' , 'the $valuable is a Tray of Glass of MulledWine';
|
56 | 56 |
|
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;'; |
77 | 96 |
|
78 | 97 | done();
|
0 commit comments