diff --git a/SmoulderingBeachBall/ScratchPad.fsx b/SmoulderingBeachBall/ScratchPad.fsx index 544dcb6..6d870b3 100644 --- a/SmoulderingBeachBall/ScratchPad.fsx +++ b/SmoulderingBeachBall/ScratchPad.fsx @@ -34,7 +34,7 @@ let imageSpec = { width = 500; height = 500; colour = Brushes.Yellow; - filePath = "C:/users/craig/desktop/test.png"; + filePath = "C:/users/craig/desktop/"; // Change this to flip between border/full overlay or None. overlay = Some fullOverlay } diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 3ace00c..6c8feca 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -2,6 +2,7 @@ module PropertyTests = + open Xunit open FsCheck.Xunit open System open System.Drawing @@ -10,8 +11,6 @@ open SmoulderingBeachBall.Services open System.IO - let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/" - (* '3000' is an arbitary value. It is used to keep the testing times sane. This function is used to randomly generate image sizes but you do not need to use it. The project can handle larger numbers than '3000' but processing takes longer. @@ -25,6 +24,8 @@ *) let randomInt () = Random().Next(3000) + let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/" + let allColours = let properties = typeof.GetProperties(BindingFlags.Public ||| BindingFlags.Static) @@ -38,14 +39,24 @@ item.GetValue(null, null) let fileSaved width height = - let path = saveLocation + width + "x" + height + ".png" - File.Exists path + saveLocation + width + "x" + height + ".png" + |> File.Exists + + // To manually clear out the SavingTestArea folder, use this function in script.fsx. + let resetSavingTestArea () = + let files = Directory.GetFileSystemEntries(saveLocation) + match files.Length with + | 0 -> () + | _ -> + files + |> Array.iter (fun f -> File.Delete(f)) [] let ``can create an image with no overlay`` () = - // See note accompanying 'randomInt' function for constraints information. + resetSavingTestArea () let spec = - { width = randomInt () + { // See note accompanying 'randomInt' function for constraints information. + width = randomInt () height = randomInt () colour = randomColour () :?> Brush filePath = saveLocation diff --git a/TestCentre/Script.fsx b/TestCentre/Script.fsx index f7a3229..526b141 100644 --- a/TestCentre/Script.fsx +++ b/TestCentre/Script.fsx @@ -1,37 +1,15 @@ // Learn more about F# at http://fsharp.org // See the 'F# Tutorial' project for more help. +open System.IO -#load "ConsoleTests.fs" -#load "LibraryTests.fs" +let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/" -open ConsoleTests -open LibraryTests -open System.Drawing -open System.Reflection -open System +let resetSavingTestArea () = + let files = Directory.GetFileSystemEntries(saveLocation) + match files.Length with + | 0 -> () + | _ -> + files + |> Array.iter (fun f -> File.Delete(f)) -// Define your library scripting code here - -let allBrushColours = - let properties = - Color().GetType().GetProperties() - let names = - seq { for prop in properties do - yield prop.Name } - |> Seq.toList - names - -let allBrushes = - let properties = - typeof.GetProperties(BindingFlags.Public|||BindingFlags.Static) - let colours = - seq { for prop in properties -> prop} - |> Seq.toArray - colours - -let randomColour () = - let item = allBrushes.[Random().Next (allBrushes.Length)] - item.GetValue(null, null) - -printfn "%A" allBrushes -printfn "%A" (randomColour ()) \ No newline at end of file +resetSavingTestArea () \ No newline at end of file