Browse Source

Merge pull request #4 from CraigOates/0.4-p2

0.4 p2 into 0.4 p1
master
Craig Oates 6 years ago committed by GitHub
parent
commit
2e24dc1e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 73
      TestCentre/PropertyTests.fs
  2. 8
      TestCentre/TestCentre.fsproj
  3. 3
      TestCentre/TestingConstants.fs
  4. 13
      TestCentre/TextFiles/test-post.txt
  5. 120
      TestCentre/UnitTests.fs
  6. 2
      TestCentre/packages.config
  7. 35
      WetPancake/DataServices.fs
  8. 21
      WetPancake/ProductServices.fs
  9. 27
      WetPancake/Script.fsx
  10. 22
      WetPancake/SystemServices.fs
  11. 13
      WetPancake/TextFiles/test-post.txt
  12. 1
      WetPancake/WetPancake.fsproj

73
TestCentre/PropertyTests.fs

@ -0,0 +1,73 @@
module PropertyTests
open FsCheck
open global.Xunit
open FsCheck.Xunit
open WetPancake
open TestingConstants
[<Property>]
let ``Request Random Text does not return null when using the built-in random settings`` () =
let test = Pancake.RequestRandomText
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``TEMP Request Random Text does not return null when using the built-in random settings`` () =
let test = Pancake.RequestRandomText
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Request Text does not return null when using fixed input parameters`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestText gibberishLevel totalSentences
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random gibberish level`` () =
let gibberishLevel = System.Random().Next(2, 10)
let test = Pancake.RequestText 5 10
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random sentence count`` () =
let totalSentences = System.Random().Next(2, 10)
let test () = Pancake.RequestText 5 totalSentences
let results () = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Using desktop-clock-info does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences DesktopClock
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Using console-waterworks-announcement does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences ConsoleWaterworks
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Using word-generator does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences WordGenerator
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Using test-post does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences TestPost
let results = Assert.NotNull test
Check.Quick results

8
TestCentre/TestCentre.fsproj

@ -58,13 +58,21 @@
<Content Include="TextFiles\desktop-clock-info.txt" />
<Content Include="TextFiles\console-waterworks-announcement.txt" />
<Content Include="TextFiles\word-generator.txt" />
<Content Include="TextFiles\test-post.txt" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="TestingConstants.fs" />
<Compile Include="UnitTests.fs" />
<Compile Include="PropertyTests.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FsCheck">
<HintPath>..\packages\FsCheck.2.11.0\lib\net452\FsCheck.dll</HintPath>
</Reference>
<Reference Include="FsCheck.Xunit">
<HintPath>..\packages\FsCheck.Xunit.2.11.0\lib\net452\FsCheck.Xunit.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core">
<HintPath>..\packages\FSharp.Core.4.5.0\lib\net45\FSharp.Core.dll</HintPath>
</Reference>

3
TestCentre/TestingConstants.fs

@ -8,3 +8,6 @@ let ConsoleWaterworks = __SOURCE_DIRECTORY__ + @"\TextFiles\console-waterworks-
[<Literal>]
let WordGenerator = __SOURCE_DIRECTORY__ + @"\TextFiles\word-generator.txt"
[<Literal>]
let TestPost = __SOURCE_DIRECTORY__ + @"\TextFiles\test-post.txt"

13
TestCentre/TextFiles/test-post.txt

@ -0,0 +1,13 @@
This is a test post for testing inner-page navigation, in the Writing section. Please ignore this post. It is only here for testing purposes. You are free to continue reading if you want but I can assure you no manner of meaningful meaning will arrive.
This is a piece of writing, which offers you nothing in return for your time spent reading it. This is selfish, in many ways, and the piece should show remorse or even shame. But, as you might have guessed, a piece of writing does not have feelings. Imagine if it did, though. Think of all the bizarre situations you would partake in. What a magical mind-quest you could have...
I see you have continued on this path to nothingness... How would you like this to end? I am at a lost so please tell me. Oh, wait... I, the writer or is it waiter? have written this at a time when you were not present. So, you have no way of communicating your goals with me -- that is a pity. Seeing as I do not know how you would like me to conclude this moment, I will fall-back to the truth -- yet again. There is no meaning here.
Wow, you really are sticking around, aren't you? Hmm... okay... I guess I should make you take your shoes off and offer you a brew. Come on then! Let's be 'avin' yea! Come in! Come in! Let's get down and dirty in the minutiae...
Let me begin by offering you a sincere "Hello and how are you today?" I hope the weather is nice when and where you are. There is something about it which can make or break a day. The tussle between working with and against it can leave a mark on the soul. But, there is a certain type of comfort to be had when you acknowledge it will always win against the human race. Jammy dodger? Would you like sugar in your tea?
Is that the doorbell? Excuse me, I'm just going to see whom it is -- or is it who?
...

120
TestCentre/UnitTests.fs

@ -1,53 +1,69 @@
namespace TestCentre
module ``Unit Tests``
module ``Unit Tests`` =
open Xunit
open WetPancake
open TestingConstants
open System.IO
(*These tests check to see if the .txt files exists in the Test Centre project.
The Wet Pancake library does not expose the file access functions so the .txt
files are mirrored here (in Text Centre)
The mirroring, also, doubles up as sample files to pass into Wet Pancake.*)
[<Fact>]
let ``desktop-clock-info-txt can be found`` () =
let result = File.Exists DesktopClock
Assert.Equal(true, result);
[<Fact>]
let ``console-waterworks-announcements-txt can be found`` () =
let result = File.Exists ConsoleWaterworks
Assert.Equal(true, result);
[<Fact>]
let ``word-generator-txt can be found`` () =
let result = File.Exists WordGenerator
Assert.Equal(true, result);
[<Fact>]
let ``Request Random Text does not generate a null`` () =
let result = Pancake.RequestRandomText
Assert.NotNull result
[<Fact>]
let ``Request Text does not generate a null`` () =
let result = Pancake.RequestText 5 5
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for desktop-clock-info-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 DesktopClock
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for console-waterworks-announcement-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for word-generator-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 WordGenerator
Assert.NotNull result
open Xunit
open WetPancake
open TestingConstants
open System.IO
(*These tests check to see if the .txt files exists in theTest Centre project.
The Wet Pancake library does not expose the file accessfunctions so the .txt files are mirrored here (in Text Centre).
The mirroring, also, doubles up as sample files to pass intoWet Pancake.*)
[<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)
[<Fact>]
let ``Request Random Text does not return a null`` () =
let result = Pancake.RequestRandomText
Assert.NotNull result
[<Fact>]
let ``Request Text does not return a null`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result () = Pancake.RequestText gibberishLevel totalSentences
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not return a null for desktop-clock-info`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFile gibberishLevel totalSentences DesktopClock
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not return a null for console-waterworks-announcement`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFile gibberishLevel totalSentences ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not return a null for word-generator`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFile gibberishLevel totalSentences WordGenerator
Assert.NotNull result
[<Fact>]
let ``Request Test From File does not generate a null for test-post`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFile gibberishLevel totalSentences TestPost
Assert.NotNull result

2
TestCentre/packages.config

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FsCheck" version="2.11.0" targetFramework="net471" />
<package id="FsCheck.Xunit" version="2.11.0" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
<package id="xunit" version="2.3.1" targetFramework="net471" />

35
WetPancake/DataServices.fs

@ -7,15 +7,19 @@
open System.Threading
let rec GenerateMarkovChain (map: Map<string, string List>) (state:string) chain =
let nextChoice = map.[state] |> PickNextWord
if MatchText @"\." nextChoice then nextChoice :: chain
if map.ContainsKey state then
let nextChoice = map.[state] |> PickNextWord
if MatchText @"\." nextChoice then nextChoice :: chain
else
let currentWords =
state
|> SplitText @"\s+"
|> Seq.skip 1
|> ConcatToString
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain)
else
let currentWords =
state
|> SplitText @"\s+"
|> Seq.skip 1
|> ConcatToString
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain)
let fallbackChoice = (PickRandomItem map).Key
fallbackChoice + "." :: chain
let GenerateMarkovSentence map start =
GenerateMarkovChain map start [start]
@ -37,4 +41,19 @@
Thread.Sleep(100)
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
}
result |> ConcatToString
(*
YOU ARE UP TO HERE!
My hunch is I need to validate the startwords collection.
If the startwords is empty, the key generated from it will not be found in the map of possible results to append on to the initial word in startwords.
*)
let GenerateMarkovTextTesting noOfSentences map =
let startWords = fst(SeperateStartWords map)
let result =
seq {
for i in 1 .. noOfSentences do
Thread.Sleep(100)
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
}
result |> ConcatToString

21
WetPancake/ProductServices.fs

@ -7,7 +7,6 @@ module Pancake =
open DataProcessing
open DataStructuring
open DataServices
open System
let RequestRandomText() =
let data =
@ -15,7 +14,8 @@ module Pancake =
|> ApplyStandardSetup
|> SortIntoGroups (PickRandomNumber 2 10)
|> GenerateMap
GenerateMarkovText (PickRandomNumber 2 10) data
//GenerateMarkovText (PickRandomNumber 2 10) data
GenerateMarkovTextTesting (PickRandomNumber 2 10) data
let RequestText (gibberishLevel: int) (sentences: int) =
let data =
@ -23,7 +23,9 @@ module Pancake =
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
GenerateMarkovText sentences data
//GenerateMarkovText sentences data
GenerateMarkovTextTesting sentences data
let RequestTextFromFile (gibberishLevel: int) (sentences: int) (filePath: string) =
let data =
@ -31,4 +33,15 @@ module Pancake =
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
GenerateMarkovText sentences data
//GenerateMarkovText sentences data
GenerateMarkovTextTesting sentences data
(* Should the library provide list of the available default txt files?
By doing so, the user can specify a particular file from the list available.
Is this overkill?
Command-method Example
======================
public static string RetrieveAllTxtFiles()...
public static string GenerateTextFromDefault(gibberishLevel, sentences, defaultFileName)... *)

27
WetPancake/Script.fsx

@ -24,7 +24,22 @@ let ss_number = PickRandomNumber 10
let ss_item =
let items = seq {1 .. 10}
PickRandomItem items
let ss_items2 =
let items = seq { for i in 0 .. 0 -> "." }
printfn "ss_items2 length is %i" (Seq.length items)
PickRandomItem items
(*
This is throwing errors so leaving as a comment for the moment.
let ss_items3 =
let items =
[ "Key 1", ["Value 1-1"; "Value 1-2"];
"Key 2", ["Value 2-1"; "Value 2-2"];
"Key 3", ["Value 3-1"; "Value 3-2"]; ]
|> Map.ofList
printfn "ss_items3 count is %i" items.Count
let result = PickStartWords items
printfn "ss_items3 final result is %s" result
*)
// Data Access
let da_sampleFilePath = CreateSampleTextFilesPath
@ -115,9 +130,13 @@ let dss_text =
|> ApplyStandardSetup
|> SortIntoGroups 2
|> GenerateMap
let dss_startwords = SeperateStartWords dss_text
let dss_sentences = GenerateMarkovText 2 dss_text
printfn "Text: %A" dss_sentences
//let dss_startwords = SeperateStartWords dss_text
//let dss_sentences = GenerateMarkovText 2 dss_text
//printfn "Text: %A" dss_sentences
let dss_sentences2 = GenerateMarkovTextTesting 2 dss_text
printfn "Text: %A" dss_sentences2
// (WetPancake) Pancake
let p_result = Pancake.RequestRandomText()

22
WetPancake/SystemServices.fs

@ -1,23 +1,23 @@
module internal SystemServices
open System
open System.Collections.Generic
let PickRandomNumber min max = Random().Next(min, max);
let PickRandomNumber min max = Random().Next(min, max)
let PickRandomItem seq =
(* This if check equates to an empty sequence.
The program cannot continue at this point.
Need a better way to handle this error.
Need a way to give a reasonable "default value" back. *)
if (Seq.length seq) = 0 then
seq |> Seq.item 0
else
let index = Random().Next(0, Seq.length seq);
let index = PickRandomNumber 1 (Seq.length seq)
seq |> Seq.item index
(* The if-check is used as a fallback.
The "." is used to signifiy the end of a sentence.
This return is picked up in the system,
in the GenerateMarkovChain function. *)
let PickNextWord seq =
if (Seq.length seq) = 0 then
"."
else
let index = Random().Next(0, Seq.length seq);
seq |> Seq.item index
let index = PickRandomNumber 0 (Seq.length seq)
seq |> Seq.item index
let PickStartWords seq = 0

13
WetPancake/TextFiles/test-post.txt

@ -0,0 +1,13 @@
This is a test post for testing inner-page navigation, in the Writing section. Please ignore this post. It is only here for testing purposes. You are free to continue reading if you want but I can assure you no manner of meaningful meaning will arrive.
This is a piece of writing, which offers you nothing in return for your time spent reading it. This is selfish, in many ways, and the piece should show remorse or even shame. But, as you might have guessed, a piece of writing does not have feelings. Imagine if it did, though. Think of all the bizarre situations you would partake in. What a magical mind-quest you could have...
I see you have continued on this path to nothingness... How would you like this to end? I am at a lost so please tell me. Oh, wait... I, the writer or is it waiter? have written this at a time when you were not present. So, you have no way of communicating your goals with me -- that is a pity. Seeing as I do not know how you would like me to conclude this moment, I will fall-back to the truth -- yet again. There is no meaning here.
Wow, you really are sticking around, aren't you? Hmm... okay... I guess I should make you take your shoes off and offer you a brew. Come on then! Let's be 'avin' yea! Come in! Come in! Let's get down and dirty in the minutiae...
Let me begin by offering you a sincere "Hello and how are you today?" I hope the weather is nice when and where you are. There is something about it which can make or break a day. The tussle between working with and against it can leave a mark on the soul. But, there is a certain type of comfort to be had when you acknowledge it will always win against the human race. Jammy dodger? Would you like sugar in your tea?
Is that the doorbell? Excuse me, I'm just going to see whom it is -- or is it who?
...

1
WetPancake/WetPancake.fsproj

@ -54,6 +54,7 @@
<Content Include="TextFiles\desktop-clock-info.txt" />
<Content Include="TextFiles\console-waterworks-announcement.txt" />
<Content Include="TextFiles\word-generator.txt" />
<Content Include="TextFiles\test-post.txt" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="SystemServices.fs" />
<Compile Include="DataAccess.fs" />

Loading…
Cancel
Save