Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions bin/auto-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ sublist
two-bucket
two-fer
wordy
word-count
yacht
zebra-puzzle
3 changes: 2 additions & 1 deletion exercises/practice/word-count/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"arueckauer",
"kunicmarko20",
"kytrinyx",
"petemcfarlane"
"petemcfarlane",
"hazeolation"
],
"files": {
"solution": [
Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/word-count/.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 wordCount($phrase)
Expand Down
8 changes: 8 additions & 0 deletions exercises/practice/word-count/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ description = "normalize case"

[4185a902-bdb0-4074-864c-f416e42a0f19]
description = "with apostrophes"
include = false

[4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3]
description = "with apostrophes"
reimplements = "4185a902-bdb0-4074-864c-f416e42a0f19"

[be72af2b-8afe-4337-b151-b297202e4a7b]
description = "with quotations"
Expand All @@ -40,3 +45,6 @@ description = "multiple spaces not detected as a word"

[50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360]
description = "alternating word separators not detected as a word"

[6d00f1db-901c-4bec-9829-d20eb3044557]
description = "quotation for word with apostrophe"
139 changes: 107 additions & 32 deletions exercises/practice/word-count/WordCountTest.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);

use PHPUnit\Framework\TestCase;
Expand All @@ -33,59 +11,156 @@ public static function setUpBeforeClass(): void
require_once 'WordCount.php';
}

/**
* UUID 61559d5f-2cad-48fb-af53-d3973a9ee9ef
*/
#[TestDox('count one word')]
public function testCountOneWord(): void
{
$this->assertEquals(['word' => 1], wordCount('word'));
}

/**
* UUID 5abd53a3-1aed-43a4-a15a-29f88c09cbbd
*/
#[TestDox('count one of each word')]
public function testCountOneOfEachWord(): void
{
$this->assertEquals(['one' => 1, 'of' => 1, 'each' => 1], wordCount('one of each'));
}

/**
* UUID 2a3091e5-952e-4099-9fac-8f85d9655c0e
*/
#[TestDox('multiple occurrences of a word')]
public function testMultipleOccurrencesOfAWord(): void
{
$this->assertEquals(['one' => 1, 'fish' => 4, 'two' => 1, 'red' => 1, 'blue' => 1], wordCount('one fish two fish red fish blue fish'));
}

/**
* UUID e81877ae-d4da-4af4-931c-d923cd621ca6
*/
#[TestDox('handles cramped lists')]
public function testHandlesCrampedLists(): void
{
$this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount('one,two,three'));
}

/**
* UUID 7349f682-9707-47c0-a9af-be56e1e7ff30
*/
#[TestDox('handles expanded lists')]
public function testHandlesExpandedLists(): void
{
$this->assertEquals(
['one' => 1, 'fish' => 4, 'two' => 1, 'red' => 1, 'blue' => 1],
wordCount('one fish two fish red fish blue fish')
['one' => 1, 'two' => 1, 'three' => 1],
wordCount('one, two, three')
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
);
}

/**
* UUID a514a0f2-8589-4279-8892-887f76a14c82
*/
#[TestDox('ignore punctuation')]
public function testIgnorePunctuation(): void
{
$this->assertEquals(
['car' => 1, 'carpet' => 1, 'as' => 1, 'java' => 1, 'javascript' => 1],
wordCount('car : carpet as java : javascript!!&@$%^&')
);
$this->assertEquals(['car' => 1, 'carpet' => 1, 'as' => 1, 'java' => 1, 'javascript' => 1], wordCount('car : carpet as java : javascript!!&@$%^&'));
}

/**
* UUID d2e5cee6-d2ec-497b-bdc9-3ebe092ce55e
*/
#[TestDox('include numbers')]
public function testIncludeNumbers(): void
{
$this->assertEquals(['1' => 1, '2' => 1, 'testing' => 2], wordCount('testing, 1, 2 testing'));
}

/**
* UUID dac6bc6a-21ae-4954-945d-d7f716392dbf
*/
#[TestDox('normalize case')]
public function testNormalizeCase(): void
{
$this->assertEquals(['go' => 3, 'stop' => 2], wordCount('go Go GO Stop stop'));
}

public function testCountsMultiline(): void
/**
* UUID 4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3
*/
#[TestDox('with apostrophes')]
public function testWithApostrophes(): void
{
$this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\nworld"));
$this->assertEquals(['first' => 1, "don't" => 1, 'count' => 1], wordCount("first: don't count"));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

public function testCountsTabs(): void
/**
* UUID be72af2b-8afe-4337-b151-b297202e4a7b
*/
#[TestDox('with quotations')]
public function testWithQuotations(): void
{
$this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\tworld"));
$this->assertEquals(['hello' => 1, "world" => 1], wordCount("hello \"world\""));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

/**
* UUID 8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6
*/
#[TestDox('starts from the beginning')]
public function testStartsFromTheBeginning(): void
{
$this->assertEquals(['goody' => 1, 'good' => 1, 'oody' => 1], wordCount('goody good oody'));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

/**
* UUID c5f4ef26-f3f7-4725-b314-855c04fb4c13
*/
#[TestDox('counts multiple spaces as one')]
public function testCountsMultipleSpacesAsOne(): void
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
{
$this->assertEquals(['hello' => 1, 'world' => 1], wordCount('hello world'));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

/**
* UUID 50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360
*/
#[TestDox('alternating word separators are not detected as words')]
public function testAlternatingWordSeparatorsNotDetectedAsWord(): void
{
$this->assertEquals(['one' => 1, 'two' => 1, 'three' => 1], wordCount("one,\ntwo,\nthree"));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

/**
* UUID 6d00f1db-901c-4bec-9829-d20eb3044557
*/
#[TestDox('quotation for word with apostrophe')]
public function testQuotationForWordWithApostrophe(): void
{
$this->assertEquals(['well' => 1, 'happening' => 1, "what's" => 1], wordCount("well, \"what's\" happening"));
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}

/**
* UUID not found
*/
public function testDoesNotCountLeadingOrTrailingWhitespace(): void
{
$this->assertEquals(['introductory' => 1, 'course' => 1], wordCount("\t\tIntroductory Course "));
}

/**
* UUID not found
*/
public function testCountsMultiline(): void
{
$this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\nworld"));
}

/**
* UUID not found
*/
public function testCountsTabs(): void
{
$this->assertEquals(['hello' => 1, 'world' => 1], wordCount("hello\tworld"));
}
Comment thread
Hazeolation marked this conversation as resolved.
Outdated
}