Skip to content

Commit 9a6f9f2

Browse files
Sync high-scores (#918)
1 parent ccb89f0 commit 9a6f9f2

8 files changed

Lines changed: 144 additions & 60 deletions

File tree

bin/auto-sync.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ gigasecond
3030
grade-school
3131
hamming
3232
hello-world
33+
high-scores
3334
house
3435
isbn-verifier
3536
isogram
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction append
2+
3+
For this exercise, you may want to look at [PHP property hooks][property_hooks].
4+
5+
[property_hooks]: https://www.php.net/manual/en/language.oop5.property-hooks.php
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
# Manage a game player's High Score list.
1+
# Instructions
22

3-
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.
3+
Manage a game player's High Score list.
4+
5+
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era.
6+
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

exercises/practice/high-scores/.meta/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
".meta/example.php"
1717
]
1818
},
19-
"blurb": "Manage a player's High Score list"
19+
"blurb": "Manage a player's High Score list.",
20+
"source": "Tribute to the eighties' arcade game Frogger"
2021
}

exercises/practice/high-scores/.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
class HighScores
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[1035eb93-2208-4c22-bab8-fef06769a73c]
13+
description = "List of scores"
14+
15+
[6aa5dbf5-78fa-4375-b22c-ffaa989732d2]
16+
description = "Latest score"
17+
18+
[b661a2e1-aebf-4f50-9139-0fb817dd12c6]
19+
description = "Personal best"
20+
21+
[3d996a97-c81c-4642-9afc-80b80dc14015]
22+
description = "Top 3 scores -> Personal top three from a list of scores"
23+
24+
[1084ecb5-3eb4-46fe-a816-e40331a4e83a]
25+
description = "Top 3 scores -> Personal top highest to lowest"
26+
27+
[e6465b6b-5a11-4936-bfe3-35241c4f4f16]
28+
description = "Top 3 scores -> Personal top when there is a tie"
29+
30+
[f73b02af-c8fd-41c9-91b9-c86eaa86bce2]
31+
description = "Top 3 scores -> Personal top when there are less than 3"
32+
33+
[16608eae-f60f-4a88-800e-aabce5df2865]
34+
description = "Top 3 scores -> Personal top when there is only one"
35+
36+
[2df075f9-fec9-4756-8f40-98c52a11504f]
37+
description = "Top 3 scores -> Latest score after personal top scores"
38+
39+
[809c4058-7eb1-4206-b01e-79238b9b71bc]
40+
description = "Top 3 scores -> Scores after personal top scores"
41+
42+
[ddb0efc0-9a86-4f82-bc30-21ae0bdc6418]
43+
description = "Top 3 scores -> Latest score after personal best"
44+
45+
[6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364]
46+
description = "Top 3 scores -> Scores after personal best"

exercises/practice/high-scores/HighScores.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
class HighScores
2828
{
29+
/**
30+
* You will need to add the methods and properties to store and present the
31+
* desired values yourself. You will want to consider using property hooks:
32+
* https://www.php.net/manual/en/language.oop5.property-hooks.php
33+
*/
2934
public function __construct(array $scores)
3035
{
3136
throw new \BadFunctionCallException("Implement the HighScores class");
Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
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
use PHPUnit\Framework\TestCase;
6+
use PHPUnit\Framework\Attributes\TestDox;
287

298
class HighScoresTest extends TestCase
309
{
@@ -33,69 +12,135 @@ public static function setUpBeforeClass(): void
3312
require_once 'HighScores.php';
3413
}
3514

15+
/**
16+
* uuid: 1035eb93-2208-4c22-bab8-fef06769a73c
17+
*/
18+
#[TestDox('List of scores')]
3619
public function testListOfScores(): void
3720
{
3821
$input = [30, 50, 20, 70];
3922
$this->assertEquals([30, 50, 20, 70], (new HighScores($input))->scores);
4023
}
4124

25+
/**
26+
* uuid: 6aa5dbf5-78fa-4375-b22c-ffaa989732d2
27+
*/
28+
#[TestDox('Latest score')]
4229
public function testLatestScore(): void
4330
{
4431
$input = [100, 0, 90, 30];
4532
$this->assertEquals(30, (new HighScores($input))->latest);
4633
}
4734

35+
/**
36+
* uuid: b661a2e1-aebf-4f50-9139-0fb817dd12c6
37+
*/
38+
#[TestDox('Personal best')]
4839
public function testPersonalBest(): void
4940
{
5041
$input = [40, 100, 70];
5142
$this->assertEquals(100, (new HighScores($input))->personalBest);
5243
}
5344

54-
public function testPersonalTopThreeFromAListOfScores(): void
45+
/**
46+
* uuid: 3d996a97-c81c-4642-9afc-80b80dc14015
47+
*/
48+
#[TestDox('Top 3 scores -> Personal top three from a list of scores')]
49+
public function testTop3ScoresPersonalTopThreeFromAListOfScores(): void
5550
{
5651
$input = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70];
5752
$this->assertEquals([100, 90, 70], (new HighScores($input))->personalTopThree);
5853
}
5954

60-
public function testPersonalTopHighestToLowest(): void
55+
/**
56+
* uuid: 1084ecb5-3eb4-46fe-a816-e40331a4e83a
57+
*/
58+
#[TestDox('Top 3 scores -> Personal top highest to lowest')]
59+
public function testTop3ScoresPersonalTopHighestToLowest(): void
6160
{
6261
$input = [20, 10, 30];
6362
$this->assertEquals([30, 20, 10], (new HighScores($input))->personalTopThree);
6463
}
6564

66-
public function testPersonalTopWhenThereIsATie(): void
65+
/**
66+
* uuid: e6465b6b-5a11-4936-bfe3-35241c4f4f16
67+
*/
68+
#[TestDox('Top 3 scores -> Personal top when there is a tie')]
69+
public function testTop3ScoresPersonalTopWhenThereIsATie(): void
6770
{
6871
$input = [40, 20, 40, 30];
6972
$this->assertEquals([40, 40, 30], (new HighScores($input))->personalTopThree);
7073
}
7174

72-
public function testPersonalTopWhenThereAreLessThan3(): void
75+
/**
76+
* uuid: f73b02af-c8fd-41c9-91b9-c86eaa86bce2
77+
*/
78+
#[TestDox('Top 3 scores -> Personal top when there are less than 3')]
79+
public function testTop3ScoresPersonalTopWhenThereAreLessThan3(): void
7380
{
7481
$input = [30, 70];
7582
$this->assertEquals([70, 30], (new HighScores($input))->personalTopThree);
7683
}
7784

78-
public function testPersonalTopWhenThereIsOnlyOne(): void
85+
/**
86+
* uuid: 16608eae-f60f-4a88-800e-aabce5df2865
87+
*/
88+
#[TestDox('Top 3 scores -> Personal top when there is only one')]
89+
public function testTop3ScoresPersonalTopWhenThereIsOnlyOne(): void
7990
{
8091
$input = [40];
8192
$this->assertEquals([40], (new HighScores($input))->personalTopThree);
8293
}
8394

84-
public function testLatestScoreDoesNotChangeAfterGettingPersonalBest(): void
95+
/**
96+
* uuid: 2df075f9-fec9-4756-8f40-98c52a11504f
97+
*/
98+
#[TestDox('Top 3 scores -> Latest score after personal top scores')]
99+
public function testTop3ScoresLatestScoreAfterPersonalTopScores(): void
100+
{
101+
$input = [70, 50, 20, 30];
102+
$highScore = new HighScores($input);
103+
104+
$this->assertEquals([70, 50, 30], $highScore->personalTopThree);
105+
$this->assertEquals(30, $highScore->latest);
106+
}
107+
108+
/**
109+
* uuid: 809c4058-7eb1-4206-b01e-79238b9b71bc
110+
*/
111+
#[TestDox('Top 3 scores -> Scores after personal top scores')]
112+
public function testTop3ScoresScoresAfterPersonalTopScores(): void
113+
{
114+
$input = [30, 50, 20, 70];
115+
$highScore = new HighScores($input);
116+
117+
$this->assertEquals([70, 50, 30], $highScore->personalTopThree);
118+
$this->assertEquals([30, 50, 20, 70], $highScore->scores);
119+
}
120+
121+
/**
122+
* uuid: ddb0efc0-9a86-4f82-bc30-21ae0bdc6418
123+
*/
124+
#[TestDox('Top 3 scores -> Latest score after personal best')]
125+
public function testTop3ScoresLatestScoreAfterPersonalBest(): void
85126
{
86-
$input = [20, 10, 30, 3, 2, 1];
127+
$input = [20, 70, 15, 25, 30];
87128
$highScore = new HighScores($input);
88129

89-
$this->assertEquals(30, $highScore->personalBest);
90-
$this->assertEquals(1, $highScore->latest);
130+
$this->assertEquals(70, $highScore->personalBest);
131+
$this->assertEquals(30, $highScore->latest);
91132
}
92133

93-
public function testLatestScoreDoesNotChangeAfterGettingPersonalTopThree(): void
134+
/**
135+
* uuid: 6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364
136+
*/
137+
#[TestDox('Top 3 scores -> Scores after personal best')]
138+
public function testTop3ScoresScoresAfterPersonalBest(): void
94139
{
95-
$input = [20, 100, 30, 90, 2, 70];
140+
$input = [20, 70, 15, 25, 30];
96141
$highScore = new HighScores($input);
97142

98-
$this->assertEquals([100, 90, 70], $highScore->personalTopThree);
99-
$this->assertEquals(70, $highScore->latest);
143+
$this->assertEquals(70, $highScore->personalBest);
144+
$this->assertEquals([20, 70, 15, 25, 30], $highScore->scores);
100145
}
101146
}

0 commit comments

Comments
 (0)