Browse Source

backfill tests for getters/setters

main
Brian Hicks 1 month ago
parent
commit
d7ea77087a
  1. 10
      src/Player.elm
  2. 54
      tests/PlayerTest.elm

10
src/Player.elm

@ -3,7 +3,7 @@ module Player exposing
, PlayerId, id, idSorter
, name
, rating, setRating
, matchesPlayed, setMatchesPlayed, incrementMatchesPlayed
, matchesPlayed, setMatchesPlayedTestOnly, incrementMatchesPlayed
, encode
, decoder
)
@ -18,7 +18,7 @@ module Player exposing
@docs rating, setRating
@docs matchesPlayed, setMatchesPlayed, incrementMatchesPlayed
@docs matchesPlayed, setMatchesPlayedTestOnly, incrementMatchesPlayed
@docs encode, decode
@ -88,7 +88,7 @@ rating (Player player) =
setRating : Int -> Player -> Player
setRating rating_ (Player player) =
Player { player | rating = rating_ }
Player { player | rating = max 0 rating_ }
@ -100,8 +100,8 @@ matchesPlayed (Player player) =
player.matches
setMatchesPlayed : Int -> Player -> Player
setMatchesPlayed matches (Player player) =
setMatchesPlayedTestOnly : Int -> Player -> Player
setMatchesPlayedTestOnly matches (Player player) =
Player { player | matches = matches }

54
tests/PlayerTest.elm

@ -1,5 +1,6 @@
module PlayerTest exposing (..)
import Elo
import Expect
import Fuzz exposing (Fuzzer)
import Json.Decode as Decode
@ -33,13 +34,64 @@ interopTest =
]
nameTest : Test
nameTest =
describe "name"
[ test "you get the same name out as you put in" <|
\_ ->
Player.init "Babaganoush"
|> Player.name
|> Expect.equal "Babaganoush"
]
matchesTest : Test
matchesTest =
describe "matches"
[ test "you start off having played zero matches" <|
\_ ->
Player.init "Pita"
|> Player.matchesPlayed
|> Expect.equal 0
, test "when you play a match, you can see it" <|
\_ ->
Player.init "Pita"
|> Player.incrementMatchesPlayed
|> Player.matchesPlayed
|> Expect.equal 1
]
ratingTest : Test
ratingTest =
describe "rating"
[ test "you start off at the default Elo rating" <|
\_ ->
Player.init "Shish Taouk"
|> Player.rating
|> Expect.equal Elo.initialRating
, fuzz (Fuzz.intRange 0 (Elo.initialRating * 2)) "your rating can be set to whatever" <|
\rating ->
Player.init "Shish Taouk"
|> Player.setRating rating
|> Player.rating
|> Expect.equal rating
, test "your rating cannot go below zero" <|
\_ ->
Player.init "Shish Taouk"
|> Player.setRating -1
|> Player.rating
|> Expect.equal 0
]
playerFuzzer : Fuzzer Player
playerFuzzer =
Fuzz.map3
(\name rating matches ->
Player.init name
|> Player.setRating rating
|> Player.setMatchesPlayed matches
|> Player.setMatchesPlayedTestOnly matches
)
nameFuzzer
(Fuzz.intRange 1000 3000)

Loading…
Cancel
Save