I know I can probably use MSTest (I'm under Linux without an IDE so maybe not?) or another unit testing library, but for a small project I decided to write my own unit tests without resorting to a framework (for fun and for learning).
Right now, I have only one type of assert and one test but I would like a code review to improve my code now to make sure I am on the right track.
module Tests // modules under test open HeightMap open MidpointDisplacement // assert functions let assertAreEqual expected actual = printf "... " if expected <> actual then printfn "%s" ("Test failed, expected " + expected.ToString() + ", actual " + actual.ToString()) else printfn "Test passed" // tests let testNewHeightMapReturnZeroInitializedHm () = let hm = newHeightMap 5 let result = hm.Map |> Array.sum assertAreEqual 0.0 result // tests included in run let testsToRun = [ ("test newHeightMap will return a 0 initialized height map", testNewHeightMapReturnZeroInitializedHm) ] // test runner let runSingleTest test = let testName, testFunction = test printf "%s" testName testFunction() let runTests = testsToRun |> List.map runSingleTest |> ignore printfn "%s" "Ran all tests."
One thing that bugs me is that I there is some redundancy by specifying the test function and then including it in a list inside a tuple.