Browse Source

Cleaned up the current exception tests.

Made a note about refactoring the input generation code in the Test Centre.
master
Craig Oates 6 years ago
parent
commit
c94ff012ab
  1. 29
      TestCentre/PropertyTests.fs
  2. 23
      TestCentre/UnitTests.fs

29
TestCentre/PropertyTests.fs

@ -6,6 +6,7 @@
open WetPancake
open TestingConstants
open System.Diagnostics
open System
module ``Null Tests`` =
@ -220,20 +221,32 @@
Check.Quick results
module ``Exception Tests`` =
open System
open System.Threading.Tasks
// YOU ARE HERE -- WRITE EXCEPTION TESTS (DON'T FOGET UNIT TESTS).
// Move this to an input generator module? seperate file?
// Will remove the copy and pasted code up above as well...
// Keep this and property test files about just the tests...
let ValidGibberishLevelInput () =
let testInputs = [|2 .. 20|]
let index = Random().Next(0, testInputs.Length)
testInputs.[index]
let ValidSentencesInput () = System.Random().Next(2, 10)
let InvalidGibberishInput () =
let testInputs = Array.concat [ [|0; 1|] ; [|21 .. 100|] ]
let index = System.Random().Next(0, testInputs.Length)
testInputs.[index]
let InvalidSentencesInput () = System.Random().Next(-5, 1)
[<Property>]
let ``RequestText throws an ArgumentException when the gibberishLevel is invalid`` () =
//let gibberishLevel () = System.Random().Next(0, 1)
let totalSentences () = System.Random().Next(2, 10)
let test =
Pancake.RequestTextAsync 0 (totalSentences())
let test () =
Pancake.RequestTextAsync (InvalidGibberishInput()) (ValidSentencesInput())
|> Async.RunSynchronously
let results =
lazy Assert.Throws<ArgumentException>(fun () -> test |> ignore)
|> ignore
Check.Quick results
(*

23
TestCentre/UnitTests.fs

@ -194,12 +194,27 @@
module ``Exception Tests`` =
// YOU ARE HERE -- WRITE EXCEPTION TESTS (DON'T FOGET PROPERTY TESTS).
// Move this to an input generator module? seperate file?
// Will remove the copy and pasted code up above as well...
// Keep this and property test files about just the tests...
let ValidGibberishLevelInput () =
let testInputs = [|2 .. 20|]
let index = Random().Next(0, testInputs.Length)
testInputs.[index]
let ValidSentencesInput () = System.Random().Next(2, 10)
let InvalidGibberishInput () =
let testInputs = Array.concat [ [|0; 1|] ; [|21 .. 100|] ]
let index = System.Random().Next(0, testInputs.Length)
testInputs.[index]
let InvalidSentencesInput () = System.Random().Next(-5, 1)
[<Fact>]
let ``RequestText throws an ArgumentException when the gibberishLevel is invalid`` () =
//let gibberishLevel () = System.Random().Next(0, 1)
//let totalSentences () = System.Random().Next(2, 10)
let test () =
Pancake.RequestTextAsync 34 0
Pancake.RequestTextAsync (InvalidGibberishInput()) (ValidSentencesInput())
|> Async.RunSynchronously
lazy Assert.Throws<ArgumentException>(fun () -> test |> ignore) |> ignore

Loading…
Cancel
Save