Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding basic tests for advent 2013 day
  • Loading branch information
dwarring committed Mar 12, 2014
1 parent c69b51d commit 6ef36a7
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions integration/advent2013-day08.t
@@ -0,0 +1,68 @@
use v6;
use Test;
plan 11;

class Vector is Array {

method new (*@values is copy, *%named) {
@values[0] = %named<x> if %named<x> :exists;
@values[1] = %named<y> if %named<y> :exists;
@values[2] = %named<z> if %named<z> :exists;

nextwith(|@values);
}

method x () is rw { self[0] }
method y () is rw { self[1] }
method z () is rw { self[2] }

method magnitude () {
sqrt [+] self »**» 2
}

method subtract (@vec) {
self.new( self »-« @vec )
}
}

my @vec := Vector.new(1, 2, 3);
is @vec.WHAT.gist, '(Vector)';

my @vec-wrong = Vector.new(1, 2, 3);
is @vec-wrong.WHAT.gist, '(Array)';

my $vec := Vector.new(1, 2, 3);
is $vec.WHAT.gist, '(Vector)';

my @position := Vector.new(1, 2);
my @destination = 4, 6;
my $distance = @position.subtract(@destination).magnitude;
is $distance, 5;

{
my $vec = Vector.new(0, 1);
is $vec.magnitude, 1;
};

{
my $vec = Vector.new(1, 2);
$vec.z = 3;
is $vec.WHAT.gist, '(Vector)';
is $vec.gist, '1 2 3';
};

{
my $vec = Vector.new(:x(1), :y(2));
$vec.z = 3;
is $vec.gist, '1 2 3';
}

{
my $vec = Vector.new(:y(3), 0);
$vec.x++;
$vec[1]--;
$vec.z = 3;

my $n = 1;
is($_, $n++) for @$vec;
}

1 comment on commit 6ef36a7

@dwarring
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's 2013 advent day 08

Please sign in to comment.