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

[New Exercise]: High Scores #237

Merged
merged 4 commits into from
Aug 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "high-scores",
"name": "High Scores",
"uuid": "c21d45bc-2217-40cc-86ee-24e6938cfeca",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "matrix",
"name": "Matrix",
Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/high-scores/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Instructions

Manage a game player's High Score list.

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.
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.
37 changes: 37 additions & 0 deletions exercises/practice/high-scores/.meta/HighScores.example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<#
.SYNOPSIS
Manage a game player's High Score list.

.DESCRIPTION
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.
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

.EXAMPLE
$roster = [HighScores]::new(@(30, 50, 40, 90, 80))
$roster.GetTopThree()
return : @(90, 80, 50)
#>
Class HighScores {
[int[]]$Scores

HighScores([int[]]$list){
$this.Scores = $list
}

[int[]] GetScores() {
return $this.Scores
}

[int] GetLatest() {
return $this.Scores[-1]
}

[int] GetPersonalBest() {
return ($this.Scores | Measure-Object -Maximum).Maximum
}

[int[]] GetTopThree() {
$SortedScores = $this.Scores | Sort-Object -Descending
return $SortedScores.Count -lt 3 ? $SortedScores : $SortedScores[0..2]
}
}
16 changes: 16 additions & 0 deletions exercises/practice/high-scores/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"authors": ["glaxxie"],
"files": {
"solution": [
"HighScores.ps1"
],
"test": [
"HighScores.tests.ps1"
],
"example": [
".meta/HighScores.example.ps1"
]
},
"blurb": "Manage a player's High Score list.",
"source": "Tribute to the eighties' arcade game Frogger"
}
46 changes: 46 additions & 0 deletions exercises/practice/high-scores/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[1035eb93-2208-4c22-bab8-fef06769a73c]
description = "List of scores"

[6aa5dbf5-78fa-4375-b22c-ffaa989732d2]
description = "Latest score"

[b661a2e1-aebf-4f50-9139-0fb817dd12c6]
description = "Personal best"

[3d996a97-c81c-4642-9afc-80b80dc14015]
description = "Top 3 scores -> Personal top three from a list of scores"

[1084ecb5-3eb4-46fe-a816-e40331a4e83a]
description = "Top 3 scores -> Personal top highest to lowest"

[e6465b6b-5a11-4936-bfe3-35241c4f4f16]
description = "Top 3 scores -> Personal top when there is a tie"

[f73b02af-c8fd-41c9-91b9-c86eaa86bce2]
description = "Top 3 scores -> Personal top when there are less than 3"

[16608eae-f60f-4a88-800e-aabce5df2865]
description = "Top 3 scores -> Personal top when there is only one"

[2df075f9-fec9-4756-8f40-98c52a11504f]
description = "Top 3 scores -> Latest score after personal top scores"

[809c4058-7eb1-4206-b01e-79238b9b71bc]
description = "Top 3 scores -> Scores after personal top scores"

[ddb0efc0-9a86-4f82-bc30-21ae0bdc6418]
description = "Top 3 scores -> Latest score after personal best"

[6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364]
description = "Top 3 scores -> Scores after personal best"
18 changes: 18 additions & 0 deletions exercises/practice/high-scores/HighScores.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<#
.SYNOPSIS
Manage a game player's High Score list.

.DESCRIPTION
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.
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

.EXAMPLE
$roster = [HighScores]::new(@(30, 50, 40, 90, 80))
$roster.GetTopThree()
return : @(90, 80, 50)
#>
Class HighScores {
HighScores([int[]]$list){
Throw "Please implement this class."
}
}
105 changes: 105 additions & 0 deletions exercises/practice/high-scores/HighScores.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
BeforeAll {
. "./HighScores.ps1"
}

Describe "High Scores Test cases" {
It "List of scores" {
$scores = [HighScores]::New(@(30, 50, 90, 40, 20, 70))
$got = $scores.GetScores()
$want = @(30, 50, 90, 40, 20, 70)

$got | Should -BeExactly $want
}

It "Latest score" {
$scores = [HighScores]::New(@(20, 60, 80))
$got = $scores.GetLatest()
$want = 80

$got | Should -BeExactly $want
}

It "should return the personal best score" {
$scores = [HighScores]::New(@(50, 40, 10, 20, 90, 100))
$got = $scores.GetPersonalBest()
$want = 100

$got | Should -BeExactly $want
}

It "Personal top three from a list of scores" {
$scores = [HighScores]::New(@(10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70))
$got = $scores.GetTopThree()
$want = @(100, 90, 70)

$got | Should -BeExactly $want
}

It "Personal top highest to lowest" {
$scores = [HighScores]::New(@(20, 10, 30))
$got = $scores.GetTopThree()
$want = @(30, 20, 10)

$got | Should -BeExactly $want
}

It "Personal top when there is a tie" {
$scores = [HighScores]::New(@(20, 30, 40, 30))
$got = $scores.GetTopThree()
$want = @(40, 30, 30)

$got | Should -BeExactly $want
}

It "Personal top when there are less than 3" {
$scores = [HighScores]::New(@(50, 60))
$got = $scores.GetTopThree()
$want = @(60, 50)

$got | Should -BeExactly $want
}

It "Personal top when there is only one" {
$scores = [HighScores]::New(@(80))
$got = $scores.GetTopThree()
$want = @(80)

$got | Should -BeExactly $want
}

It "Latest score after personal top scores" {
$scores = [HighScores]::New(@(70, 50, 20, 30))
$scores.GetTopThree()
$got = $scores.GetLatest()
$want = @(30)

$got | Should -BeExactly $want
}

It "Scores after personal top scores" {
$scores = [HighScores]::New(@(70, 50, 20, 30))
$scores.GetTopThree()
$got = $scores.GetScores()
$want = @(70, 50, 20, 30)

$got | Should -BeExactly $want
}

It "Latest score after personal best" {
$scores = [HighScores]::New(@(40, 60, 20, 90, 70))
$scores.GetPersonalBest()
$got = $scores.GetLatest()
$want = 70

$got | Should -BeExactly $want
}

It "Scores after personal best" {
$scores = [HighScores]::New(@(50, 60, 100, 90, 70))
$scores.GetPersonalBest()
$got = $scores.GetScores()
$want = @(50, 60, 100, 90, 70)

$got | Should -BeExactly $want
}
}