Skip to content

Commit

Permalink
Add pangram exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
snahor committed Oct 18, 2016
1 parent e21f98b commit 1234552
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pangram/example.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fun isPangram (sentence: string): bool =
let
val alphabet = String.explode "qwertyuiopasdfghjklzxcvbnm"
val chars = map Char.toLower (String.explode sentence)
in
List.all (fn letter => List.exists (fn char => char = letter) chars) alphabet
end
2 changes: 2 additions & 0 deletions pangram/pangram.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fun isPangram (sentence: string): bool =
raise Fail "isPangram is not implemented"
21 changes: 21 additions & 0 deletions pangram/test_pangram.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use "example.sml";

val test_cases = [
("", false),
("The Quick Brown Fox Jumps Over The Lazy Dog", true),
("the quick brown fox jumps over the lazy dog", true),
("a quick movement of the enemy will jeopardize five gunboats", false),
("the quick brown fish jumps over the lazy dog", false),
("the_quick_brown_fox_jumps_over_the_lazy_dog", true),
("the 1 quick brown fox jumps over the 2 lazy dogs", true),
("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog", false),
("\"Five quacking Zephyrs jolt my wax bed.\"", true)
(*"Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.", true*)
(*"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.", false*)
];

fun run_tests [] = []
| run_tests ((sentence, expected) :: ts) =
(isPangram sentence = expected) :: run_tests ts

val allTestsPass = List.foldl (fn (x, y) => x andalso y) true (run_tests test_cases)

0 comments on commit 1234552

Please sign in to comment.