Last week I wrote a post on transforming the playing logic from C# to F#, and, I admit it, I testing neither. In my defense: I was in a hurry 🙂
So, I added a few tests now, and what do you know? First test, first bug found! In a previous post I talked about on transforming an option type to an enum, and what I did not know is that you have to make a change to matches. I did not know before as I did not run my tests, so I did not realize it ceased working! What I had was:
let cardtoPoint(c:Card): int = match c with | Card (s,v) -> match v with | A -> 4 | K -> 3 | Q -> 2 | J -> 1 | _ -> 0
Which did work (by which I mean typecheck), however but all options matched to A somehow, so nothing worked anymore. I am still a bit clueless of why this is, but that is the way it is.
To be fair, VS does gives you a warning:
But of course I was making the changes in a different place (namely: at the type Rank), so I did not notice. I actually had to change this into:
let cardtoPoint(c:Card): int = match c with | Card (s,v) -> match v with | Rank.A -> 4 | Rank.K -> 3 | Rank.Q -> 2 | Rank.J -> 1 | _ -> 0
I am not entirely sure why this did type check and not gave some sort of mismatch since v does not match with A….?