Skip to content

Incomplete tests for pig-latin exercise allows to apply one pattern to all words in phrase #2696

Closed

Description

@Aksima

Introduction

While mentioning a student's solution, I noticed that his/her solution makes a wrong assumption that phrase always consists of words with the same type (all words starting with consonants or all words starting with vowels).

Then I tried to lead student towards a canonical solution, but to my suprise, the canonical solution have the same bug. And despite of bug, both solutions (canonical and student's) pass all tests in suite.

Why this happened

Almost all tests in the suite tests a single word (for which the incorrect assumption that phrase always contains words of one type always holds). Due to the unfortunate decision the only test that contains several words contain only words of the same type, too (the ones starting with consonants).

Steps to reproduce the issue

Below are the steps to reproduce the issue with the problematic test quick fast run.
Note that this test contain only words starting with consonants.

  1. Write an Example.fs file with following content:
module PigLatin
open System.Text.RegularExpressions
let vowelPattern = @"(?<begin>^|\s+)(?<vowel>a|e|i|o|u|yt|xr)(?<rest>\w+)"
let consonantPattern = @"(?<begin>^|\s+)(?<consonant>ch|qu|thr|th|rh|sch|yt|\wqu|\w)(?<rest>\w+)"
let vowelReplacement = "${begin}${vowel}${rest}ay";
let consonantReplacement = "${begin}${rest}${consonant}ay";
let translate (sentence: string) = 
    if Regex.IsMatch(sentence, vowelPattern) then
        Regex.Replace(sentence, vowelPattern, vowelReplacement)
    else
        Regex.Replace(sentence, consonantPattern, consonantReplacement)
  1. Load it into interactive shell:
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
  1. Test the solution on original test and on any phrase with words of mixed type:
> PigLatin.translate "quick fast run";;
val it: string = "ickquay astfay unray"

> PigLatin.translate "quick afternoon run";;
val it: string = "quick afternoonay run"

You will notice that it uses consonants pattern for all words in the first test (and this works here - lucky!), and vowel pattern for all words in the second test (which is incorrect, because only one word start with vowel, not all of them).

A proposal

To help students catch the bug, a test is proposed which contains not only words starting with consonants, but a mix of words of different types. This helps to ensure that the decision for each word is taken individually, not like one pattern is applied to all words.

The proposed variants:

  1. original suggestion:
"quick afternoon run"
  1. keraville's variant
"my quick afternoon xray scan"
  1. glennj's variant
"why do squids enjoy xrays"

Activity

  1. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    Hello. Thanks for opening an issue on Exercism 🙂

    At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

    This issue will be automatically closed. Please use this link to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

    If you're interested in learning more about this auto-responder, please read this blog post.

  2. reopened this on Nov 2, 2026
  3. IsaacG commented on Nov 2, 2026

    @IsaacG
    Member

    Please clean up the commit message. It should explain what is changing and briefly why. You can link to the forum for context, but should not include a whole story in the commit. Please review prior commits to see what a commit message typically looks like.

  4. IsaacG commented on Nov 2, 2026

    @IsaacG
    Member

    And please don't use AI to rewrite it. Spend a minute and summarize the change yourself. It's a good skill to practice, and it shows respect for the time of everyone reading it.

  5. Aksima commented on Nov 2, 2026

    @Aksima
    ContributorAuthor

    I want to be respectful to the readers, so I go and study prior commits to decide on how commit message should look like.

  6. Aksima commented on Nov 2, 2026

    @Aksima
    ContributorAuthor

    The current commit message is:

    Add a test to pig-latin exercise that reimplements test with whole phrase (uuid 44616581-5ce3-4a81-82d0-40c7ab13d2cf)

    Examples of previous commits are:

    One commit:

    [resistor-color-tolerance] Correct tolerance in expected output: grey is 0.05% tolerance

    • [resistor-color-tolerance] Correct tolerance in expected output: grey is 0.05% tolerance
    • Add the reimplements key
    • Reorder keys

    Another commit:

    state-of-tic-tac-toe: Add test cases for playing after a win
    Add two new canonical test cases to verify that an error is thrown
    when a player makes a move after the game has already been won:

    • O kept playing after X wins
    • X kept playing after O wins

    After studying previous commits, I plan to modify my commit message to:

    [pig-latin] Add test case for catching an invalid assumption that all words in a phrase are of same type. A discussion of new test case is here: https://forum.exercism.org/t/add-tests-to-pig-latin-exercise/95998/36

    • Add new canonical test to verify that student's program analyses and processes each word individually, without trying to apply a single pattern to all words
    • Add the reimplements key
    • Add the comments key with brief description of reason behind introduction of new test

    What do you think?

  7. IsaacG commented on Nov 2, 2026

    @IsaacG
    Member

    Did you write that or did AI write that?

  8. Aksima commented on Nov 2, 2026

    @Aksima
    ContributorAuthor

    I wrote it by my own, since I am an author of pull request and prefer to explain it by myself, even if AI can write better commit message.

    And I really want to learn, so don't hesitate to point to my mistakes, if any.

  9. IsaacG commented on Nov 2, 2026

    @IsaacG
    Member

    [pig-latin] Add test case for catching an invalid assumption that all words in a phrase are of same type. A discussion of new test case is here: https://forum.exercism.org/t/add-tests-to-pig-latin-exercise/95998/36

    • Add new canonical test to verify that student's program analyses and processes each word individually, without trying to apply a single pattern to all words
    • Add the reimplements key
    • Add the comments key with brief description of reason behind introduction of new test

    This is a good start.

    • The first line of a commit is the summary line. The first sentence looks like a good summary. The second sentence with the forum link should not be in the summary -- it should be in the body after the blank line.
    • You can (and should) use markdown. A discussion of new test case is here: https://forum.exercism.org/t/add-tests-to-pig-latin-exercise/95998/36 can be simplified to [See forum discussion](https://forum.exercism.org/t/add-tests-to-pig-latin-exercise/95998/)
    • There's no need to mention the reimplements or comments in the commit message. People can see what is added by looking at the code. The commit should explain, at a high level, what changed and why. It should not repeat what is in the code.
  10. Aksima commented on Nov 3, 2026

    @Aksima
    ContributorAuthor

    Updated message accordingly:

    [pig-latin] Add test case for catching an invalid assumption that all words in a phrase are of same type.

    See forum discussion

    • Add new canonical test to verify that student's program analyses and processes each word individually, without trying to apply a single pattern to all words
  11. IsaacG commented on Nov 3, 2026

    @IsaacG
    Member

    That looks much better! The bullet isn't needed on the last line as there's only one entry. Otherwise, that looks great.

  12. Aksima commented on Nov 3, 2026

    @Aksima
    ContributorAuthor

    Managed to modify the commit message not only in discussion, but in pull request too.

  13. IsaacG commented on Nov 3, 2026

    @IsaacG
    Member

    @Aksima I still see the old message at #2697

  14. Aksima commented on Nov 3, 2026

    @Aksima
    ContributorAuthor

    I probably made some mistake and the change is not complete. But first of all, how can I reproduce the issue? Since it shows new commit message at given link.

  15. IsaacG commented on Nov 3, 2026

    @IsaacG
    Member

    17. I probably made some mistake and the change is not complete. But first of all, how can I reproduce the issue? Since it shows new commit message at given link.

    Image

    Click the pencil icon next to the title to edit the title.

    Click the ... and Edit to edit the description.

  16. Aksima commented on Nov 3, 2026

    @Aksima
    ContributorAuthor

    Successfully copied text from commits tab to conservation tab

  17. IsaacG commented on Nov 3, 2026

    @IsaacG
    Member

    Nicely done! Thank you for your patience. PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions