Skip to content
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
3 changes: 3 additions & 0 deletions exercises/practice/flower-field/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ description = "cross"

[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8]
description = "large garden"

[6e4ac13a-3e43-4728-a2e3-3551d4b1a996]
description = "multiple adjacent flowers"
15 changes: 15 additions & 0 deletions exercises/practice/flower-field/FlowerFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,19 @@ public function testLargeFlowerfield(): void

$this->assertSame($expected, $actual);
}

/**
* uuid 6e4ac13a-3e43-4728-a2e3-3551d4b1a996
*/
#[TestDox('Multiple adjacent flowers')]
public function testMultipleAdjacentFlowers(): void
{
$garden = [" ** "];
$expected = ["1**1"];

$subject = new FlowerField($garden);
$actual = $subject->annotate();

$this->assertSame($expected, $actual);
}
}
6 changes: 6 additions & 0 deletions exercises/practice/isbn-verifier/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ description = "invalid character in isbn is not treated as zero"
[28025280-2c39-4092-9719-f3234b89c627]
description = "X is only valid as a check digit"

[8005b57f-f194-44ee-88d2-a77ac4142591]
description = "only one check digit is allowed"

[fdb14c99-4cf8-43c5-b06d-eb1638eff343]
description = "X is not substituted by the value 10"

[f6294e61-7e79-46b3-977b-f48789a4945b]
description = "valid isbn without separating dashes"

Expand Down
104 changes: 78 additions & 26 deletions exercises/practice/isbn-verifier/IsbnVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,170 +3,222 @@
declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;

class IsbnVerifierTest extends TestCase
{
private IsbnVerifier $isbnVerifier;

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

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

/**
* uuid: 0caa3eac-d2e3-4c29-8df8-b188bc8c9292
*/
#[TestDox('Valid ISBN')]
public function testValidIsbn(): void
{
$this->assertTrue($this->isbnVerifier->isValid('3-598-21508-8'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(true, $isbnVerifier->isValid('3-598-21508-8'));
}

/**
* uuid: 19f76b53-7c24-45f8-87b8-4604d0ccd248
*/
#[TestDox('Invalid ISBN check digit')]
public function testInvalidIsbnCheckDigit(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-21508-9'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-21508-9'));
}

/**
* uuid: 4164bfee-fb0a-4a1c-9f70-64c6a1903dcd
*/
#[TestDox('Valid ISBN with a check digit of 10')]
public function testValidIsbnWithACheckDigitOf10(): void
{
$this->assertTrue($this->isbnVerifier->isValid('3-598-21507-X'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(true, $isbnVerifier->isValid('3-598-21507-X'));
}

/**
* uuid: 3ed50db1-8982-4423-a993-93174a20825c
*/
#[TestDox('Check digit is a character other than X')]
public function testCheckDigitIsACharacterOtherThanX(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-21507-A'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-21507-A'));
}

/**
* uuid: 9416f4a5-fe01-4b61-a07b-eb75892ef562
*/
#[TestDox('Invalid check digit in ISBN is not treated as zero')]
public function testInvalidCheckDigitInIsbnIsNotTreatedAsZero(): void
{
$this->assertFalse($this->isbnVerifier->isValid('4-598-21507-B'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('4-598-21507-B'));
}

/**
* uuid: c19ba0c4-014f-4dc3-a63f-ff9aefc9b5ec
*/
#[TestDox('Invalid character in ISBN is not treated as zero')]
public function testInvalidCharacterInIsbnIsNotTreatedAsZero(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-P1581-X'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-P1581-X'));
}

/**
* uuid: 28025280-2c39-4092-9719-f3234b89c627
*/
#[TestDox('X is only valid as a check digit')]
public function testXIsOnlyValidAsACheckDigit(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-2X507-9'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-2X507-9'));
}

/**
* uuid: 8005b57f-f194-44ee-88d2-a77ac4142591
*/
#[TestDox('Only one check digit is allowed')]
public function testOnlyOneCheckDigitIsAllowed(): void
{
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-21508-96'));
}

/**
* uuid: fdb14c99-4cf8-43c5-b06d-eb1638eff343
*/
#[TestDox('X is not substituted by the value 10')]
public function testXIsNotSubstitutedByTheValue10(): void
{
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-2X507-5'));
}

/**
* uuid: f6294e61-7e79-46b3-977b-f48789a4945b
*/
#[TestDox('Valid ISBN without separating dashes')]
public function testValidIsbnWithoutSeparatingDashes(): void
{
$this->assertTrue($this->isbnVerifier->isValid('3598215088'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(true, $isbnVerifier->isValid('3598215088'));
}

/**
* uuid: 185ab99b-3a1b-45f3-aeec-b80d80b07f0b
*/
#[TestDox('ISBN without separating dashes and X as check digit')]
public function testIsbnWithoutSeparatingDashesAndXAsCheckDigit(): void
{
$this->assertTrue($this->isbnVerifier->isValid('359821507X'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(true, $isbnVerifier->isValid('359821507X'));
}

/**
* uuid: 7725a837-ec8e-4528-a92a-d981dd8cf3e2
*/
#[TestDox('ISBN without check digit and dashes')]
public function testIsbnWithoutCheckDigitAndDashes(): void
{
$this->assertFalse($this->isbnVerifier->isValid('359821507'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('359821507'));
}

/**
* uuid: 47e4dfba-9c20-46ed-9958-4d3190630bdf
*/
#[TestDox('Too long ISBN and no dashes')]
public function testTooLongIsbnAndNoDashes(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3598215078X'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3598215078X'));
}

/**
* uuid: 737f4e91-cbba-4175-95bf-ae630b41fb60
*/
#[TestDox('Too short ISBN')]
public function testTooShortIsbn(): void
{
$this->assertFalse($this->isbnVerifier->isValid('00'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('00'));
}

/**
* uuid: 5458a128-a9b6-4ff8-8afb-674e74567cef
*/
#[TestDox('ISBN without check digit')]
public function testIsbnWithoutCheckDigit(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-21507'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-21507'));
}

/**
* uuid: 70b6ad83-d0a2-4ca7-a4d5-a9ab731800f7
*/
#[TestDox('Check digit of X should not be used for 0')]
public function testCheckDigitOfXShouldNotBeUsedForZero(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3-598-21515-X'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3-598-21515-X'));
}

/**
* uuid: 94610459-55ab-4c35-9b93-ff6ea1a8e562
*/
#[TestDox('Empty ISBN')]
public function testEmptyIsbn(): void
{
$this->assertFalse($this->isbnVerifier->isValid(''));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid(''));
}

/**
* uuid: 7bff28d4-d770-48cc-80d6-b20b3a0fb46c
*/
#[TestDox('Input is 9 characters')]
public function testInputIs9Characters(): void
{
$this->assertFalse($this->isbnVerifier->isValid('134456729'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('134456729'));
}

/**
* uuid: ed6e8d1b-382c-4081-8326-8b772c581fec
*/
#[TestDox('Invalid characters are not ignored after checking length')]
public function testInvalidCharactersAreNotIgnoredAfterCheckingLength(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3132P34035'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3132P34035'));
}

/**
* uuid: daad3e58-ce00-4395-8a8e-e3eded1cdc86
*/
#[TestDox('Invalid characters are not ignored before checking length')]
public function testCatchInvalidCharactersInOnOtherwiseValidIsbn(): void
{
$this->assertFalse($this->isbnVerifier->isValid('3598P215088'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('3598P215088'));
}

/**
* uuid: fb5e48d8-7c03-4bfb-a088-b101df16fdc3
*/
#[TestDox('Input is too long but contains a valid ISBN')]
public function testInputIsTooLongButContainsAValidIsbn(): void
{
$this->assertFalse($this->isbnVerifier->isValid('98245726788'));
$isbnVerifier = new IsbnVerifier();
$this->assertSame(false, $isbnVerifier->isValid('98245726788'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ You can also find Killer Sudokus in varying difficulty in numerous newspapers, a

## Credit

The screenshots above have been generated using [F-Puzzles.com](https://www.f-puzzles.com/), a Puzzle Setting Tool by Eric Fox.
The screenshots above have been generated using F-Puzzles.com, a Puzzle Setting Tool by Eric Fox.

[sudoku-rules]: https://masteringsudoku.com/sudoku-rules-beginners/
[killer-guide]: https://masteringsudoku.com/killer-sudoku/
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/line-up/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Yaʻqūb expects to use numbers from 1 up to 999.

Rules:

- Numbers ending in 1 (except for 11) → `"st"`
- Numbers ending in 2 (except for 12) → `"nd"`
- Numbers ending in 3 (except for 13) → `"rd"`
- Numbers ending in 1 (unless ending in 11) → `"st"`
- Numbers ending in 2 (unless ending in 12) → `"nd"`
- Numbers ending in 3 (unless ending in 13) → `"rd"`
- All other numbers → `"th"`

Examples:
Expand Down
36 changes: 18 additions & 18 deletions exercises/practice/ocr-numbers/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Instructions

Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is
represented, or whether it is garbled.
Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.

# Step One
## Step One

To begin with, convert a simple binary font to a string containing 0 or 1.

Expand Down Expand Up @@ -31,19 +30,19 @@ If the input is the correct size, but not recognizable, your program should retu

If the input is the incorrect size, your program should return an error.

# Step Two
## Step Two

Update your program to recognize multi-character binary strings, replacing garbled numbers with ?

# Step Three
## Step Three

Update your program to recognize all numbers 0 through 9, both individually and as part of a larger string.

```text
_
_
_|
|_
|_

```

Is converted to "2"
Expand All @@ -57,23 +56,24 @@ Is converted to "2"

Is converted to "1234567890"

# Step Four
## Step Four

Update your program to handle multiple numbers, one per line. When converting several lines, join the lines with commas.
Update your program to handle multiple numbers, one per line.
When converting several lines, join the lines with commas.

```text
_ _
_ _
| _| _|
||_ _|
_ _
|_||_ |_

_ _
|_||_ |_
| _||_|
_ _ _

_ _ _
||_||_|
||_| _|

```

Is converted to "123,456,789"
Is converted to "123,456,789".
6 changes: 6 additions & 0 deletions exercises/practice/ocr-numbers/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Introduction

Your best friend Marta recently landed their dream job working with a local history museum's collections.
Knowing of your interests in programming, they confide in you about an issue at work for an upcoming exhibit on computing history.
A local university's math department had donated several boxes of historical printouts, but given the poor condition of the documents, the decision has been made to digitize the text.
However, the university's old printer had some quirks in how text was represented, and your friend could use your help to extract the data successfully.
Loading