Incorrect Code passes on Pig Latin

Iteration 3 of the following solution:
https://exercism.org/tracks/rust/exercises/pig-latin/solutions/Iurig

Passes all current tests, but panics at runtime if there is a one letter word in the test. I propose the following test:

#[test]
#[ignore]
fn sentence_with_one_letter_word() {
    let input = "make me a strong x man";
    let output = translate(input);
    let expected = "akemay emay aay ongstray xay anmay";
    assert_eq!(output, expected);
}

Which fails iteration 3, passing iteration 4.

Is this proposed test exclusively for Rust or all 75+ Exercism tracks to benefit from?

I think other tracks would benefit from it? I’m not very experienced with many languages, but it seems like any solution that breaks into words and tries to check anything related to a 0 indexed “position 1” would break on single lettered words. Maybe other tracks would also benefit from single letter tests (not just words in an answer), which I would do like this:

#[test]
#[ignore]
fn one_letter_word() {
    let input = "a";
    let output = translate(input);
    let expected = "aay";
    assert_eq!(output, expected);
}

I can PR both in if deemed valuable.

1 Like

I think this would be useful for some tracks, and largely not harmful.

For Python or any language that has equivalent “startswith” and “endswith” string methods, a single codepoint string makes no difference. Neither does using regex. But if you are using indexes, or working under the assumption that “words” are always longer than 1, this could trip you up fairly quickly.

+1 from me for adding this one-letter word test as the first case to the ay is added to words that start with vowel group. The single-letter behavior mainly affects the first rule since the other rules affect words with multiple letters. The other sentence test doesn’t really add much and obscures the behavior we’re checking for.

Once we have some more more maintainers weigh in, we’ll decide if a problem-specs PR is warranted at that point and then explicitly request one. That’s generally when there’s at least three maintainers in favor of it in this thread.

Fair enough! I guess I framed it as a sentence because I also found it weird there is only one test that is a sentence. I’m not sure which “common mistake” having more would catch, it just seemed prudent to have more full sentence tests. This does feel like an “out of scope” question though, I could add more sentence tests in another PR, making sure to use words that trip multiple other tests, but for sure the most important thing is having a one letter word in there, and this second idea would need separate maintainer considerating to be PRed in.

I’ll be waiting for confirmation of both as separate questions in this thread.

The exercise structure with single words vs strings is a bit odd. But we don’t want to add more tests just to have more tests. If there isn’t a “gap” in the test coverage that a new test specifically addresses, we shouldn’t add the test just to have more. More isn’t always better.

1 Like

Yeah on second thought, my interest was that it would be nice as a first test. "A", "I", and "O" are the only single-letter words that come to mind though so this would be an edge case when considering individual words.

They’re more likely to occur alongside other words in a sentence, but if we test it in a sentence, we’re testing it indirectly at best. So yeah, I think I’m against both tests.