Skip to content

Commit e93178d

Browse files
authored
Sync diamond (#832)
[no important files changed]
1 parent abf3d49 commit e93178d

File tree

4 files changed

+34
-59
lines changed

4 files changed

+34
-59
lines changed

exercises/practice/diamond/.docs/instructions.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# Instructions
22

3-
The diamond kata takes as its input a letter, and outputs it in a diamond
4-
shape. Given a letter, it prints a diamond starting with 'A', with the
5-
supplied letter at the widest point.
3+
The diamond kata takes as its input a letter, and outputs it in a diamond shape.
4+
Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point.
65

76
## Requirements
87

9-
* The first row contains one 'A'.
10-
* The last row contains one 'A'.
11-
* All rows, except the first and last, have exactly two identical letters.
12-
* All rows have as many trailing spaces as leading spaces. (This might be 0).
13-
* The diamond is horizontally symmetric.
14-
* The diamond is vertically symmetric.
15-
* The diamond has a square shape (width equals height).
16-
* The letters form a diamond shape.
17-
* The top half has the letters in ascending order.
18-
* The bottom half has the letters in descending order.
19-
* The four corners (containing the spaces) are triangles.
8+
- The first row contains one 'A'.
9+
- The last row contains one 'A'.
10+
- All rows, except the first and last, have exactly two identical letters.
11+
- All rows have as many trailing spaces as leading spaces. (This might be 0).
12+
- The diamond is horizontally symmetric.
13+
- The diamond is vertically symmetric.
14+
- The diamond has a square shape (width equals height).
15+
- The letters form a diamond shape.
16+
- The top half has the letters in ascending order.
17+
- The bottom half has the letters in descending order.
18+
- The four corners (containing the spaces) are triangles.
2019

2120
## Examples
2221

exercises/practice/diamond/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
},
2020
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",
2121
"source": "Seb Rose",
22-
"source_url": "https://claysnow.co.uk/recycling-tests-in-tdd/"
22+
"source_url": "https://web.archive.org/web/20220807163751/http://claysnow.co.uk/recycling-tests-in-tdd/"
2323
}

exercises/practice/diamond/.meta/example.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
function diamond($limit)

exercises/practice/diamond/DiamondTest.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
class DiamondTest extends PHPUnit\Framework\TestCase
@@ -31,11 +9,19 @@ public static function setUpBeforeClass(): void
319
require_once 'Diamond.php';
3210
}
3311

12+
/**
13+
* uuid: 202fb4cc-6a38-4883-9193-a29d5cb92076
14+
* @testdox Degenerate case with a single 'A' row
15+
*/
3416
public function testDegenerateCaseWithASingleARow(): void
3517
{
3618
$this->assertEquals(["A"], diamond("A"));
3719
}
3820

21+
/**
22+
* uuid: bd6a6d78-9302-42e9-8f60-ac1461e9abae
23+
* @testdox Degenerate case with no row containing 3 distinct groups of spaces
24+
*/
3925
public function testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces(): void
4026
{
4127
$this->assertEquals(
@@ -48,6 +34,10 @@ public function testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces():
4834
);
4935
}
5036

37+
/**
38+
* uuid: af8efb49-14ed-447f-8944-4cc59ce3fd76
39+
* @testdox Smallest non-degenerate case with odd diamond side length
40+
*/
5141
public function testSmallestNonDegenerateCaseWithOddDiamondSideLength(): void
5242
{
5343
$this->assertEquals(
@@ -62,6 +52,10 @@ public function testSmallestNonDegenerateCaseWithOddDiamondSideLength(): void
6252
);
6353
}
6454

55+
/**
56+
* uuid: e0c19a95-9888-4d05-86a0-fa81b9e70d1d
57+
* @testdox Smallest non-degenerate case with even diamond side length
58+
*/
6559
public function testSmallestNonDegenerateCaseWithEvenDiamondSideLength(): void
6660
{
6761
$this->assertEquals(
@@ -78,6 +72,10 @@ public function testSmallestNonDegenerateCaseWithEvenDiamondSideLength(): void
7872
);
7973
}
8074

75+
/**
76+
* uuid: 82ea9aa9-4c0e-442a-b07e-40204e925944
77+
* @testdox Largest possible diamond
78+
*/
8179
public function testLargestPossibleDiamond(): void
8280
{
8381
$this->assertEquals(

0 commit comments

Comments
 (0)