From e6890045b08642020c8f901e4fc905378213dd16 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Fri, 7 Sep 2018 22:19:26 +0100 Subject: [PATCH] add property tests for library project. Add rough code for generating a collection of brushes in script.fsx in Test Centre. Make minor changes to Assembly Info and fsproj (Test Centre). --- SmoulderingBeachBall/InternalServices.fs | 2 - TestCentre/AssemblyInfo.fs | 8 ++-- TestCentre/LibraryTests.fs | 54 ++++++++++++++++++++++++ TestCentre/Script.fsx | 28 ++++++++++++ TestCentre/TestCentre.fsproj | 1 + 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 TestCentre/LibraryTests.fs diff --git a/SmoulderingBeachBall/InternalServices.fs b/SmoulderingBeachBall/InternalServices.fs index 260e608..7402b30 100644 --- a/SmoulderingBeachBall/InternalServices.fs +++ b/SmoulderingBeachBall/InternalServices.fs @@ -44,7 +44,6 @@ let penPath = createBorderPath pen.Width spec graphics.DrawLines (pen, penPath) - let drawFullOverlay (graphics: Graphics) (pen: Pen) spec = drawBorder graphics pen spec printfn "[INFO.] Adding full overlay to image..." @@ -70,7 +69,6 @@ sb.Append ".png" |> ignore (sb.ToString ()) - let drawImage spec = let bitmap = new Bitmap (spec.width, spec.height) let graphics = Graphics.FromImage (bitmap) diff --git a/TestCentre/AssemblyInfo.fs b/TestCentre/AssemblyInfo.fs index d8dda7b..bfea358 100644 --- a/TestCentre/AssemblyInfo.fs +++ b/TestCentre/AssemblyInfo.fs @@ -7,8 +7,8 @@ open System.Runtime.InteropServices // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[] -[] +[] +[] [] [] [] @@ -34,8 +34,8 @@ open System.Runtime.InteropServices // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [] -[] -[] +[] +[] do () \ No newline at end of file diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs new file mode 100644 index 0000000..3ace00c --- /dev/null +++ b/TestCentre/LibraryTests.fs @@ -0,0 +1,54 @@ +namespace LibraryTests + + module PropertyTests = + + open FsCheck.Xunit + open System + open System.Drawing + open SmoulderingBeachBall.Domain.DomainTypes + open System.Reflection + 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. + If you decide to change it, please keep an eye on the saving time. + When a image is too big, the project cannot write it to disc fast enough -- + sometimes it is because of IO constraints. + This means the tests checking for this fail/error will think the image does not exist. + To resolved this, add a Thread.Sleep call to the affected tests. + Just be aware, the length of sleep-time depends on the size of the image. + Also, problems tends to arise around the 15,000 mark. + *) + let randomInt () = Random().Next(3000) + + let allColours = + let properties = + typeof.GetProperties(BindingFlags.Public ||| BindingFlags.Static) + let colours = + seq { for prop in properties -> prop} + |> Seq.toArray + colours + + let randomColour () = + let item = allColours.[Random().Next(allColours.Length)] + item.GetValue(null, null) + + let fileSaved width height = + let path = saveLocation + width + "x" + height + ".png" + File.Exists path + + [] + let ``can create an image with no overlay`` () = + // See note accompanying 'randomInt' function for constraints information. + let spec = + { width = randomInt () + height = randomInt () + colour = randomColour () :?> Brush + filePath = saveLocation + overlay = None } + makeImage spec |> Async.RunSynchronously + fileSaved (spec.width.ToString()) (spec.height.ToString()) = true diff --git a/TestCentre/Script.fsx b/TestCentre/Script.fsx index c3b5e6c..f7a3229 100644 --- a/TestCentre/Script.fsx +++ b/TestCentre/Script.fsx @@ -2,8 +2,36 @@ // See the 'F# Tutorial' project for more help. #load "ConsoleTests.fs" +#load "LibraryTests.fs" open ConsoleTests +open LibraryTests +open System.Drawing +open System.Reflection +open System // 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 diff --git a/TestCentre/TestCentre.fsproj b/TestCentre/TestCentre.fsproj index b72f52d..01d14c5 100644 --- a/TestCentre/TestCentre.fsproj +++ b/TestCentre/TestCentre.fsproj @@ -47,6 +47,7 @@ +