Browse Source

Added new validation checks to RequestTextFromFile.

Updated the FilePathIsValid to operate in the same way as the gibberishLevelIsValid and SentenceIsVallid structure.
Removed any remaining rough test code associated with the last several commits.
master
Craig Oates 6 years ago
parent
commit
de267a9432
  1. 8
      WetPancake/DataProcessing.fs
  2. 24
      WetPancake/ProductServices.fs
  3. 5
      WetPancakeCLI/ConsoleCommands.cs

8
WetPancake/DataProcessing.fs

@ -22,8 +22,12 @@
| _ -> ignore
let FilePathIsValid filePath =
if Path.GetExtension filePath = ".txt" && File.Exists filePath then true
else false
match filePath with
| filePath when Path.GetExtension filePath = ".txt" ->
raise (ArgumentException("Invalid argument. File must be a .txt file and include avalidfilepath.","filePath"))
| filePath when File.Exists filePath ->
raise (ArgumentException("Invalid argument. File must be a .txt file and include avalidfilepath.","filePath"))
| _ -> ignore
let SortIntoGroups groupSize text =
SplitText @"\s+" text // Splits text where there is a space.

24
WetPancake/ProductServices.fs

@ -42,21 +42,15 @@ module Pancake =
let RequestTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =
async {
try
if GibberishLevelIsValid gibberishLevel then
if SentencesIsValid sentences then
if FilePathIsValid filePath then
let data =
LoadFile filePath
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
return GenerateMarkovText sentences data
else
return raise (ArgumentException("Invalid argument. File must be a .txt file and include a valid file path.", "filePath"))
else
return raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
else
return raise (ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
GibberishLevelIsValid gibberishLevel |> ignore
SentencesIsValid sentences |> ignore
FilePathIsValid |> ignore
let data =
LoadFile filePath
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
return GenerateMarkovText sentences data
with
| :? ArgumentException as ex ->
return ex.Message

5
WetPancakeCLI/ConsoleCommands.cs

@ -113,10 +113,5 @@ namespace WetPancakeCLI
throw;
}
}
public static string failtest(int gibberishLevel, int sentences)
{
return FSharpAsync.StartAsTask(RequestTest(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
}
}

Loading…
Cancel
Save