@ -20,13 +20,16 @@
open S y s t e m . D r a w i n g
open S y s t e m . R e f l e c t i o n
open S y s t e m . I O
open D e a t h S o c k e t . D o m a i n
let rand = Random ( )
(* These are duplicates from ConsoleTests.fs (both of them). See p o i n t
about helpers. Tests for checking these locations can be found i n
ConsoleTests.fs. * )
C o n s o l e T e s t s . f s .
Also, these folders should not show up in Visual S t u d i o s
Solution Explorer -- unless you are viewing the solution in its folder
format. * )
let loadLocation = __SOURCE_DIRECTORY__ + " / L o a d i n g T e s t A r e a "
let saveLocation = __SOURCE_DIRECTORY__ + " / S a v i n g T e s t A r e a "
@ -46,6 +49,10 @@
Intended for horizontal and vertical line tests. * )
let newNum () = rand.Next(1, 1000 )
let newPenWidth () = rand.Next (1, 10 )
let newRGBANum () = rand.Next ( 255 )
let imagesInLoadingTestArea =
Directory.GetFileSystemEntries (loadLocation, " * . p n g " )
@ -67,6 +74,17 @@
f i l e s
|> Array.iter (fun f -> F i l e . D e l e t e ( f ) )
let makeTestRGBASpec r g b a =
{ originalPath = "test p a t h "
savePath = "test p a t h "
alpha = float a
red = float r
green = float g
blue = float b
penWidth = float32 10
rows = newNum ( )
columns = newNum () }
module PropertyTests =
open F s C h e c k . X u n i t
@ -75,28 +93,68 @@
open D e a t h S o c k e t . G r i d P a i n t e r
open T e s t i n g H e l p e r s
open S y s t e m . I O
open S y s t e m
(* With regards to the "saving images" tests, you should end up w i t h
one image left over in the SavingTestArea folder. Comment out t h e
"reset" function to see all the images produced by this test. This w i l l
mean you will need to manually delete the images yourself if you do. * )
[ < P r o p e r t y > ]
let ``Can apply grid to image and save it`` () =
(* You should end up with one image left over in S a v i n g T e s t A r e a .
Comment out the "reset" function to see all the images p r o d u c e d ,
by this test. This will mean you will need to manually delete t h e
images yourself if you do. * )
let ``Can apply grid to image and save it using BrushSpec`` () =
resetSavingTestArea ( )
let oPath = generateLoadPath ( )
let sPath = generateSavePath o P a t h
let spec =
let (spec: BrushSpec) =
{ originalPath = o P a t h
savePath = s P a t h
colour = randomBrush () :?> B r u s h
penWidth = float32 1
penWidth = float32 ( n e w P e n W i d t h ( ) )
rows = 10
columns = 10 }
applyBrushSpecGridAsync s p e c
|> A s y n c . R u n S y n c h r o n o u s l y
(File.Exists sPath) = t r u e
[ < P r o p e r t y > ]
let ``Can apply grid to image and save it using RGBASpec`` () =
resetSavingTestArea ( )
let oPath = generateLoadPath ( )
let sPath = generateSavePath o P a t h
let (spec: RGBASpec) =
{ originalPath = o P a t h
savePath = s P a t h
alpha = float (newRGBANum ( ) )
red = float (newRGBANum ( ) )
green = float (newRGBANum ( ) )
blue = float (newRGBANum ( ) )
penWidth = float32 ( n e w P e n W i d t h ( ) )
rows = 10
columns = 10 }
applyGridAsync s p e c
applyRGBA GridAsync s p e c
|> A s y n c . R u n S y n c h r o n o u s l y
(File.Exists sPath) = t r u e
[ < P r o p e r t y > ]
let ``SolidBrush colour matches the individual RGBA values`` () =
let a = newRGBANum ( )
let r = newRGBANum ( )
let g = newRGBANum ( )
let b = newRGBANum ( )
let referenceColour = Color.FromArgb (a, r, g, b )
let brush = makeSolidBrushFromRGBA r g b a
brush.Color = r e f e r e n c e C o l o u r
[ < P r o p e r t y > ]
let ``SolidBrush colour matches the RGBASpec`` () =
let a = newRGBANum ( )
let r = newRGBANum ( )
let g = newRGBANum ( )
let b = newRGBANum ( )
let referenceColour = Color.FromArgb (a, r, g, b )
let referenceSpec = makeTestRGBASpec r g b a
let brush = makeSolidBrushFromRGBASpec r e f e r e n c e S p e c
brush.Color = r e f e r e n c e C o l o u r
[ < P r o p e r t y > ]
let ``Can return a collection of points which represent a grids horizontal lines`` () =
let result = determineHorizontalLines (newNum()) (newNum()) ( n e w N u m ( ) )
@ -113,8 +171,9 @@
open X u n i t
open D e a t h S o c k e t
open S y s t e m
open S y s t e m . I O
(* This test is a precaution (a test for the tests if you w i l l ... ) .
(* This test is a pre-test test (a test for the tests if you w i l l ... ) .
It is here to make sure the property test has what it needs to r u n .
If the property test fails, here is a good place to s t a r t .
See script.fs (in Test Centre) for information on populating t h e
@ -125,6 +184,16 @@
let imagesAreThere = if length < 100 then false else t r u e
Assert.True i m a g e s A r e T h e r e
(* This test is a pre-test test. If the property tests fails, here is a
good place to start. The easiest way to get this test to pass is t o
create a folder called "SavingTestArea" in this projects f o l d e r
(at the root). You can, also, see script.fs (in Test Centre) f o r
creating this folder via code. (See "LoadingTestArea contains..." n o t e
for extra context. * )
[ < F a c t > ]
let ``SavingTestArea folder can be found`` () =
Assert.True (Directory.Exists s a v e L o c a t i o n )
[ < F a c t > ]
let ``Divide By Zero Exception is thrown when 0 rows is used when determining horizontal lines`` () =
let result () = GridPainter.determineHorizontalLines 100 100 0