Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pangram #132

Merged
merged 1 commit into from
Jun 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"difference-of-squares",
"hamming",
"scrabble-score",
"pangram",
"nucleotide-count",
"word-count",
"etl",
Expand Down
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .graphemes iterator might be a better choice here:

http://www.steveklabnik.com/rust-issue-17340/#indexing-strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@EduardoBautista EduardoBautista Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IanWhitney haha, that shows how long it's been since I've played with Rust. Code looks good to me, but now I am not so confident in my Rust review skills haha.

.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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numbers cannot replace letters, I presume

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));
}