Browse Source

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.
master
Craig Oates 6 years ago
parent
commit
a60d490368
  1. 3
      .gitignore
  2. 64
      TestCentre/LibraryTests.fs
  3. 56
      TestCentre/Script.fsx
  4. 4
      TestCentre/TestCentre.fsproj
  5. 1
      TestCentre/packages.config

3
.gitignore vendored

@ -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

64
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<Brushes>.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
[<Property>]
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
[<Property>]
let ``Can populate the LoadingTestArea`` () =
populateLoadingTestArea ()
true = true

56
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"
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<Brushes>.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 ()

4
TestCentre/TestCentre.fsproj

@ -54,6 +54,7 @@
</None>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="ConsoleTests.fs" />
<Compile Include="LibraryTests.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>
@ -68,6 +69,9 @@
<HintPath>..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="SmoulderingBeachBall">
<HintPath>..\packages\SmoulderingBeachBall.0.4.0-alpha1\lib\netstandard2.0\SmoulderingBeachBall.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />

1
TestCentre/packages.config

@ -3,6 +3,7 @@
<package id="FsCheck" version="2.11.0" targetFramework="net471" />
<package id="FsCheck.Xunit" version="2.11.0" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.2" targetFramework="net471" />
<package id="SmoulderingBeachBall" version="0.4.0-alpha1" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
<package id="xunit" version="2.4.0" targetFramework="net471" />

Loading…
Cancel
Save