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.
 
 

294 lines
13 KiB

module ``Unit Tests``
open Xunit
open WetPancake
open TestingConstants
open System
open System.IO
open InputGeneration
open Helpers
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 ``console-waterworks-announcements can be found`` () =
let result = File.Exists ConsoleWaterworks
Assert.True result
[<Fact>]
let ``desktop-clock-info can be found`` () =
let result = File.Exists DesktopClock
Assert.True result
[<Fact>]
let ``invalid-text can be found`` () =
let result = File.Exists InvalidTextFile
Assert.True result
[<Fact>]
let ``test-post can be found`` () =
let result = File.Exists TestPost
Assert.True result
[<Fact>]
let ``word-generator can be found`` () =
let result = File.Exists WordGenerator
Assert.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.CleanResultAsync (Random().Next(1, 6)) text
Assert.NotNull result
[<Fact>]
let ``RequestAllTemplateFiles does not generate a null`` () =
let result = Pancake.RequestAllTemplateFiles ()
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
[<Fact>]
let ``TextIsValid does not return a null`` () =
let result = Pancake.TextInFileIsValidAsync TestPost
Assert.NotNull result
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.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let result =
Pancake.RequestAllTemplateFiles ()
Assert.NotEmpty result
[<Fact>]
let ``RequestCleanText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(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)
[<Fact>]
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using console-waterworks-announcement`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using desktop-clock-info`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using test-post`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using word-generator`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using console-waterworks-announcement`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount ConsoleWaterworks
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using desktop-clock-info`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount DesktopClock
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using test-post`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount TestPost
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using word-generator`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount WordGenerator
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestRandomText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a string which ends with the correct end-token when using console-waterworks-announcement`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``TextInFileIsValid returns correct boolean value when processing a files text`` () =
let trueResult =
Pancake.TextInFileIsValidAsync TestPost
|> Async.RunSynchronously
let falseResult =
Pancake.TextInFileIsValidAsync InvalidTextFile
|> Async.RunSynchronously
let outcomes = (trueResult, falseResult)
let finalResult =
match outcomes with
| true, false -> true
| _, _ -> false
Assert.True finalResult