Skip to content

Commit

Permalink
Implement pangram
Browse files Browse the repository at this point in the history
Note: This won't pass CI. I haven't yet put the problem into
config.json. Waiting on exercism#127

Implements the Pangram problem and follows the current canonical test
suite.
  • Loading branch information
whit0694 committed May 27, 2016
1 parent 83e4c0b commit b50a468
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exercises/pangram/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exercises/pangram/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "pangram"
version = "0.0.0"
18 changes: 18 additions & 0 deletions exercises/pangram/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::collections::BTreeSet;
use std::ascii::AsciiExt;
use std::iter::FromIterator;

pub fn is_pangram(sentence: &str) -> bool {
sentence.to_lowercase()
.chars()
.filter(|c| c.is_alphabetic())
.filter(|c| c.is_ascii())
.collect::<BTreeSet<char>>() == english_letter_set()

}

fn english_letter_set() -> BTreeSet<char> {
BTreeSet::from_iter(ENGLISH_ALPHABET.chars())
}

const ENGLISH_ALPHABET: &'static str = "abcdefghijklmnopqrstuvwxyz";
65 changes: 65 additions & 0 deletions exercises/pangram/tests/pangram.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
extern crate pangram;

use pangram::*;

#[test]
fn empty_strings_are_not_pangrams() {
let sentence = "";
assert!(!is_pangram(&sentence));
}

#[test]
#[ignore]
fn classic_pangram_is_a_pangram() {
let sentence = "the quick brown fox jumps over the lazy dog";
assert!(is_pangram(&sentence));
}

#[test]
#[ignore]
fn pangrams_must_have_all_letters() {
let sentence = "a quick movement of the enemy will jeopardize five gunboats";
assert!(!is_pangram(&sentence));
}

#[test]
#[ignore]
fn pangrams_must_have_all_letters_two() {
let sentence = "the quick brown fish jumps over the lazy dog";
assert!(!is_pangram(&sentence));
}

#[test]
#[ignore]
fn underscores_do_not_affect_pangrams() {
let sentence = "the_quick_brown_fox_jumps_over_the_lazy_dog";
assert!(is_pangram(&sentence));
}

#[test]
#[ignore]
fn numbers_do_not_affect_pangrams() {
let sentence = "the 1 quick brown fox jumps over the 2 lazy dogs";
assert!(is_pangram(&sentence));
}

#[test]
#[ignore]
fn numbers_can_not_replace_numbers() {
let sentence = "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog";
assert!(!is_pangram(&sentence));
}

#[test]
#[ignore]
fn capitals_and_punctuation_can_be_in_pangrams() {
let sentence = "\"Five quacking Zephyrs jolt my wax bed.\"";
assert!(is_pangram(&sentence));
}

#[test]
#[ignore]
fn non_ascii_characters_can_be_in_pangrams() {
let sentence = "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.";
assert!(is_pangram(&sentence));
}

0 comments on commit b50a468

Please sign in to comment.