Browse Source

add unit tests for scaleLineThickness function.

master
Craig Oates 5 years ago
parent
commit
c6b32fcac2
  1. 13
      DeathSocket/Domain.fs
  2. 4
      DeathSocket/GridPainter.fs
  3. 6
      DeathSocket/ImageServices.fs
  4. 22
      TestCentre/LibraryTests.fs

13
DeathSocket/Domain.fs

@ -97,7 +97,7 @@
///The number of columns the grid will have. ///The number of columns the grid will have.
columns: int } columns: int }
/// Discriminated Union representing the various specification types /// A Discriminated Union representing the various specification types
/// Death Socket can use to apply a grid to an image. /// Death Socket can use to apply a grid to an image.
type ImageSpec = type ImageSpec =
| Brush of BrushSpec | Brush of BrushSpec
@ -105,9 +105,14 @@
| Skia of SkiaSpec | Skia of SkiaSpec
| SkiaRGB of SkiaRGBSpec | SkiaRGB of SkiaRGBSpec
/// Discriminated Union representing the graphics libraries used by /// A Discriminated Union representing a type of image. The type refers
/// Death Socket. Useful for selecting which one you want to use. /// to the graphics library used to read the image file.
/// System.Drawing for using Windows/Mono and SkiaSharp for Xamarin. /// The graphics library determines how the image is stored in memory
/// and the functions you can perform on it.
/// When creating an ImageType, pass in the file path of the image
/// as a string. If you are on Windows or using Mono, SystemDrawing is
/// the recommended choice. If you using Xamarin, SkiaSharp is the
/// recommended choice.
type ImageType = type ImageType =
| SkiaSharp of string | SkiaSharp of string
| SystemDrawing of string | SystemDrawing of string

4
DeathSocket/GridPainter.fs

@ -51,8 +51,6 @@ namespace DeathSocket
printfn "File could not be found at %s" ex.Message printfn "File could not be found at %s" ex.Message
} }
// NOT TESTED
/// <summary> /// <summary>
/// Determines the current scale an image is viewed at (E.G. scaled /// Determines the current scale an image is viewed at (E.G. scaled
/// preview in image viewer). The (pen) line thickness is then updated /// preview in image viewer). The (pen) line thickness is then updated
@ -75,7 +73,7 @@ namespace DeathSocket
/// you should not need to use this function when using them. /// you should not need to use this function when using them.
/// </remarks> /// </remarks>
let scaleLineThickness (previewDimension: double) (actualDimension: double) (lineThickness: double) = let scaleLineThickness (previewDimension: double) (actualDimension: double) (lineThickness: double) =
lineThickness / (previewDimension / actualDimension) setLineThickness previewDimension actualDimension lineThickness
// NOT TESTED // NOT TESTED

6
DeathSocket/ImageServices.fs

@ -6,6 +6,12 @@
open DeathSocket open DeathSocket
open ColourServices open ColourServices
open SkiaSharp open SkiaSharp
open System
let setLineThickness pDimension aDimension lineWidth =
if (pDimension <= 0.0 || aDimension <= 0.0 || lineWidth <= 0.0) then
raise (new DivideByZeroException ("[ERROR] The images height and width must be greater than 0."))
else lineWidth / (pDimension / aDimension)
// SkiaSharp Functions // SkiaSharp Functions
// ======================================================================== // ========================================================================

22
TestCentre/LibraryTests.fs

@ -111,6 +111,8 @@
"reset" function to see all the images produced by this test. This will "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. *) mean you will need to manually delete the images yourself if you do. *)
// scaleLineThickness
[<Property>] [<Property>]
let ``Can apply grid to image and save it using BrushSpec`` () = let ``Can apply grid to image and save it using BrushSpec`` () =
resetSavingTestArea () resetSavingTestArea ()
@ -219,6 +221,8 @@
module UnitTests = module UnitTests =
// scaleLineThickness
open TestingHelpers open TestingHelpers
open Xunit open Xunit
open DeathSocket open DeathSocket
@ -254,4 +258,22 @@
[<Fact>] [<Fact>]
let ``Divide By Zero Exception is thrown when 0 columns is used when determining vertical lines`` () = let ``Divide By Zero Exception is thrown when 0 columns is used when determining vertical lines`` () =
let result () = GridPainter.determineVerticalLines 100 100 0 let result () = GridPainter.determineVerticalLines 100 100 0
Assert.Throws<DivideByZeroException>(fun () -> result () |> ignore)
[<Fact>]
let ``Divide By Zero Exception is thrown when previewDimension is set to 0 when calling scaleLineThickness`` () =
let result () =
GridPainter.scaleLineThickness 0.0 1.0 1.0
Assert.Throws<DivideByZeroException>(fun () -> result () |> ignore)
[<Fact>]
let ``Divide By Zero Exception is thrown when actualDimension is set to 0 when calling scaleLineThickness`` () =
let result () =
GridPainter.scaleLineThickness 1.0 0.0 1.0
Assert.Throws<DivideByZeroException>(fun () -> result () |> ignore)
[<Fact>]
let ``Divide By Zero Exception is thrown when lineThickness is set to 0 when calling scaleLineThickness`` () =
let result () =
GridPainter.scaleLineThickness 1.0 1.0 0.0
Assert.Throws<DivideByZeroException>(fun () -> result () |> ignore) Assert.Throws<DivideByZeroException>(fun () -> result () |> ignore)
Loading…
Cancel
Save