Browse Source

add logic to clean TestSaveAea in tests and script.

master
Craig Oates 6 years ago
parent
commit
29e8f46cb2
  1. 2
      SmoulderingBeachBall/ScratchPad.fsx
  2. 23
      TestCentre/LibraryTests.fs
  3. 42
      TestCentre/Script.fsx

2
SmoulderingBeachBall/ScratchPad.fsx

@ -34,7 +34,7 @@ let imageSpec =
{ width = 500; { width = 500;
height = 500; height = 500;
colour = Brushes.Yellow; 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. // Change this to flip between border/full overlay or None.
overlay = Some fullOverlay } overlay = Some fullOverlay }

23
TestCentre/LibraryTests.fs

@ -2,6 +2,7 @@
module PropertyTests = module PropertyTests =
open Xunit
open FsCheck.Xunit open FsCheck.Xunit
open System open System
open System.Drawing open System.Drawing
@ -10,8 +11,6 @@
open SmoulderingBeachBall.Services open SmoulderingBeachBall.Services
open System.IO open System.IO
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
(* '3000' is an arbitary value. It is used to keep the testing times sane. (* '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. 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. The project can handle larger numbers than '3000' but processing takes longer.
@ -25,6 +24,8 @@
*) *)
let randomInt () = Random().Next(3000) let randomInt () = Random().Next(3000)
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
let allColours = let allColours =
let properties = let properties =
typeof<Brushes>.GetProperties(BindingFlags.Public ||| BindingFlags.Static) typeof<Brushes>.GetProperties(BindingFlags.Public ||| BindingFlags.Static)
@ -38,14 +39,24 @@
item.GetValue(null, null) item.GetValue(null, null)
let fileSaved width height = let fileSaved width height =
let path = saveLocation + width + "x" + height + ".png" saveLocation + width + "x" + height + ".png"
File.Exists path |> 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))
[<Property>] [<Property>]
let ``can create an image with no overlay`` () = let ``can create an image with no overlay`` () =
// See note accompanying 'randomInt' function for constraints information. resetSavingTestArea ()
let spec = let spec =
{ width = randomInt () { // See note accompanying 'randomInt' function for constraints information.
width = randomInt ()
height = randomInt () height = randomInt ()
colour = randomColour () :?> Brush colour = randomColour () :?> Brush
filePath = saveLocation filePath = saveLocation

42
TestCentre/Script.fsx

@ -1,37 +1,15 @@
// Learn more about F# at http://fsharp.org // Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help. // See the 'F# Tutorial' project for more help.
open System.IO
#load "ConsoleTests.fs" let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
#load "LibraryTests.fs"
open ConsoleTests let resetSavingTestArea () =
open LibraryTests let files = Directory.GetFileSystemEntries(saveLocation)
open System.Drawing match files.Length with
open System.Reflection | 0 -> ()
open System | _ ->
files
|> Array.iter (fun f -> File.Delete(f))
// Define your library scripting code here resetSavingTestArea ()
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<Brushes>.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 ())
Loading…
Cancel
Save