Add tests to pig-latin exercise

Hello everyone!

I am mentoring the F# track and regretfully have to say that students come with wrong solutions for pig-latin exercise due to the incomplete tests.

The tests I want to add are the following phrases:

"quick afternoon run"
" extraneous  space   "

If you agree, I will prepare the pull requests to the problem-specifications repo and to the tracks.

What are these proposed tests testing for?

Also please don’t prepare pull requests to the problem-specifications repo until we have a consensus among track maintainers participating in this thread that a PR is warranted. You won’t be expected to sync any problem-specifications changes to the 80+ Exercism tracks because that’s the responsibility of the track maintainers, and they can choose when and how they want to implement any upstream changes.

2 Likes

The proposed tests checks the following errors respectively:

  1. Words starting with vowels are processed the same way as words starting with consonants, or vice versa.

  2. Spaces are handled by splitting and then concatenating the words again rather than preserved.

  1. The canonical data already has inputs starting with vowels. What is new/different about your example?
  2. Are you assuming spaces should not be preserved? Is that necessarily correct behavior? Why?
1 Like

Hello, IsaacG!

That is right, canonical data have inputs starting with vowels, but only as separate words. This is why Examplar.fs manages to handle them while being incorrect.

I’m against the first test in its current form, and I’m unconvinced that we need to complicate this exercise with whitespace formatting.

For the first test, the existing test "quick fast run" already proves that a student’s solution can translate a phrase, not just a single word. Therefore, it’s earned its place even though the individual words are covered by previous rules. Adding "quick afternoon run" alongside that test needs to supplement that test, but it’s not adding much. I’d be more favorable of a test that reimplements the existing phase and uses a single word from each rule instead. Currently, the existing phrase test only uses the three of the four rules.

For the second test, Pig Latin is about word translation, not whitespace behavior. Given that this behavior isn’t previously defined in the instructions, " extraneous space " could just as equally be " extraneousay acespay " as "extraneousay acespay". Therefore I’m against this test since it distracts from word translation, the focus of the exercise

And I assume that spaces should be preserved, unlike in the student’s solutions that split and concatenate the words.

BNAndras, I agree that whitespace test do not have much value on its own, but it is important to put hold on students that are trying to remedy the solution that does not process vowels correctly by split + apply wrong solution to each word separately + concat trick

Can we examine that assumption? Is it necessarily correct? Is the opposite just as easily correct? What makes one approach more correct than the other? …and how relevant is that to this exercise?

Space-preserving behaviour is what you expect based on the canonical solution.

But that canonical solution, as well as many student’s solutions, breaks completely on phrases that contain words with vowels:

root@localhost:~# dotnet fsi

F# Interactive version 14.0.111.0 for F# 10.0

> #load "Example.fs";;
[Loading /root/Example.fs]
module FSI_0002.PigLatin
val vowelPattern: string
val consonantPattern: string
val vowelReplacement: string
val consonantReplacement: string
val translate: sentence: string -> string

> let t = PigLatin.translate;;
val t: (string -> string)

> t "quick fast run";;
val it: string = "ickquay astfay unray"

> t "quick afternoon run";;
val it: string = "quick afternoonay run"

> t " extraneous  space   ";;
val it: string = " extraneousay  space   "

Example solutions for practice exercises only prove that a test suite as currently written for a language can be solved for continuous integration purposes. I wouldn’t read too much into what one particular example solution is doing as a result. Some maintainers do prefer polished and idiomatic example solutions, but that’s in no way expected across the board as long as the test suite CI passes.

I do not suggest to change example solution, but the tests are not complete and they need to be refined.

Or you think that quick afternoonay run is the correct translation? One could expect ickquay afternoonay unray instead.

We could even add “quick afternoon run” as reimplementantation of “quick fast run” with explaination “‘quick fast run’ does not test when words starting with consonants and words starting with vowels are mixed together”

And then let maintainers decide. If they choose not to use reimplementantation, that is perfectly fine, but it is good to have options.

Would you mind explaining why it matters if a multi word solution has a middle word starting with a vowel? Most of the solutions I’ve seen split input into words and process each word. If they can handle the single word cases starting with vowels, the sentence version should behave the same. I’m not understanding what this change would accomplish.

1 Like

When the word in the middle starts with vowel, the “ickquay” and “unray” words turns into untranslated “quick” and “run” respectively.

This is why it matters.

We could replace the "quick fast run" test case with "my quick afternoon xray scan"

This covers all four rules, including two forms of the first rule. It also includes a starting consonant pattern that is not detected by solutions that may have been written for older versions of the instructions.

2 Likes

Could you explain why that might happen? If words are split and translated, I don’t see why middle words would be different than initial words. If middle words are not translated properly, why would words starting with a consonant be different from words starting with a vowel. You are stating they are different but I’m not hearing a why.

I think the F# example solution checks if the string contains any word satisfying rule 1. If so, only rule 1 is ever applied.

If words were split and translated independently, in all student solutions, the existing test case would suffice.

That seems like a pretty poor implementation if you’re checking all words to transform one word :eyes: