diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index b0d8a2d..0dbe187 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -19,11 +19,9 @@ namespace DeathSocket } // Needs XML comments. - // Tests have not been written. let determineHorizontalLines width height rows = createHorizontalLines width height rows // Needs XML comments. - // Tests have not been written. let determineVerticalLines width height columns = createVerticalLines width height columns \ No newline at end of file diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 34dbfd6..8395d4e 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -21,9 +21,12 @@ open System.Reflection open System.IO + let rand = Random () + + (* These are duplicates from ConsoleTests.fs (both of them). See point about helpers. Tests for checking these locations can be found in - ConsoleTests.fs.*) + ConsoleTests.fs. *) let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea" @@ -35,14 +38,18 @@ |> Seq.toArray let randomBrush () = - let item = allColours.[Random().Next(allColours.Length)] + let item = allColours.[rand.Next(allColours.Length)] item.GetValue(null, null) + (* Max. value is arbitrary (change for performance). + Min. value is to stop divide by zero exceptions. + Intended for horizontal and vertical line tests. *) + let newNum () = rand.Next(1, 1000) + let imagesInLoadingTestArea = Directory.GetFileSystemEntries (loadLocation, "*.png") let generateLoadPath () = - let rand = Random () let files = imagesInLoadingTestArea files.[rand.Next(files.Length)] @@ -51,7 +58,7 @@ saveLocation + "/" + fileName (* To "manually" clear out the SavingTestArea folder, use this function - in script.fsx. More information can be found there, also.*) + in script.fsx. More information can be found there, also. *) let resetSavingTestArea () = let files = Directory.GetFileSystemEntries(saveLocation, "*.png") match files.Length with @@ -68,13 +75,14 @@ open DeathSocket.GridPainter open TestingHelpers open System.IO + open System [] let ``Can apply grid to image and save it`` () = (* You should end up with one image left over in SavingTestArea. Comment out the "reset" function to see all the images produced, by this test. This will mean you will need to manually delete the - images yourself if you do.*) + images yourself if you do. *) resetSavingTestArea () let oPath = generateLoadPath () let sPath = generateSavePath oPath @@ -89,6 +97,16 @@ |> Async.RunSynchronously (File.Exists sPath) = true + [] + let ``Can return a collection of points which represent a grids horizontal lines`` () = + let result = determineHorizontalLines (newNum()) (newNum()) (newNum()) + result.Length > 0 + + [] + let ``Can return a collection of points which represent a grids vertical lines`` () = + let result = determineVerticalLines (newNum()) (newNum()) (newNum()) + result.Length > 0 + module UnitTests = open TestingHelpers