CYRUJI4WX3ZBGYRPPOQ5BJWAH3EHFSNBJD7TG25DWCA33BRIVEQAC
use std::collections::HashSet;
fn process_anagram_case(word: &str, inputs: &[&str], expected: &[&str]) {
let result = anagram::anagrams_for(word, inputs);
let expected: HashSet<&str> = expected.iter().cloned().collect();
assert_eq!(result, expected);
}
#[test]
fn test_no_matches() {
let word = "diaper";
let inputs = ["hello", "world", "zombies", "pants"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_detect_simple_anagram() {
let word = "ant";
let inputs = ["tan", "stand", "at"];
let outputs = vec!["tan"];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_does_not_confuse_different_duplicates() {
let word = "galea";
let inputs = ["eagle"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_eliminate_anagram_subsets() {
let word = "good";
let inputs = ["dog", "goody"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_detect_anagram() {
let word = "listen";
let inputs = ["enlists", "google", "inlets", "banana"];
let outputs = vec!["inlets"];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_multiple_anagrams() {
let word = "allergy";
let inputs = [
"gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading",
];
let outputs = vec!["gallery", "regally", "largely"];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_case_insensitive_anagrams() {
let word = "Orchestra";
let inputs = ["cashregister", "Carthorse", "radishes"];
let outputs = vec!["Carthorse"];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_unicode_anagrams() {
let word = "ΑΒΓ";
// These words don't make sense, they're just greek letters cobbled together.
let inputs = ["ΒΓΑ", "ΒΓΔ", "γβα"];
let outputs = vec!["ΒΓΑ", "γβα"];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_misleading_unicode_anagrams() {
// Despite what a human might think these words contain different letters, the input uses Greek
// A and B while the list of potential anagrams uses Latin A and B.
let word = "ΑΒΓ";
let inputs = ["ABΓ"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_does_not_detect_a_word_as_its_own_anagram() {
let word = "banana";
let inputs = ["banana"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_does_not_detect_a_differently_cased_word_as_its_own_anagram() {
let word = "banana";
let inputs = ["bAnana"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_does_not_detect_a_differently_cased_unicode_word_as_its_own_anagram() {
let word = "ΑΒΓ";
let inputs = ["ΑΒγ"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_same_bytes_different_chars() {
let word = "a⬂"; // 61 E2 AC 82
let inputs = ["€a"]; // E2 82 AC 61
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
#[test]
#[ignore]
fn test_different_words_but_same_ascii_sum() {
let word = "bc";
let inputs = ["ad"];
let outputs = vec![];
process_anagram_case(word, &inputs, &outputs);
}
use std::collections::HashSet;
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&str]) -> HashSet<&'a str> {
unimplemented!(
"For the '{}' word find anagrams among the following words: {:?}",
word,
possible_anagrams
);
}
# Anagram
Welcome to Anagram on Exercism's Rust Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
An anagram is a rearrangement of letters to form a new word.
Given a word and a list of candidates, select the sublist of anagrams of the given word.
Given `"listen"` and a list of candidates like `"enlists" "google"
"inlets" "banana"` the program should return a list containing
`"inlets"`.
The solution is case insensitive, which means `"WOrd"` is the same as `"word"` or `"woRd"`. It may help to take a peek at the [std library](https://doc.rust-lang.org/std/primitive.char.html) for functions that can convert between them.
The solution cannot contain the input word. A word is always an anagram of itself, which means it is not an interesting result. Given `"hello"` and the list `["hello", "olleh"]` the answer is `["olleh"]`.
You are going to have to adjust the function signature provided in the stub in order for the lifetimes to work out properly. This is intentional: what's there demonstrates the basics of lifetime syntax, and what's missing teaches how to interpret lifetime-related compiler errors.
Try to limit case changes. Case changes are expensive in terms of time, so it's faster to minimize them.
If sorting, consider [sort_unstable](https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable) which is typically faster than stable sorting. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn't allocate auxiliary memory.
## Source
### Created by
- @EduardoBautista
### Contributed to by
- @andrewclarkson
- @ashleygwilliams
- @bobahop
- @chancancode
- @ClashTheBunny
- @coriolinus
- @cwhakes
- @Dimkar3000
- @EduardoBautista
- @efx
- @ErikSchierboom
- @gris
- @IanWhitney
- @kytrinyx
- @lutostag
- @mkantor
- @nfiles
- @petertseng
- @pminten
- @quartsize
- @rofrol
- @stevejb71
- @stringparser
- @xakon
- @ZapAnton
### Based on
Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup
# Help
## Running the tests
Execute the tests with:
```bash
$ cargo test
```
All but the first test have been ignored. After you get the first test to
pass, open the tests source file which is located in the `tests` directory
and remove the `#[ignore]` flag from the next test and get the tests to pass
again. Each separate test is a function with `#[test]` flag above it.
Continue, until you pass every test.
If you wish to run _only ignored_ tests without editing the tests source file, use:
```bash
$ cargo test -- --ignored
```
If you are using Rust 1.51 or later, you can run _all_ tests with
```bash
$ cargo test -- --include-ignored
```
To run a specific test, for example `some_test`, you can use:
```bash
$ cargo test some_test
```
If the specific test is ignored, use:
```bash
$ cargo test some_test -- --ignored
```
To learn more about Rust tests refer to the online [test documentation][rust-tests].
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
## Submitting your solution
You can submit your solution using the `exercism submit src/lib.rs` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
## Rust Installation
Refer to the [exercism help page][help-page] for Rust installation and learning
resources.
## Submitting the solution
Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
## Feedback, Issues, Pull Requests
The GitHub [track repository][github] is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
If you want to know more about Exercism, take a look at the [contribution guide].
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
[help-page]: https://exercism.io/tracks/rust/learning
[github]: https://github.com/exercism/rust
[contribution guide]: https://exercism.io/docs/community/contributors
[package]
edition = "2018"
name = "anagram"
version = "0.0.0"
# Generated by Cargo
# will have compiled files and executables
/target/
**/*.rs.bk
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
{"track":"rust","exercise":"anagram","id":"e75a6a64b64f445db2baff950c154bf8","url":"https://exercism.org/tracks/rust/exercises/anagram","handle":"nicoty","is_requester":true,"auto_approve":false}
{
"blurb": "Given a word and a list of possible anagrams, select the correct sublist.",
"authors": [
"EduardoBautista"
],
"contributors": [
"andrewclarkson",
"ashleygwilliams",
"bobahop",
"chancancode",
"ClashTheBunny",
"coriolinus",
"cwhakes",
"Dimkar3000",
"EduardoBautista",
"efx",
"ErikSchierboom",
"gris",
"IanWhitney",
"kytrinyx",
"lutostag",
"mkantor",
"nfiles",
"petertseng",
"pminten",
"quartsize",
"rofrol",
"stevejb71",
"stringparser",
"xakon",
"ZapAnton"
],
"files": {
"solution": [
"src/lib.rs"
],
"test": [
"tests/anagram.rs"
],
"example": [
".meta/example.rs"
]
},
"source": "Inspired by the Extreme Startup game",
"source_url": "https://github.com/rchatley/extreme_startup"
}