Skip to content

Commit 0e1bbf8

Browse files
committed
Adding tests for "Micro assembly".
1 parent 69dcfad commit 0e1bbf8

File tree

11 files changed

+212
-1
lines changed

11 files changed

+212
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [3.11.0] - 2022-07-31
88
### Added
99
- Tests for "Someone's acting sus....".
1010
- Tests for "Personal best".
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Lunar lockout".
3737
- Tests for "Shikaku solver".
3838
- Tests for "Hexagonal maze".
39+
- Tests for "Micro assembly".
3940

4041
### Changed
4142
- Renaming "Linear Bézier curves" to "Cubic Bézier curves".
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\MicroAssembly;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Micro assembly" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/micro-assembly
12+
*/
13+
class MicroAssembly implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d %d %d", $a, $b, $c, $d);
18+
fscanf($stdin, "%d", $n);
19+
for ($i = 0; $i < $n; $i++)
20+
{
21+
$instruction = stream_get_line($stdin, 16 + 1, "\n");
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("a b c d\n");
27+
}
28+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\MicroAssembly;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\MicroAssembly\MicroAssembly;
9+
10+
/**
11+
* Tests for the "Micro assembly" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\MicroAssembly\MicroAssembly
14+
* @group microAssembly
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new MicroAssembly();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "MOV test".
26+
*
27+
* @group microAssembly_MOVTest
28+
*/
29+
public function testCanExecuteMOVTest(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - MOV test.txt',
33+
"1 3 1 -4" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "ADD test".
39+
*
40+
* @group microAssembly_ADDTest
41+
*/
42+
public function testCanExecuteADDTest(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - ADD test.txt',
46+
"4 9 13 5" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "SUB test".
52+
*
53+
* @group microAssembly_SUBTest
54+
*/
55+
public function testCanExecuteSUBTest(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - SUB test.txt',
59+
"0 12 21 12" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "JNE test".
65+
*
66+
* @group microAssembly_JNETest
67+
*/
68+
public function testCanExecuteJNETest(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - JNE test.txt',
72+
"3 0 7 9" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Handling negative values".
78+
*
79+
* @group microAssembly_handlingNegativeValues
80+
*/
81+
public function testCanExecuteHandlingNegativeValues(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - handling negative values.txt',
85+
"-1 0 -3 -10" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Calculating sum of 1..N".
91+
*
92+
* @group microAssembly_calculatingSumOf1N
93+
*/
94+
public function testCanExecuteCalculatingSumOf1N(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - calculating sum of 1_N.txt',
98+
"55 0 0 0" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Nested loops".
104+
*
105+
* @group microAssembly_nestedLoops
106+
*/
107+
public function testCanExecuteNestedLoops(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - nested loops.txt',
111+
"30 0 0 -7" . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Multiplication and jump over instruction".
117+
*
118+
* @group microAssembly_multiplicationAndJumpOverInstruction
119+
*/
120+
public function testCanExecuteMultiplicationAndJumpOverInstruction(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - multiplication and jump over instruction.txt',
124+
"105 0 0 0" . PHP_EOL
125+
);
126+
}
127+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 2 3 -4
2+
2
3+
MOV b 3
4+
MOV c a
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2 3 4 5
2+
3
3+
ADD a b 1
4+
ADD b 2 7
5+
ADD c a b
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
14 2 21 9
2+
3
3+
SUB a a a
4+
SUB d 12 a
5+
SUB b 15 3
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 5 7 9
2+
2
3+
SUB b b 1
4+
JNE 0 b 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0 -2 -3 -4
2+
4
3+
MOV a -1
4+
SUB b c -3
5+
ADD d d -1
6+
JNE 2 d -10
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0 10 0 0
2+
3
3+
ADD a a b
4+
SUB b b 1
5+
JNE 0 b 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1 3 3 7
2+
9
3+
MOV a 10
4+
MOV b 5
5+
MOV c b
6+
SUB c c 1
7+
ADD a a c
8+
JNE 3 c 0
9+
SUB b b 1
10+
JNE 2 b c
11+
SUB d 0 d

0 commit comments

Comments
 (0)