forked from brenden/ukkonen-animation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Tests (..) where | ||
|
||
import Debug | ||
import Array | ||
import Html exposing (..) | ||
import List exposing (..) | ||
import String | ||
import UkkonenTree exposing (..) | ||
import UkkonenAlgorithm exposing (..) | ||
|
||
|
||
main = | ||
let | ||
testWords = | ||
[ "banana" | ||
, "tctcatcaa#ggaaccattg@tccatctcgc" | ||
, "abacabadabacabae" | ||
, "asdfsfasdfasdfx" | ||
, "aaaaaaa" | ||
, "abababa" | ||
, "abcabxabcd" | ||
, "abcabcdefbcabcd" | ||
, "abcabcdefhabcabcdw" | ||
, "abcabcdefbcabcd" | ||
] | ||
in | ||
text <| | ||
if (all checkValidSuffixTree testWords) then | ||
"All tests passed." | ||
else | ||
"Some tests failed. Check console for details." | ||
|
||
|
||
checkValidSuffixTree : String -> Bool | ||
checkValidSuffixTree input = | ||
let | ||
finalState = | ||
List.head <| List.reverse <| UkkonenAlgorithm.steps (input ++ "$") | ||
in | ||
case finalState of | ||
Just finalState -> | ||
let | ||
suffixes = | ||
Debug.log "expected" <| List.sort <| suffixesOfString input | ||
|
||
suffixesFromTree = | ||
Debug.log " actual" <| | ||
List.sort <| | ||
UkkonenTree.suffixes | ||
finalState.tree | ||
0 | ||
(String.fromList <| Array.toList <| finalState.string) | ||
in | ||
Debug.log "matches" <| suffixes == List.sort suffixesFromTree | ||
|
||
Nothing -> | ||
False | ||
|
||
|
||
suffixesOfString : String -> List String | ||
suffixesOfString string = | ||
let | ||
len = | ||
String.length string | ||
in | ||
List.map | ||
(\n -> String.right n string) | ||
[0..len] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters