Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync diamond #832

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
27 changes: 13 additions & 14 deletions exercises/practice/diamond/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Instructions

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

## Requirements

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

## Examples

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/diamond/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
},
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",
"source": "Seb Rose",
"source_url": "https://claysnow.co.uk/recycling-tests-in-tdd/"
"source_url": "https://web.archive.org/web/20220807163751/http://claysnow.co.uk/recycling-tests-in-tdd/"
}
22 changes: 0 additions & 22 deletions exercises/practice/diamond/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function diamond($limit)
Expand Down
42 changes: 20 additions & 22 deletions exercises/practice/diamond/DiamondTest.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

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

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

/**
* uuid: bd6a6d78-9302-42e9-8f60-ac1461e9abae
* @testdox Degenerate case with no row containing 3 distinct groups of spaces
*/
public function testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces(): void
{
$this->assertEquals(
Expand All @@ -48,6 +34,10 @@ public function testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces():
);
}

/**
* uuid: af8efb49-14ed-447f-8944-4cc59ce3fd76
* @testdox Smallest non-degenerate case with odd diamond side length
*/
public function testSmallestNonDegenerateCaseWithOddDiamondSideLength(): void
{
$this->assertEquals(
Expand All @@ -62,6 +52,10 @@ public function testSmallestNonDegenerateCaseWithOddDiamondSideLength(): void
);
}

/**
* uuid: e0c19a95-9888-4d05-86a0-fa81b9e70d1d
* @testdox Smallest non-degenerate case with even diamond side length
*/
public function testSmallestNonDegenerateCaseWithEvenDiamondSideLength(): void
{
$this->assertEquals(
Expand All @@ -78,6 +72,10 @@ public function testSmallestNonDegenerateCaseWithEvenDiamondSideLength(): void
);
}

/**
* uuid: 82ea9aa9-4c0e-442a-b07e-40204e925944
* @testdox Largest possible diamond
*/
public function testLargestPossibleDiamond(): void
{
$this->assertEquals(
Expand Down