Pig Latin in Rust
Implement a program that translates from English to Pig Latin
exercism fetch rust pig-latin
Implement a program that translates from English to Pig Latin.
Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below), but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.
- Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay").
- Rule 2: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word. Consonant sounds can be made up of multiple consonants, a.k.a. a consonant cluster (e.g. "chair" -> "airchay").
- Rule 3: If a word starts with a consonant sound followed by "qu", move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay").
- Rule 4: If a word contains a "y" after a consonant cluster or as the second letter in a two letter word it makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay").
There are a few more rules for edge cases, and there are regional variants too.
See http://en.wikipedia.org/wiki/Pig_latin for more details.
Refer to the exercism help page for Rust installation and learning resources.
Writing the Code
Execute the tests with:
$ cargo test
All but the first test have been ignored. After you get the first test to
pass, open the tests source file wich is located in the
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 all tests without editing the tests source file, use:
$ cargo test -- --ignored
To run a specific test, for example
some_test, you can use:
$ cargo test some_test
If the specfic test is ignored use:
$ cargo test some_test -- --ignored
To learn more about Rust tests refer to the online test documentation
Make sure to read the Modules chapter if you haven't already, it will help you with organizing your files.
Feedback, Issues, Pull Requests
The exercism/rust repository on 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.
The Pig Latin exercise at Test First Teaching by Ultrasaurus https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/pig_latin/
Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.