diff --git a/TestCentre/InputGeneration.fs b/TestCentre/InputGeneration.fs index 30de836..7bd4efc 100644 --- a/TestCentre/InputGeneration.fs +++ b/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 @@ [] 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) \ No newline at end of file + let private testSentCount = CountSentences DefaultTestSentence + + let DefaultSentenceCount () = Random().Next(1, testSentCount) \ No newline at end of file diff --git a/TestCentre/PropertyTests.fs b/TestCentre/PropertyTests.fs index 5a22cc0..fed5bf6 100644 --- a/TestCentre/PropertyTests.fs +++ b/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()) [] diff --git a/TestCentre/UnitTests.fs b/TestCentre/UnitTests.fs index 4c92246..3fe7f0d 100644 --- a/TestCentre/UnitTests.fs +++ b/TestCentre/UnitTests.fs @@ -39,7 +39,7 @@ [] 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 [] @@ -112,11 +112,19 @@ module ``Contents Tests`` = + [] + let ``CleanResult returns a string which ends with the correct end-token`` () = + let result () = + Pancake.CleanResultAsync (DefaultSentenceCount()) DefaultTestSentence + |> Async.RunSynchronously + |> EndsAsIntended + Assert.True(result()) + [] 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) diff --git a/WetPancake/DataCleaning.fs b/WetPancake/DataCleaning.fs index 71998a6..7b8a1f3 100644 --- a/WetPancake/DataCleaning.fs +++ b/WetPancake/DataCleaning.fs @@ -4,4 +4,6 @@ let ReplaceArtifact pattern text = Regex.Replace(text, pattern, " ") - let SplitText pattern text = Regex.Split(text, pattern) \ No newline at end of file + let SplitText pattern text = Regex.Split(text, pattern) + + let TrimEnd charArray (text: string) = text.TrimEnd charArray //[|' '|] \ No newline at end of file diff --git a/WetPancake/DataServices.fs b/WetPancake/DataServices.fs index af0dbf4..ef0d149 100644 --- a/WetPancake/DataServices.fs +++ b/WetPancake/DataServices.fs @@ -90,6 +90,8 @@ let RemoveArtifactSentences noOfSentences text = text |> SplitText @"(?<=[\.\!\?]\s)" - |> Array.take (noOfSentences - 1) + |> Array.take noOfSentences |> ConcatToString - |> ReplaceArtifact " " \ No newline at end of file + |> ReplaceArtifact " " + |> TrimEnd [|' '|] + \ No newline at end of file diff --git a/WetPancake/ProductServices.fs b/WetPancake/ProductServices.fs index 2a0834f..b115977 100644 --- a/WetPancake/ProductServices.fs +++ b/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 } \ No newline at end of file