Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/robot-name/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"masters3d",
"petemcfarlane",
"schorsch3000",
"hazeolation"
"hazeolation",
"resu-xuniL"
],
"files": {
"solution": [
Expand Down
32 changes: 15 additions & 17 deletions exercises/practice/robot-name/RobotNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,38 @@ public static function setUpBeforeClass(): void
require_once 'RobotName.php';
}

/** @var Robot $robot */
protected $robot = null;

public function setUp(): void
{
$this->robot = new Robot();
}

public function testHasName(): void
{
$this->assertMatchesRegularExpression('/^[a-z]{2}\d{3}$/i', $this->robot->getName());
$robot = new Robot();
$this->assertMatchesRegularExpression('/^[a-z]{2}\d{3}$/i', $robot->getName());
}

public function testNameSticks(): void
{
$old = $this->robot->getName();
$robot = new Robot();
$old = $robot->getName();

$this->assertSame($this->robot->getName(), $old);
$this->assertSame($robot->getName(), $old);
}

public function testDifferentRobotsHaveDifferentNames(): void
{
$robot = new Robot();
$other_bot = new Robot();

$this->assertNotSame($other_bot->getName(), $this->robot->getName());
$this->assertNotSame($other_bot->getName(), $robot->getName());

unset($other_bot);
}

public function testResetName(): void
{
$name1 = $this->robot->getName();
$robot = new Robot();
$name1 = $robot->getName();

$this->robot->reset();
$robot->reset();

$name2 = $this->robot->getName();
$name2 = $robot->getName();

$this->assertNotSame($name1, $name2);

Expand All @@ -55,19 +51,21 @@ public function testResetName(): void

public function testNamesArentRecycled(): void
{
$robot = new Robot();
$names = [];

for ($i = 0; $i < 10000; $i++) {
$name = $this->robot->getName();
$name = $robot->getName();
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after Reset.', $name));
$names[$name] = true;
$this->robot->reset();
$robot->reset();
}
}

// This test is optional.
public function testNameUniquenessManyRobots(): void
{
$robot = new Robot();
$names = [];

for ($i = 0; $i < 10000; $i++) {
Expand Down
3 changes: 3 additions & 0 deletions exercises/practice/secret-handshake/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"tomasnorre"
],
"contributors": [
"resu-xuniL"
],
"files": {
"solution": [
"SecretHandshake.php"
Expand Down
40 changes: 22 additions & 18 deletions exercises/practice/secret-handshake/SecretHandshakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@

class SecretHandshakeTest extends TestCase
{
private SecretHandshake $secretHandshake;

public static function setUpBeforeClass(): void
{
require_once 'SecretHandshake.php';
}

public function setUp(): void
{
$this->secretHandshake = new SecretHandshake();
}

/**
* uuid: b8496fbd-6778-468c-8054-648d03c4bb23
*/
#[TestDox('Wink for 1')]
public function testWinkForOne(): void
{
$this->assertEquals(['wink'], $this->secretHandshake->commands(1));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['wink'], $secretHandshake->commands(1));
}

/**
Expand All @@ -34,7 +28,8 @@ public function testWinkForOne(): void
#[TestDox('Double blink for 10')]
public function testDoubleBlinkForTen(): void
{
$this->assertEquals(['double blink'], $this->secretHandshake->commands(0b0_0010));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['double blink'], $secretHandshake->commands(0b0_0010));
}

/**
Expand All @@ -43,7 +38,8 @@ public function testDoubleBlinkForTen(): void
#[TestDox('Close your eyes for 100')]
public function testCloseYourEyesForHundred(): void
{
$this->assertEquals(['close your eyes'], $this->secretHandshake->commands(0b100));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['close your eyes'], $secretHandshake->commands(0b100));
}

/**
Expand All @@ -52,7 +48,8 @@ public function testCloseYourEyesForHundred(): void
#[TestDox('Jump for 1000')]
public function testJumpForThousand(): void
{
$this->assertEquals(['jump'], $this->secretHandshake->commands(8));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['jump'], $secretHandshake->commands(8));
}

/**
Expand All @@ -61,7 +58,8 @@ public function testJumpForThousand(): void
#[TestDox('Combine two actions')]
public function testCombineTwoActions(): void
{
$this->assertEquals(['wink', 'double blink'], $this->secretHandshake->commands(3));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['wink', 'double blink'], $secretHandshake->commands(3));
}

/**
Expand All @@ -70,7 +68,8 @@ public function testCombineTwoActions(): void
#[TestDox('Reverse two actions')]
public function testReverseTwoActions(): void
{
$this->assertEquals(['double blink', 'wink'], $this->secretHandshake->commands(0b10011));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['double blink', 'wink'], $secretHandshake->commands(0b10011));
}

/**
Expand All @@ -79,7 +78,8 @@ public function testReverseTwoActions(): void
#[TestDox('Reversing one action gives the same action')]
public function testReversingOneActionGivesTheSameAction(): void
{
$this->assertEquals(['jump'], $this->secretHandshake->commands(24));
$secretHandshake = new SecretHandshake();
$this->assertEquals(['jump'], $secretHandshake->commands(24));
}

/**
Expand All @@ -88,7 +88,8 @@ public function testReversingOneActionGivesTheSameAction(): void
#[TestDox('Reversing no actions still gives no actions')]
public function testReversingNoActionsStillGivesNoActions(): void
{
$this->assertEquals([], $this->secretHandshake->commands(16));
$secretHandshake = new SecretHandshake();
$this->assertEquals([], $secretHandshake->commands(16));
}

/**
Expand All @@ -97,9 +98,10 @@ public function testReversingNoActionsStillGivesNoActions(): void
#[TestDox('All possible actions')]
public function testAllPossibleActions(): void
{
$secretHandshake = new SecretHandshake();
$this->assertEquals(
['wink', 'double blink', 'close your eyes', 'jump'],
$this->secretHandshake->commands(15)
$secretHandshake->commands(15)
);
}

Expand All @@ -109,9 +111,10 @@ public function testAllPossibleActions(): void
#[TestDox('Reverse all possible actions')]
public function testReverseAllPossibleActions(): void
{
$secretHandshake = new SecretHandshake();
$this->assertEquals(
['jump', 'close your eyes', 'double blink', 'wink'],
$this->secretHandshake->commands(31)
$secretHandshake->commands(31)
);
}

Expand All @@ -121,6 +124,7 @@ public function testReverseAllPossibleActions(): void
#[TestDox('Do nothing for zero')]
public function testDoNothingForZero(): void
{
$this->assertEquals([], $this->secretHandshake->commands(0b0));
$secretHandshake = new SecretHandshake();
$this->assertEquals([], $secretHandshake->commands(0b0));
}
}
3 changes: 3 additions & 0 deletions exercises/practice/spiral-matrix/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"tomasnorre"
],
"contributors": [
"resu-xuniL"
],
"files": {
"solution": [
"SpiralMatrix.php"
Expand Down
25 changes: 12 additions & 13 deletions exercises/practice/spiral-matrix/SpiralMatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@

class SpiralMatrixTest extends TestCase
{
private SpiralMatrix $spiralMatrix;

public static function setUpBeforeClass(): void
{
require_once 'SpiralMatrix.php';
}

public function setUp(): void
{
$this->spiralMatrix = new SpiralMatrix();
}

/**
* uuid: 8f584201-b446-4bc9-b132-811c8edd9040
*/
#[TestDox('Empty spiral')]
public function testEmptySpiral(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [];
$actual = $this->spiralMatrix->draw(0);
$actual = $spiralMatrix->draw(0);
$this->assertEquals($expected, $actual);
}

Expand All @@ -36,8 +30,9 @@ public function testEmptySpiral(): void
#[TestDox('Trivial spiral')]
public function testTrivialSpiral(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [[1]];
$actual = $this->spiralMatrix->draw(1);
$actual = $spiralMatrix->draw(1);
$this->assertEquals($expected, $actual);
}

Expand All @@ -47,11 +42,12 @@ public function testTrivialSpiral(): void
#[TestDox('Spiral of size 2')]
public function testSpiralOfSize2(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [
[1, 2],
[4, 3],
];
$actual = $this->spiralMatrix->draw(2);
$actual = $spiralMatrix->draw(2);
$this->assertEquals($expected, $actual);
}

Expand All @@ -61,12 +57,13 @@ public function testSpiralOfSize2(): void
#[TestDox('Spiral of size 3')]
public function testSpiralOfSize3(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [
[1, 2, 3],
[8, 9, 4],
[7, 6, 5],
];
$actual = $this->spiralMatrix->draw(3);
$actual = $spiralMatrix->draw(3);
$this->assertEquals($expected, $actual);
}

Expand All @@ -76,13 +73,14 @@ public function testSpiralOfSize3(): void
#[TestDox('Spiral of size 4')]
public function testSpiralOfSize4(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [
[1, 2, 3, 4],
[12, 13, 14, 5],
[11, 16, 15, 6],
[10, 9, 8, 7],
];
$actual = $this->spiralMatrix->draw(4);
$actual = $spiralMatrix->draw(4);
$this->assertEquals($expected, $actual);
}

Expand All @@ -92,14 +90,15 @@ public function testSpiralOfSize4(): void
#[TestDox('Spiral of size 5')]
public function testSpiralOfSize5(): void
{
$spiralMatrix = new SpiralMatrix();
$expected = [
[1, 2, 3, 4, 5],
[16, 17, 18, 19, 6],
[15, 24, 25, 20, 7],
[14, 23, 22, 21, 8],
[13, 12, 11, 10, 9],
];
$actual = $this->spiralMatrix->draw(5);
$actual = $spiralMatrix->draw(5);
$this->assertEquals($expected, $actual);
}
}
Loading
Loading