Богопротівний FSharpx
Середа, 12 Листопад 2014 03:06![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Юніт-тести від модуля FSharpx (github)
module GayBar =
open Club
let checkGender (p: Person) =
match p.Gender with
| Male -> Success p
| _ -> Failure "Men only"
let costToEnter p =
[checkAge; checkClothes; checkSobriety; checkGender]
|> Validation.mapM (fun check -> check p |> Choice.mapSecond NonEmptyList.singleton)
|> Choice.map (function x::_ -> decimal x.Age + 1.5m | [] -> failwith "costToEnter")
[<Test>]
let part3() =
GayBar.costToEnter { Person.Gender = Male; Age = 59; Clothes = set ["Jeans"]; Sobriety = Paralytic }
|> shouldEqual (Failure (NonEmptyList.create "Too old!" ["Smarten up!"; "Sober up!"]))
GayBar.costToEnter { Person.Gender = Male; Age = 25; Clothes = set ["Tie"]; Sobriety = Sober } |> shouldEqual (Success 26.5m)