The purpose of this repository is to provide a way for people to generate random "placeholder text" -- with a Markov Chain. https://www.craigoates.net/Software/project/12
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
10 KiB

module ``Unit Tests``
open Xunit
open WetPancake
open TestingConstants
open System
open System.IO
open InputGeneration
open System.Text.RegularExpressions
module ``File Access Tests`` =
(* These tests check to see if the .txt files exists in the Test Centre project.
The WetPancake library does not expose the file access functions so the .txt files are mirrored here (in Test Centre).
The mirroring, also, doubles up as sample files to pass into WetPancake. *)
[<Fact>]
let ``desktop-clock-info can be found`` () =
let result = File.Exists DesktopClock
Assert.Equal(true, result);
[<Fact>]
let ``console-waterworks-announcements can be found`` () =
let result = File.Exists ConsoleWaterworks
Assert.Equal(true, result);
[<Fact>]
let ``word-generator can be found`` () =
let result = File.Exists WordGenerator
Assert.Equal(true, result);
[<Fact>]
let ``test-post can be found`` () =
let result = File.Exists TestPost
Assert.Equal(true, result)
module ``Null Tests`` =
[<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
Assert.NotNull result
[<Fact>]
let ``RequestAllTemplateFiles does not generate a null`` () =
let result = Pancake.RequestAllTemplateFilesAsync ()
Assert.NotNull result
[<Fact>]
let ``RequestCleanText does not return a null`` () =
let result = Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using console-waterworks-announcement`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using desktop-clock-info`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using test-post`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using word-generator`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Assert.NotNull result
[<Fact>]
let ``RequestRandomText does not return a null`` () =
let result = Pancake.RequestRandomTextAsync ()
Assert.NotNull result
[<Fact>]
let ``RequestText does not return a null`` () =
let result () = Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using console-waterworks-announcement`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Assert.NotNull result
[<Fact>]
let ``RequestTestFromFile does not generate a null when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Assert.NotNull result
module ``Contents Tests`` =
// This function is mostly for the "cleaning" functions, hence placement.
// Feel free to use through this module if needed.
let private countSentences text =
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 (DefaultSentenceCount()) DefaultTestSentence
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount())
let result =
Pancake.CleanResult desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> countSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let result =
Pancake.RequestAllTemplateFilesAsync ()
|> 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 =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestText returns a string which contains a full stop`` () =
let result =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using console-waterworks-announcement`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
Assert.Contains(".", result)
[<Fact>]
let ``RequestRandomText returns a string which ends with a full stop`` () =
let result =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestText returns a string which ends with a full stop`` () =
let result =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestTextFromFile returns a string which ends with a full stop when using console-waterworks-announcement`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
Assert.EndsWith(".", result)