From 001bb5ddcdbc72bf2f90eae2a854c67179b8f875 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Tue, 4 Dec 2018 02:33:40 +0000 Subject: [PATCH] add property tests for functions which add a grid with the SkiaSharp based spec's. --- TestCentre/LibraryTests.fs | 83 +++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 20 deletions(-) diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index a8bc0c7..6d7e6dc 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -21,6 +21,7 @@ open System.Reflection open System.IO open DeathSocket.Domain + open SkiaSharp let rand = Random () @@ -42,7 +43,18 @@ let randomBrush () = let item = allColours.[rand.Next(allColours.Length)] - item.GetValue(null, null) + item.GetValue (null, null) + + let allSKColours = + let properties = + typeof.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). Min. value is to stop divide by zero exceptions. @@ -93,6 +105,7 @@ open DeathSocket.GridPainter open TestingHelpers open System.IO + open SkiaSharp (* With regards to the "saving images" tests, you should end up with one image left over in the SavingTestArea folder. Comment out the @@ -104,14 +117,13 @@ resetSavingTestArea () let oPath = generateLoadPath () let sPath = generateSavePath oPath - let (spec: BrushSpec) = - { originalPath = oPath - savePath = sPath - colour = randomBrush () :?> Brush - penWidth = float32 (newPenWidth()) - rows = 10 - columns = 10 } - applyBrushSpecGridAsync spec + { originalPath = oPath + savePath = sPath + colour = randomBrush () :?> Brush + penWidth = float32 (newPenWidth()) + rows = 10 + columns = 10 } + |> applyBrushSpecGridAsync |> Async.RunSynchronously (File.Exists sPath) = true @@ -120,17 +132,16 @@ resetSavingTestArea () let oPath = generateLoadPath () let sPath = generateSavePath oPath - let (spec: RGBASpec) = - { originalPath = oPath - savePath = sPath - alpha = float (newRGBANum ()) - red = float (newRGBANum ()) - green = float (newRGBANum ()) - blue = float (newRGBANum ()) - penWidth = float32 (newPenWidth()) - rows = 10 - columns = 10 } - applyRGBAGridAsync spec + { originalPath = oPath + savePath = sPath + alpha = float (newRGBANum ()) + red = float (newRGBANum ()) + green = float (newRGBANum ()) + blue = float (newRGBANum ()) + penWidth = float32 (newPenWidth()) + rows = 10 + columns = 10 } + |> applyRGBAGridAsync |> Async.RunSynchronously (File.Exists sPath) = true @@ -165,6 +176,38 @@ let result = determineVerticalLines (newNum()) (newNum()) (newNum()) result.Length > 0 + [] + 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 + + [] + 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 + [] let ``Can return a collection of SKPoints which represent a grids horizontal lines`` () = let result = determineSKHorizontalLines (newNum()) (newNum()) (newNum())