-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b667f92
commit e5224a2
Showing
3 changed files
with
96 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
scores_list <- function(scores) { | ||
scores | ||
} | ||
|
||
latest <- function(scores) { | ||
tail(scores, n = 1) | ||
} | ||
|
||
personal_best <- function(scores) { | ||
max(scores) | ||
} | ||
|
||
personal_top_three <- function(scores) { | ||
sort(scores, decreasing = TRUE)[1:(min(length(scores), 3))] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
scores_list <- function(scores) { | ||
|
||
} | ||
|
||
latest <- function(scores) { | ||
|
||
} | ||
|
||
personal_best <- function(scores) { | ||
|
||
} | ||
|
||
personal_top_three <- function(scores) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,78 @@ | ||
source("./high-scores.R") | ||
library(testthat) | ||
|
||
test_that("list of scores", { | ||
scores <- c(30, 50, 20, 70) | ||
expected <- c(30, 50, 20, 70) | ||
expect_equal(scores_list(scores), expected) | ||
}) | ||
|
||
def test_list_of_scores(self): | ||
scores = [30, 50, 20, 70] | ||
expected = [30, 50, 20, 70] | ||
self.assertEqual(HighScores(scores).scores, expected) | ||
test_that("latest score", { | ||
scores <- c(100, 0, 90, 30) | ||
expected <- 30 | ||
expect_equal(latest(scores), expected) | ||
}) | ||
|
||
def test_latest_score(self): | ||
scores = [100, 0, 90, 30] | ||
expected = 30 | ||
self.assertEqual(HighScores(scores).latest(), expected) | ||
test_that("personal best", { | ||
scores <- c(40, 100, 70) | ||
expected <- 100 | ||
expect_equal(personal_best(scores), expected) | ||
}) | ||
|
||
def test_personal_best(self): | ||
scores = [40, 100, 70] | ||
expected = 100 | ||
self.assertEqual(HighScores(scores).personal_best(), expected) | ||
test_that("personal top three from a list of scores", { | ||
scores <- c(10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70) | ||
expected <- c(100, 90, 70) | ||
expect_equal(personal_top_three(scores), expected) | ||
}) | ||
|
||
def test_personal_top_three_from_a_list_of_scores(self): | ||
scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70] | ||
expected = [100, 90, 70] | ||
self.assertEqual(HighScores(scores).personal_top_three(), expected) | ||
test_that("personal top highest to lowest", { | ||
scores <- c(20, 10, 30) | ||
expected <- c(30, 20, 10) | ||
expect_equal(personal_top_three(scores), expected) | ||
}) | ||
|
||
def test_personal_top_highest_to_lowest(self): | ||
scores = [20, 10, 30] | ||
expected = [30, 20, 10] | ||
self.assertEqual(HighScores(scores).personal_top_three(), expected) | ||
test_that("personal top when there is a tie", { | ||
scores <- c(40, 20, 40, 30) | ||
expected <- c(40, 40, 30) | ||
expect_equal(personal_top_three(scores), expected) | ||
}) | ||
|
||
def test_personal_top_when_there_is_a_tie(self): | ||
scores = [40, 20, 40, 30] | ||
expected = [40, 40, 30] | ||
self.assertEqual(HighScores(scores).personal_top_three(), expected) | ||
test_that("personal top when there are less than 3", { | ||
scores <- c(30, 70) | ||
expected <- c(70, 30) | ||
expect_equal(personal_top_three(scores), expected) | ||
}) | ||
|
||
def test_personal_top_when_there_are_less_than_3(self): | ||
scores = [30, 70] | ||
expected = [70, 30] | ||
self.assertEqual(HighScores(scores).personal_top_three(), expected) | ||
test_that("personal top when there is only one", { | ||
scores <- c(40) | ||
expected <- c(40) | ||
expect_equal(personal_top_three(scores), expected) | ||
}) | ||
|
||
def test_personal_top_when_there_is_only_one(self): | ||
scores = [40] | ||
expected = [40] | ||
self.assertEqual(HighScores(scores).personal_top_three(), expected) | ||
test_that("latest score after personal top scores", { | ||
scores <- c(70, 50, 20, 30) | ||
expected <- 30 | ||
personal_top_three(scores) | ||
expect_equal(latest(scores), expected) | ||
}) | ||
|
||
def test_latest_score_after_personal_top_scores(self): | ||
scores = [70, 50, 20, 30] | ||
expected = 30 | ||
highscores = HighScores(scores) | ||
highscores.personal_top_three() | ||
self.assertEqual(highscores.latest(), expected) | ||
test_that("scores after personal top scores", { | ||
scores <- c(30, 50, 20, 70) | ||
expected <- c(30, 50, 20, 70) | ||
personal_top_three(scores) | ||
expect_equal(scores_list(scores), expected) | ||
}) | ||
|
||
def test_scores_after_personal_top_scores(self): | ||
scores = [30, 50, 20, 70] | ||
expected = [30, 50, 20, 70] | ||
highscores = HighScores(scores) | ||
highscores.personal_top_three() | ||
self.assertEqual(highscores.scores, expected) | ||
test_that("latest score after personal best", { | ||
scores <- c(20, 70, 15, 25, 30) | ||
expected <- 30 | ||
personal_best(scores) | ||
expect_equal(latest(scores), expected) | ||
}) | ||
|
||
def test_latest_score_after_personal_best(self): | ||
scores = [20, 70, 15, 25, 30] | ||
expected = 30 | ||
highscores = HighScores(scores) | ||
highscores.personal_best() | ||
self.assertEqual(highscores.latest(), expected) | ||
|
||
def test_scores_after_personal_best(self): | ||
scores = [20, 70, 15, 25, 30] | ||
expected = [20, 70, 15, 25, 30] | ||
highscores = HighScores(scores) | ||
highscores.personal_best() | ||
self.assertEqual(highscores.scores, expected) | ||
test_that("scores after personal best", { | ||
scores <- c(20, 70, 15, 25, 30) | ||
expected <- c(20, 70, 15, 25, 30) | ||
personal_best(scores) | ||
expect_equal(scores_list(scores), expected) | ||
}) |