Death Socket consists of three projects. They are a .Net Standard 2.0 library, a console program and a Test Centre. The purpose of this repository is to provide a way for people to add grids to images.
https://www.craigoates.net/Software/project/13
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.7 KiB
161 lines
5.7 KiB
namespace ConsoleTests |
|
|
|
(* Initial Setup -- Populating the Test Folders. |
|
=========================================================================== |
|
If you have just cloned this repository or have not run any of the tests |
|
before, please head over to script.fs (in Test Centre) and populate the |
|
LoadingTestArea and SavingTestArea folders. More information will be |
|
provided there about what the scripts do. It is worth pointing out here the |
|
.gitignore file ignores any .png files in them. This is why you must |
|
populate them before running any tests. *) |
|
|
|
module TestingHelpers = |
|
|
|
(* When you are writing tests, please keep all helper functions in this |
|
module. If this module grows to a point where it hinders the actual |
|
testing modules, consider moving it then. If you do decide to move them |
|
out, pay attention to LibraryTests.fs and its helper functions. *) |
|
|
|
open System |
|
open DeathSocketCLI.Validation |
|
|
|
// Directory Path |
|
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea" |
|
let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" |
|
|
|
// File Path |
|
let loadPath = loadLocation + "/RequiredInfo/LoadTest.png" |
|
let savePath = saveLocation + "/SaveTest.png" |
|
|
|
(* Brushes converted to string []. |
|
CLI deals with strings before brushes. *) |
|
let testingColourArray = |
|
colourList |
|
|> Map.toSeq |
|
|> Seq.map fst |
|
|> Seq.toArray |
|
|
|
let randomColourString () = |
|
testingColourArray.[Random().Next(testingColourArray.Length - 1)] |
|
|
|
let randomBrush () = |
|
colourList |
|
|> Map.toSeq |
|
|> Seq.map snd |
|
|> Seq.toArray |
|
|> Array.item (Random().Next(colourList.Count)) |
|
|
|
module PropertyTests = |
|
|
|
open System |
|
open FsCheck.Xunit |
|
open DeathSocketCLI.Validation |
|
open System.Drawing |
|
open TestingHelpers |
|
open DeathSocket.Domain |
|
|
|
[<Property>] |
|
let ``Pen width is set greater than 0`` () = |
|
(setPenWidth (Random().Next()) (Random().Next())) > 0.0f |
|
|
|
[<Property>] |
|
let ``Can build the intended default BrushSpec`` () = |
|
let defaultSpec = |
|
{ originalPath = loadPath |
|
savePath = savePath |
|
colour = Brushes.White |
|
penWidth = setPenWidth 1000 1000 |
|
rows = 10 |
|
columns = 10 } |
|
let spec = buildDefaultSpec loadPath savePath |
|
defaultSpec = spec |
|
|
|
[<Property>] |
|
let ``Can build a BrushSpec as intended`` () = |
|
let colourString = randomColourString () |
|
let brush = parseColour colourString |
|
let pWidth = float32 (Random().Next()) |
|
let randRows = Random().Next() |
|
let randCols = Random().Next() |
|
let intendedSpec = |
|
{ originalPath = loadPath |
|
savePath = savePath |
|
colour = brush |
|
penWidth = pWidth |
|
rows =randRows |
|
columns = randCols } |
|
let spec = |
|
buildSpec loadPath randRows randCols pWidth colourString savePath |
|
intendedSpec = spec |
|
|
|
[<Property>] |
|
let ``Can build a SkiaSpec as intended`` () = |
|
let colourString = randomColourString () |
|
let colour = parseSkiaColour colourString |
|
let pWidth = float32 (Random().Next()) |
|
let randRows = (Random().Next()) |
|
let randCols = (Random().Next()) |
|
let intendedSpec = |
|
{ originalPath = loadPath |
|
savePath = savePath |
|
skColour = colour |
|
penWidth = pWidth |
|
rows =randRows |
|
columns = randCols } |
|
let spec = |
|
buildSkiaSpec loadPath randRows randCols pWidth colourString savePath |
|
intendedSpec = spec |
|
|
|
[<Property>] |
|
let ``Can build a SkiaRGBSpec as intended`` () = |
|
let r = (Random().Next()) |
|
let g = (Random().Next()) |
|
let b = (Random().Next()) |
|
let pWidth = float32 (Random().Next()) |
|
let randRows = (Random().Next()) |
|
let randCols = (Random().Next()) |
|
let intendedSpec = |
|
{ originalPath = loadPath |
|
savePath = savePath |
|
red = (float32 r) |
|
green = (float32 g) |
|
blue = (float32 b) |
|
penWidth = pWidth |
|
rows =randRows |
|
columns = randCols } |
|
let spec = |
|
buildSkiaRGBSpec loadPath randRows randCols pWidth r g b savePath |
|
intendedSpec = spec |
|
|
|
module UnitTests = |
|
|
|
open System.IO |
|
open DeathSocketCLI.Validation |
|
open Xunit |
|
open TestingHelpers |
|
|
|
[<Fact>] |
|
let ``Saving Test Area can be located`` () = |
|
Assert.True (Directory.Exists saveLocation) |
|
|
|
[<Fact>] |
|
let ``Loading Test Area can be located`` () = |
|
Assert.True (Directory.Exists loadLocation) |
|
|
|
[<Fact>] |
|
let ``Colour list is not empty`` () = |
|
Assert.False (colourList.IsEmpty) |
|
|
|
[<Fact>] |
|
let ``Exception thrown when invalid colour is used`` () = |
|
Assert.Throws<System.ArgumentException> |
|
(fun () -> parseColour "not a valid colour" |> ignore) |
|
|
|
[<Fact>] |
|
let ``Skia colour list is not empty`` () = |
|
Assert.False (skiaColourList.IsEmpty) |
|
|
|
[<Fact>] |
|
let ``Exception thrown when invalid skia-colour is used`` () = |
|
Assert.Throws<System.ArgumentException> |
|
(fun () -> parseSkiaColour "not a valid colour" |> ignore)
|
|
|