diff --git a/SmoulderingBeachBallCLI/Validation.fs b/SmoulderingBeachBallCLI/Validation.fs index 774e384..47460e6 100644 --- a/SmoulderingBeachBallCLI/Validation.fs +++ b/SmoulderingBeachBallCLI/Validation.fs @@ -62,14 +62,14 @@ let private buildOverlaySpec oColour (oType: string) = let oSpec = - { colour = parseColour oColour; + { colour = parseColour oColour overlayType = parseOverlay oType } oSpec let private buildMainSpec iWidth iHeight mainColour path oSpec = let spec = - { width = iWidth; - height = iHeight; + { width = iWidth + height = iHeight colour = parseColour mainColour filePath = parsePath path overlay = oSpec } diff --git a/TestCentre/ConsoleTests.fs b/TestCentre/ConsoleTests.fs index 5bd7e96..95b44a6 100644 --- a/TestCentre/ConsoleTests.fs +++ b/TestCentre/ConsoleTests.fs @@ -2,17 +2,38 @@ module PropertyTests = - open FsCheck open FsCheck.Xunit open Validation open System open SmoulderingBeachBall.Domain.DomainTypes open System.Drawing + (* The functions without the "Property" attribute are not for testing. + They generate the test data used in the (property) tests. + Please be careful when removing any of these types of functions. + They are the ones not marked with the "Property" attribute. + Also, the intention is to keep these functions seperate from the tests. + Until it is not practical to keep them in this module, the default place to keep them is above the tests. With that said, it is just a guide. + Use your best judgement when adding new "helper" functions. + This applies to the UnitTests module, thanks. *) + + let randomInt () = Random().Next() + + let randomColour () = + colourList + |> Map.toList + |> List.item (Random().Next(colourList.Count)) + + let overlays = [|"none"; "n"; "full"; "f"|] + + let noOverlay () = overlays.[Random().Next(0, 1)] + + let fullOverlay () = overlays.[Random().Next(2, 3)] + [] let ``buildDefaultSpec creates intended type`` () = - let width = Random().Next() - let height = Random().Next() + let width = randomInt () + let height = randomInt () let oSpec = { colour = Brushes.Black overlayType = Full } @@ -25,8 +46,42 @@ } let spec = buildDefaultSpec width height defaultSpec = spec - - Check.Quick (``buildDefaultSpec creates intended type`` ()) + + [] + let ``buildSpec creates intended type with no overlay`` () = + let width = randomInt () + let height = randomInt () + let colour = randomColour () + let overlay = noOverlay () + let expectedSpec = + { width = width + height = height + colour = snd colour + filePath = getDesktopPath + overlay = option.None } + let spec = + buildSpec width height (fst colour) (fst colour) overlay getDesktopPath + expectedSpec = spec + + [] + let ``buildSpec creates intended type with full overlay`` () = + let width = randomInt () + let height = randomInt () + let mainColour = randomColour () + let overlayColour = randomColour () + let overlay = fullOverlay () + let oSpec = + { colour = snd overlayColour + overlayType = Full } + let expectedSpec = + { width = width + height = height + colour = snd mainColour + filePath = getDesktopPath + overlay = Some oSpec } + let spec = + buildSpec width height (fst mainColour) (fst overlayColour) overlay getDesktopPath + expectedSpec = spec module UnitTests =