From fbe6b0fe67647f8f7c74d3e5c3f1693208115ff8 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Fri, 14 Sep 2018 21:19:46 +0100 Subject: [PATCH] add several console unit and property tests. Also, add "grey" option to colour list in CLI. --- DeathSocketCLI/Validation.fs | 1 + TestCentre/ConsoleTests.fs | 35 +++++++++++++++++++++++++++++------ TestCentre/Script.fsx | 9 ++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/DeathSocketCLI/Validation.fs b/DeathSocketCLI/Validation.fs index de3f5cb..db67507 100644 --- a/DeathSocketCLI/Validation.fs +++ b/DeathSocketCLI/Validation.fs @@ -10,6 +10,7 @@ "brown", Brushes.Brown "black", Brushes.Black "gray", Brushes.Gray + "grey", Brushes.Gray "green", Brushes.Green "purple", Brushes.Purple "red", Brushes.Red diff --git a/TestCentre/ConsoleTests.fs b/TestCentre/ConsoleTests.fs index 9ba4a8d..12e0ae9 100644 --- a/TestCentre/ConsoleTests.fs +++ b/TestCentre/ConsoleTests.fs @@ -5,23 +5,46 @@ open System open FsCheck.Xunit open DeathSocket.Validation + open System.Drawing + + let testingColourArray = + colourList + |> Map.toSeq + |> Seq.map fst + |> Seq.toArray + + let randomColour () = + testingColourArray.[Random().Next(testingColourArray.Length)] [] - let ``Setting pen width greater than 0`` () = + let ``Pen width is set greater than 0`` () = (setPenWidth (Random().Next()) (Random().Next())) > 0.0f + [] + let ``Parsed colour matches expected colour`` () = + let expectedColour = (randomColour ()) + let brush = parseColour (expectedColour) + let convertedBrush = (brush :?> SolidBrush).Color.Name.ToLower() + convertedBrush = expectedColour + + module UnitTests = - open Xunit - open DeathSocket.Validation open System.IO + open DeathSocket.Validation + open Xunit - let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/" + let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea" [] let ``Saving Test Area can be located`` () = - Assert.True (Directory.Exists saveLocation) + Assert.True (Directory.Exists (saveLocation)) [] let ``Colour list is not empty`` () = - Assert.False (colourList.IsEmpty) \ No newline at end of file + Assert.False (colourList.IsEmpty) + + [] + let ``Exception thrown when invalid colour is used`` () = + Assert.Throws + (fun () -> parseColour "not a valid colour" |> ignore) \ No newline at end of file diff --git a/TestCentre/Script.fsx b/TestCentre/Script.fsx index 1845605..9274e75 100644 --- a/TestCentre/Script.fsx +++ b/TestCentre/Script.fsx @@ -1,8 +1,3 @@ -// Learn more about F# at http://fsharp.org -// See the 'F# Tutorial' project for more help. - -#load "Library1.fs" -open TestCentre - -// Define your library scripting code here +// Testing scripts to go here... +let saveLocation = __SOURCE_DIRECTORY__ + "\\SavingTestArea" \ No newline at end of file