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 System
open TestingConstants open TestingConstants
open Helpers
let ValidGibberishLevelInput () = let ValidGibberishLevelInput () =
let testInputs = [|2 .. 20|] let testInputs = [|2 .. 20|]
@ -22,7 +23,7 @@
let index = Random().Next(0, testInputs.Length) let index = Random().Next(0, testInputs.Length)
testInputs.[index] testInputs.[index]
(* Note: Code-Smell for "Desults" (* Note: Code-Smell for "Defaults"
================================================================================================================== ==================================================================================================================
DefaultTestSentence & DefaultSentenceCount should be used in tandem. DefaultTestSentence & DefaultSentenceCount should be used in tandem.
Treat is as a code-smell in the (unit and property) tests when they are not. Treat is as a code-smell in the (unit and property) tests when they are not.
@ -32,4 +33,6 @@
[<Literal>] [<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) 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 ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount()) let desiredSentencesCount = (DefaultSentenceCount())
let test () = let test () =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously |> Async.RunSynchronously
|> CountSentences |> CountSentences
let results = Assert.Equal(desiredSentencesCount , test()) let results () = Assert.Equal(desiredSentencesCount , test())
Check.Quick results Check.Quick (results())
[<Property>] [<Property>]

12
TestCentre/UnitTests.fs

@ -39,7 +39,7 @@
[<Fact>] [<Fact>]
let ``CleanResult does not return a null`` () = 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 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 Assert.NotNull result
[<Fact>] [<Fact>]
@ -112,11 +112,19 @@
module ``Contents Tests`` = 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>] [<Fact>]
let ``CleanResult returns intended number of sentences`` () = let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount()) let desiredSentencesCount = (DefaultSentenceCount())
let result = let result =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously |> Async.RunSynchronously
|> CountSentences |> CountSentences
Assert.Equal(desiredSentencesCount, result) Assert.Equal(desiredSentencesCount, result)

4
WetPancake/DataCleaning.fs

@ -4,4 +4,6 @@
let ReplaceArtifact pattern text = Regex.Replace(text, pattern, " ") 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 = let RemoveArtifactSentences noOfSentences text =
text text
|> SplitText @"(?<=[\.\!\?]\s)" |> SplitText @"(?<=[\.\!\?]\s)"
|> Array.take (noOfSentences - 1) |> Array.take noOfSentences
|> ConcatToString |> ConcatToString
|> ReplaceArtifact " " |> ReplaceArtifact " "
|> TrimEnd [|' '|]

7
WetPancake/ProductServices.fs

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