From a60d490368353e2d3fe71b40ee473b102e882984 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Sat, 15 Sep 2018 03:43:37 +0100 Subject: [PATCH] begin adding property test for library. Add scripts to Test Centre to populate LoadingTestArea folder with images for testing. Update .gitignore file to ignore .png files in LoadingTestArea. --- .gitignore | 3 ++ TestCentre/LibraryTests.fs | 64 ++++++++++++++++++++++++++++++++++++ TestCentre/Script.fsx | 56 +++++++++++++++++++++++++++++-- TestCentre/TestCentre.fsproj | 4 +++ TestCentre/packages.config | 1 + 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 TestCentre/LibraryTests.fs diff --git a/.gitignore b/.gitignore index 3e759b7..edddaec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +# Project-specific Files +/TestCentre/LoadingTestArea/*.png + # User-specific files *.suo *.user diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs new file mode 100644 index 0000000..22bce43 --- /dev/null +++ b/TestCentre/LibraryTests.fs @@ -0,0 +1,64 @@ +namespace LibraryTests + + module TestingHelpers = + + open System + open System.Drawing + open System.Reflection + open SmoulderingBeachBall.Domain + open SmoulderingBeachBall.Services + + let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" + + let allColours = + let properties = + typeof.GetProperties(BindingFlags.Public ||| BindingFlags.Static) + seq { for prop in properties -> prop} + |> Seq.toArray + + let randomBrush () = + let item = allColours.[Random().Next(allColours.Length)] + item.GetValue(null, null) + + let populateSpec () = + { width = (Random().Next(3000)) + height = (Random().Next(3000)) + colour = (randomBrush ()) :?> Brush + filePath = loadLocation + overlay = None } + + let generateSpecs amount = + [for i in 1 .. amount -> (populateSpec ()) ] + + let populateLoadingTestArea () = + printfn "[INFO.] Populating LoadingTestArea..." + generateSpecs 100 + |> List.map makeImage + |> Async.Parallel + |> Async.RunSynchronously + |> ignore + printfn "[INFO.] Finishing populating Saving Test Area." + + module PropertyTests = + + open FsCheck.Xunit + open DeathSocket + open System.Drawing + open DeathSocket.GridPainter + open TestingHelpers + + [] + let ``Can apply grid to image and save it`` () = + let spec = + { originalPath = "tba" + savePath = "tba" + colour = randomBrush () :?> Brush + penWidth = float32 0.002 + rows = 10 + columns = 10 } + applyGrid spec |> Async.RunSynchronously + + [] + let ``Can populate the LoadingTestArea`` () = + populateLoadingTestArea () + true = true \ No newline at end of file diff --git a/TestCentre/Script.fsx b/TestCentre/Script.fsx index 9274e75..be14646 100644 --- a/TestCentre/Script.fsx +++ b/TestCentre/Script.fsx @@ -1,3 +1,55 @@ -// Testing scripts to go here... +// These DLL's must be built before you can use them in this script. +#r "bin/Debug/System.Drawing.Common.dll" +#r "bin/Debug/SmoulderingBeachBall.dll" -let saveLocation = __SOURCE_DIRECTORY__ + "\\SavingTestArea" \ No newline at end of file +open System +open System.Drawing +open System.Reflection +open SmoulderingBeachBall.Domain +open SmoulderingBeachBall.Services +open System.Threading + +(* Populating LoadingTestArea Folder Scripts +=============================================================================== +The following scripts are to help you populate a test folder of images. +You can then use these images in LibraryTests.fs -- Property Tests. +The tests consists of loading images from LoadingTestArea, transforming them +and saving them in SavingTestArea. *) + +let saveLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" + +let allColours = + let properties = + typeof.GetProperties(BindingFlags.Public ||| BindingFlags.Static) + seq { for prop in properties -> prop} + |> Seq.toArray + +let randomBrush () = + let item = allColours.[Random().Next(allColours.Length)] + item.GetValue(null, null) + +let populateSpec () = + { width = (Random().Next(3000)) + height = (Random().Next(3000)) + colour = (randomBrush ()) :?> Brush + filePath = saveLocation + overlay = None } + +let generateSpecs amount = + [for i in 1 .. amount do + Thread.Sleep 500 + yield (populateSpec ()) ] + +let generateImage spec = + printfn "[INFO.] Creating image [Width: %i] [Height: %i] ..." (spec.width) (spec.height) + makeImage spec + +let populateLoadingTestArea () = + printfn "[INFO.] Populating LoadingTestArea..." + for spec in generateSpecs 100 do + generateImage spec + |> Async.RunSynchronously + printfn "[INFO.] Finishing populating /LoadingTestArea." + +// You should only need this once you have passed the above into F# Interactive. +populateLoadingTestArea () \ No newline at end of file diff --git a/TestCentre/TestCentre.fsproj b/TestCentre/TestCentre.fsproj index ed0c934..2e6f108 100644 --- a/TestCentre/TestCentre.fsproj +++ b/TestCentre/TestCentre.fsproj @@ -54,6 +54,7 @@ + @@ -68,6 +69,9 @@ ..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll + + ..\packages\SmoulderingBeachBall.0.4.0-alpha1\lib\netstandard2.0\SmoulderingBeachBall.dll + diff --git a/TestCentre/packages.config b/TestCentre/packages.config index 6de53e1..398fcee 100644 --- a/TestCentre/packages.config +++ b/TestCentre/packages.config @@ -3,6 +3,7 @@ +