Browse Source

Wrote CleanResult ends with "correct end-token" unit test.

Renamed CleanResult to include "async" naming convention.
Refactored the "cleaning" functions. The text now trims the end of the setences instead of using the "length - 1" trick we all know and love.
Updated the DefaultTestSentences collection in TestCentre.
master
Craig Oates 6 years ago
parent
commit
719dd6b5fd
  1. 7
      TestCentre/InputGeneration.fs
  2. 6
      TestCentre/PropertyTests.fs
  3. 12
      TestCentre/UnitTests.fs
  4. 4
      WetPancake/DataCleaning.fs
  5. 6
      WetPancake/DataServices.fs
  6. 7
      WetPancake/ProductServices.fs

7
TestCentre/InputGeneration.fs

@ -2,6 +2,7 @@
open System
open TestingConstants
open Helpers
let ValidGibberishLevelInput () =
let testInputs = [|2 .. 20|]
@ -22,7 +23,7 @@
let index = Random().Next(0, testInputs.Length)
testInputs.[index]
(* Note: Code-Smell for "Desults"
(* Note: Code-Smell for "Defaults"
==================================================================================================================
DefaultTestSentence & DefaultSentenceCount should be used in tandem.
Treat is as a code-smell in the (unit and property) tests when they are not.
@ -32,4 +33,6 @@
[<Literal>]
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)
let private testSentCount = CountSentences DefaultTestSentence
let DefaultSentenceCount () = Random().Next(1, testSentCount)

6
TestCentre/PropertyTests.fs

@ -97,11 +97,11 @@
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount())
let test () =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence
Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> CountSentences
let results = Assert.Equal(desiredSentencesCount , test())
Check.Quick results
let results () = Assert.Equal(desiredSentencesCount , test())
Check.Quick (results())
[<Property>]

12
TestCentre/UnitTests.fs

@ -39,7 +39,7 @@
[<Fact>]
let ``CleanResult does not return a null`` () =
let text = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let result = Pancake.CleanResult (Random().Next(1, 6)) text
let result = Pancake.CleanResultAsync (Random().Next(1, 6)) text
Assert.NotNull result
[<Fact>]
@ -112,11 +112,19 @@
module ``Contents Tests`` =
[<Fact>]
let ``CleanResult returns a string which ends with the correct end-token`` () =
let result () =
Pancake.CleanResultAsync (DefaultSentenceCount()) DefaultTestSentence
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result())
[<Fact>]
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount())
let result =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence
Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)

4
WetPancake/DataCleaning.fs

@ -4,4 +4,6 @@
let ReplaceArtifact pattern text = Regex.Replace(text, pattern, " ")
let SplitText pattern text = Regex.Split(text, pattern)
let SplitText pattern text = Regex.Split(text, pattern)
let TrimEnd charArray (text: string) = text.TrimEnd charArray //[|' '|]

6
WetPancake/DataServices.fs

@ -90,6 +90,8 @@
let RemoveArtifactSentences noOfSentences text =
text
|> SplitText @"(?<=[\.\!\?]\s)"
|> Array.take (noOfSentences - 1)
|> Array.take noOfSentences
|> ConcatToString
|> ReplaceArtifact " "
|> ReplaceArtifact " "
|> TrimEnd [|' '|]

7
WetPancake/ProductServices.fs

@ -13,8 +13,7 @@ module Pancake =
open System.IO
// TODO: Add XML comments to CleanResult function.
// Not 100% correct. Hunch is in RemoveArtifactSentences.
let CleanResult noOfSentences text =
let CleanResultAsync noOfSentences text =
async {
let cleanText =
text
@ -162,7 +161,7 @@ module Pancake =
let RequestCleanTextAsync (gibberishLevel: int) (sentences: int) =
async {
let! text = RequestTextAsync gibberishLevel sentences
let! cleanText = CleanResult sentences text
let! cleanText = CleanResultAsync sentences text
return cleanText
}
@ -170,6 +169,6 @@ module Pancake =
let RequestCleanTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =
async {
let! text = RequestTextFromFileAsync gibberishLevel sentences filePath
let! cleanText = CleanResult sentences text
let! cleanText = CleanResultAsync sentences text
return cleanText
}
Loading…
Cancel
Save