diff options
author | Matias Linares <matiaslina@gmail.com> | 2019-12-10 09:29:12 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2019-12-10 09:29:12 -0300 |
commit | 8f35c2dc6516303ae0786d08cc7912ccb8218f78 (patch) | |
tree | f27e82ddd3d7044e19d964345e2991d5cbf67f00 /t | |
download | advent-of-code-2019-8f35c2dc6516303ae0786d08cc7912ccb8218f78.tar.gz |
Initial commit
Diffstat (limited to 't')
-rw-r--r-- | t/01-basic.t | 62 | ||||
-rw-r--r-- | t/03-day3.t | 49 |
2 files changed, 111 insertions, 0 deletions
diff --git a/t/01-basic.t b/t/01-basic.t new file mode 100644 index 0000000..cebebd8 --- /dev/null +++ b/t/01-basic.t @@ -0,0 +1,62 @@ +use v6.c; +use Test; +use AdventOfCode; + +plan 8; + +my $test-vm = IntcodeVM.new(slurp("./data/day2-a.txt")); + +sub check-vm($input, $output, $name) { + my $vm = IntcodeVM.new($input); + $vm.run; + is $vm.memory.join(','), $output, $name; +} + +check-vm "1,0,0,0,99", "2,0,0,0,99", 'first example'; +check-vm "2,3,0,3,99", "2,3,0,6,99", 'second example'; +check-vm '2,4,4,5,99,0', '2,4,4,5,99,9801', 'third example'; +check-vm '1,1,1,4,99,5,6,0,99', '30,1,1,4,2,5,6,0,99', 'last example'; + +{ + my $input = slurp("./data/day2-a.txt"); + my $vm = IntcodeVM.new($input); + $vm.memory[1] = 12; + $vm.memory[2] = 2; + + $vm.run(); + + is $vm.output, 3760627, "day 2 first problem output"; +} + +subtest "VM don't change program after run", { + my $input = '1,1,1,4,99,5,6,0,99'; + my $vm = IntcodeVM.new($input); + $vm.run; + is $vm.program, $input.split(','), 'simple input'; +} + +subtest "VM resets memory", { + my $input = '1,1,1,4,99,5,6,0,99'; + my $vm = IntcodeVM.new($input); + $vm.run; + isnt $vm.memory, $vm.program, 'Run changes memory'; + my $memory = $vm.memory; + $vm.reset-memory(); + is $vm.memory, $vm.program, '.reset-memory() resets memory to program'; + + $test-vm.memory[1] = 12; + $test-vm.memory[2] = 2; + $test-vm.run; + is $test-vm.output, 3760627, "day 2 first problem output"; + $test-vm.reset-memory; + isnt $test-vm.output, 3760627, "day2 first problem resets memory"; +} + +subtest "day2 example", { + my $input = slurp("./data/day2-a.txt"); + my $vm = IntcodeVM.new($input); + $vm.run(); +} + + +done-testing; diff --git a/t/03-day3.t b/t/03-day3.t new file mode 100644 index 0000000..0d7c516 --- /dev/null +++ b/t/03-day3.t @@ -0,0 +1,49 @@ +use v6.d; +use Test; +use AdventOfCode::Utils; + +#plan 2; + +subtest "Point", { + ok Point.new, 'Default Point creation'; + is Point.new.x, 0, 'Default x'; + is Point.new.y, 0, 'Default y'; + ok Point.new(:1x, :2y), 'Point creation'; +} + +subtest "Line", { + my $point1 = Point.new; + my $point2 = Point.new; + + ok Line.new($point1, $point2), 'without named parameters'; + ok Line.new(:$point1, :$point2), 'with named parameters'; +} + +subtest "Wire", { + ok Wire.new("R1"); + my $wire = Wire.new("R1"); + + is $wire.points.elems, 1, 'wire has one point'; + isa-ok $wire.points.head, Point, 'Elements are points'; + my $point = $wire.points.head; + + is $point.x, 1, "First wire point x {$point}"; + is $point.y, 0, 'First wire point y {$point}'; + + subtest "intersection", { + my $line1 = Line.new( + :p(Point.new(:4x, :0y)), + :q(Point.new(:6x, :10y)) + ); + my $line2 = Line.new( + :p(Point.new(:0x, :3y)), + :q(Point.new(:10x, :7y)) + ); + + my $intersection = intersection($line1, $line2); + + is $intersection.x, 5, 'intersection x'; + is $intersection.y, 5, 'intersection y'; + } +} +done-testing; |