Browse Source

add property tests for functions which add a grid with the SkiaSharp based spec's.

master
Craig Oates 6 years ago
parent
commit
001bb5ddcd
  1. 83
      TestCentre/LibraryTests.fs

83
TestCentre/LibraryTests.fs

@ -21,6 +21,7 @@
open System.Reflection open System.Reflection
open System.IO open System.IO
open DeathSocket.Domain open DeathSocket.Domain
open SkiaSharp
let rand = Random () let rand = Random ()
@ -42,7 +43,18 @@
let randomBrush () = let randomBrush () =
let item = allColours.[rand.Next(allColours.Length)] let item = allColours.[rand.Next(allColours.Length)]
item.GetValue(null, null) item.GetValue (null, null)
let allSKColours =
let properties =
typeof<SKColors>.GetFields
(BindingFlags.Static ||| BindingFlags.Public)
seq {for prop in properties -> prop}
|> Seq.toArray
let randomSKColour () =
let item = allSKColours.[rand.Next(allSKColours.Length)]
item.GetValue (null) :?> SKColor
(* Max. value is arbitrary (change for performance). (* Max. value is arbitrary (change for performance).
Min. value is to stop divide by zero exceptions. Min. value is to stop divide by zero exceptions.
@ -93,6 +105,7 @@
open DeathSocket.GridPainter open DeathSocket.GridPainter
open TestingHelpers open TestingHelpers
open System.IO open System.IO
open SkiaSharp
(* With regards to the "saving images" tests, you should end up with (* With regards to the "saving images" tests, you should end up with
one image left over in the SavingTestArea folder. Comment out the one image left over in the SavingTestArea folder. Comment out the
@ -104,14 +117,13 @@
resetSavingTestArea () resetSavingTestArea ()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
let (spec: BrushSpec) = { originalPath = oPath
{ originalPath = oPath savePath = sPath
savePath = sPath colour = randomBrush () :?> Brush
colour = randomBrush () :?> Brush penWidth = float32 (newPenWidth())
penWidth = float32 (newPenWidth()) rows = 10
rows = 10 columns = 10 }
columns = 10 } |> applyBrushSpecGridAsync
applyBrushSpecGridAsync spec
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true
@ -120,17 +132,16 @@
resetSavingTestArea () resetSavingTestArea ()
let oPath = generateLoadPath () let oPath = generateLoadPath ()
let sPath = generateSavePath oPath let sPath = generateSavePath oPath
let (spec: RGBASpec) = { originalPath = oPath
{ originalPath = oPath savePath = sPath
savePath = sPath alpha = float (newRGBANum ())
alpha = float (newRGBANum ()) red = float (newRGBANum ())
red = float (newRGBANum ()) green = float (newRGBANum ())
green = float (newRGBANum ()) blue = float (newRGBANum ())
blue = float (newRGBANum ()) penWidth = float32 (newPenWidth())
penWidth = float32 (newPenWidth()) rows = 10
rows = 10 columns = 10 }
columns = 10 } |> applyRGBAGridAsync
applyRGBAGridAsync spec
|> Async.RunSynchronously |> Async.RunSynchronously
(File.Exists sPath) = true (File.Exists sPath) = true
@ -165,6 +176,38 @@
let result = determineVerticalLines (newNum()) (newNum()) (newNum()) let result = determineVerticalLines (newNum()) (newNum()) (newNum())
result.Length > 0 result.Length > 0
[<Property>]
let ``Can apply grid to image and save it using SkiaSpec`` () =
resetSavingTestArea()
let oPath = generateLoadPath ()
let sPath = generateSavePath oPath
{ originalPath = oPath
savePath= sPath
skColour = randomSKColour ()
penWidth = float32 (newPenWidth())
rows = newNum ()
columns = newNum () }
|> applySkiaGridAsync
|> Async.RunSynchronously
(File.Exists sPath) = true
[<Property>]
let ``Can apply grid to image and save it using SkiaRGBSpec`` () =
resetSavingTestArea()
let oPath = generateLoadPath ()
let sPath = generateSavePath oPath
{ originalPath = oPath
savePath= sPath
red = float32 (newRGBANum ())
green = float32 (newRGBANum ())
blue = float32 (newRGBANum ())
penWidth = float32 (newPenWidth())
rows = newNum ()
columns = newNum () }
|> applySkiaRGBGridAsync
|> Async.RunSynchronously
(File.Exists sPath) = true
[<Property>] [<Property>]
let ``Can return a collection of SKPoints which represent a grids horizontal lines`` () = let ``Can return a collection of SKPoints which represent a grids horizontal lines`` () =
let result = determineSKHorizontalLines (newNum()) (newNum()) (newNum()) let result = determineSKHorizontalLines (newNum()) (newNum()) (newNum())

Loading…
Cancel
Save