Browse Source

add property tests and helper functions to console tests.

Add a comment about the setup of the tests in console tests.
master
Craig Oates 6 years ago
parent
commit
466a833dfb
  1. 6
      SmoulderingBeachBallCLI/Validation.fs
  2. 65
      TestCentre/ConsoleTests.fs

6
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 }

65
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)]
[<Property>]
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`` ())
[<Property>]
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
[<Property>]
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 =

Loading…
Cancel
Save