Browse Source

Wrote a unit test for RequestCleanText.

Added DefaultSentenceCount in InputGeneration and refactored unit tests to include it where needed.
master
Craig Oates 6 years ago
parent
commit
11f97f5fcd
  1. 11
      TestCentre/InputGeneration.fs
  2. 27
      TestCentre/UnitTests.fs

11
TestCentre/InputGeneration.fs

@ -22,5 +22,14 @@
let index = Random().Next(0, testInputs.Length)
testInputs.[index]
(* Note: Code-Smell for "Desults"
==================================================================================================================
DefaultTestSentence & DefaultSentenceCount should be used in tandem.
Treat is as a code-smell in the (unit and property) tests when they are not.
The main use for these expressions should be the "clean" functions.
If you change the DefaultTestSentence, remember to change the random-range for DefaultSentencsCount.
*)
[<Literal>]
let DefaultTestSentence = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let DefaultTestSentence = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let DefaultSentenceCount () = Random().Next(1, 5)

27
TestCentre/UnitTests.fs

@ -115,27 +115,26 @@
// This function is mostly for the "cleaning" functions, hence placement.
// Feel free to use through this module if needed.
let private countSentences text =
Regex.Split(text, @"(?<=[\.\!\?]\s)")
|> Array.length
let count =
Regex.Split(text, @"(?<=[\.\!\?]\s)")
|> Array.length
(count - 1) // Split creates an extra (empty) item at end.
[<Fact>]
let ``CleanResult returns a string with a full stop`` () =
let result =
Pancake.CleanResult (Random().Next(1, 5)) DefaultTestSentence
Pancake.CleanResult (DefaultSentenceCount()) DefaultTestSentence
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (Random().Next(1,5))
let desiredSentencesCount = (DefaultSentenceCount())
let result =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> countSentences
Assert.Equal(desiredSentencesCount, (result - 1))
// YOU ARE HERE...
// - ADD TESTS FOR "CLEANING" FUNCTIONS
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
@ -144,6 +143,18 @@
|> Async.RunSynchronously
Assert.NotEmpty result
[<Fact>]
let ``RequestCleanText returns intended number of sentences`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) desiredSentencesCount
|> Async.RunSynchronously
|> countSentences
Assert.Equal(desiredSentencesCount, result)
// YOU ARE HERE...
// - ADD TESTS FOR "CLEANING" FUNCTIONS
[<Fact>]
let ``RequestRandomText returns a string which contains a full stop`` () =
let result =

Loading…
Cancel
Save