Browse Source

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).
master
Craig Oates 6 years ago
parent
commit
e6890045b0
  1. 2
      SmoulderingBeachBall/InternalServices.fs
  2. 8
      TestCentre/AssemblyInfo.fs
  3. 54
      TestCentre/LibraryTests.fs
  4. 28
      TestCentre/Script.fsx
  5. 1
      TestCentre/TestCentre.fsproj

2
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)

8
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.
[<assembly: AssemblyTitle("TestCentre")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyTitle("Test Centre")>]
[<assembly: AssemblyDescription("A testing library for Smouldering Beach Ball solution.")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("TestCentre")>]
@ -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:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
[<assembly: AssemblyVersion("0.3.0.0")>]
[<assembly: AssemblyFileVersion("0.3.0.0")>]
do
()

54
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<Brushes>.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
[<Property>]
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

28
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<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 ())

1
TestCentre/TestCentre.fsproj

@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="ConsoleTests.fs" />
<Compile Include="LibraryTests.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>

Loading…
Cancel
Save