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.
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.
type ImageSpec =
| Brush of BrushSpec
@ -105,9 +105,14 @@
| Skia of SkiaSpec
| SkiaRGB of SkiaRGBSpec
/// Discriminated Union representing the graphics libraries used by
/// Death Socket. Useful for selecting which one you want to use.
/// System.Drawing for using Windows/Mono and SkiaSharp for Xamarin.
/// A Discriminated Union representing a type of image. The type refers
/// to the graphics library used to read the image file.
/// 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 =
| SkiaSharp 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
}
// NOT TESTED
/// <summary>
/// Determines the current scale an image is viewed at (E.G. scaled
/// 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.
/// </remarks>
let scaleLineThickness (previewDimension: double) (actualDimension: double) (lineThickness: double) =
lineThickness / (previewDimension / actualDimension)
setLineThickness previewDimension actualDimension lineThickness
// NOT TESTED

6
DeathSocket/ImageServices.fs

@ -6,6 +6,12 @@
open DeathSocket
open ColourServices
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
// ========================================================================

22
TestCentre/LibraryTests.fs

@ -111,6 +111,8 @@
"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. *)
// scaleLineThickness
[<Property>]
let ``Can apply grid to image and save it using BrushSpec`` () =
resetSavingTestArea ()
@ -219,6 +221,8 @@
module UnitTests =
// scaleLineThickness
open TestingHelpers
open Xunit
open DeathSocket
@ -254,4 +258,22 @@
[<Fact>]
let ``Divide By Zero Exception is thrown when 0 columns is used when determining vertical lines`` () =
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)
Loading…
Cancel
Save