Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved output for simple_cipher test #2288

Merged

Conversation

anton-ptashnik
Copy link
Contributor

@anton-ptashnik anton-ptashnik commented Jul 7, 2022

Fixes

  • made tests to output all failed data examples instead of one only

Before

=== RUN   TestShift
    simple_cipher_test.go:58: Shift(3) Encode("Go, go, gophers") = "jrWjrWjrskhuv", want "jrjrjrskhuv".

Now

=== RUN   TestShift
    simple_cipher_test.go:58: Shift(3) Encode("Go, go, gophers") = "jrWjrWjrskhuv", want "jrjrjrskhuv".
    simple_cipher_test.go:58: Shift(3) Encode("I am a panda bear.") = "lWdpWdWsdqgdWehdu", want "ldpdsdqgdehdu".
    simple_cipher_test.go:58: Shift(3) Encode("Programming is AWESOME!") = "surjudpplqjWlvWdzhvrph", want "surjudpplqjlvdzhvrph". 
  • changed Encode test error log to contain an original string instead of the one with cleared extra symbols

Before

simple_cipher_test.go:26: Caesar Encode("todayisholiday") = "wrgdlvkrolgd", want "wrgdblvkrolgdb".

Now

simple_cipher_test.go:58: Caesar Encode("today is holiday") = "wrgdlvkrolgd", want "wrgdblvkrolgdb".

Related issue: #2098

- made tests to output all failed data examples instead of one only
- changed Encode test error log to contain an original string instead of the one with cleared extra symbols
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2022

Dear iAutomator

Thank you for contributing to the Go track on Exercism! 💙
You will see some automated feedback below 🤖. It would be great if you can make sure your PR covers those points. This will save your reviewer some time and your change can be merged quicker.

  • ⬆️ The instructions and test cases for many practice exercises originate in the Exercism-wide problem-specifications repo. If the exercise you changed is listed there in the exercises folder, please consider the following.

    • Improvements to the instructions.md file should be made in the problem-spec repo so that all tracks can benefit.
      You can open a PR there instead.
    • If you want to add some language specific information, use the instructions.append.md file (see Practice Exercise Docs).
    • Test cases selected in the .meta/tests.toml file need to be implemented in the <exercise>_test.go file according to the specification in canonical-data.json.
  • 🔗 If your PR fully fixes an issue, please include the text Fixes #issue_no in any line of the PR description. This will make the issue be automatically be closed when the PR is merged. If your PR is related to an existing issue but does not fix it completely, please link the issue anywhere in the description of the PR with #issue_no. You can read more about this in Github: Linking a pull request to an issue

  • ✍️ If your PR is not related to an existing issue (and is not self-explaining like a typo fix), please make sure the description explains why the change you made is necessary.

  • 🔤 If your PR fixes an easy to identify typo, if would be great if you could check for that typo in the whole repo. For example, if you found Unicdoe, use "replace all" in your editor (or command line magic) to fix it consistently.

Dear Reviewer/Maintainer

  • 📏 Make sure you set the appropriate x:size label for the PR. (This also works after merging, in case you forgot about it.)

  • 🔍 Don't be too nit-picky. If the PR is a clear improvement compared to the status quo, it should be approved as clear signal this is good to be merged even if the minor comments you might have are not addressed by the contributor. Further improvement ideas can be captured in issues (if important enough) and implemented via additional PRs.

  • 🤔 After reviewing the diff in the "Files changed" section, take a moment to think about whether there are changes missing from the diff. Does something need to be adjusted in other places so the code or content stays consistent?

Automated comment created by PR Commenter 🤖.

Copy link
Member

@andrerfcsantos andrerfcsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should show the output for the other failed tests, but let me suggest another way to do this.

Right now we are not using subtests for this exercise, and subtests can have calls to t.Fatalf in them, but still allow the other tests to run. We are in the process of converting the tests on the track to subtests, you can read more about this here: #2098

So my suggestion would be to convert the tests for this exercise into subtests, and keep the calls to t.Fatalf inside the subtests. This way we fix 2 issues at once :)

When doing subtests, the call to t.Run expects a "test name" as the first argument. Right now it seems we don't have descriptions attached to each test case. My suggestion would be to add a description field to the prepped and cipherTest structs and grab the descriptions for the tests from canonical-data.json. If there's a test that we have that is not present in that json file, feel free to write a small description for the test. If there are tests in the json file that we don't currently have, ignore those and we'll add them at a later date.

Let me know if you would you like to implement subtests for the tests of this exercise. I know this is a bigger ask than what you probably intended originally, so I totally get if you don't want to do this. But I truly believe this is the right way to fix this issue. If you make these changes, I'll make sure to size the PR accordingly so you get a little bit more rep for the extra work.

@anton-ptashnik
Copy link
Contributor Author

applied subtests so now output is as follows

PS C:\Users\iavto\Documents\exercism_tasks\go\simple-cipher> go test -v -run TestCaesar
=== RUN   TestCaesar
=== RUN   TestCaesar/no_extra_symbols
=== RUN   TestCaesar/no_extra_symbols/Encode(iamapandabear)
=== RUN   TestCaesar/no_extra_symbols/Decode(ldpdsdqgdehdu)
=== RUN   TestCaesar/no_extra_symbols/Encode(programmingisawesome)
=== RUN   TestCaesar/no_extra_symbols/Decode(surjudpplqjlvdzhvrph)
=== RUN   TestCaesar/no_extra_symbols/Encode(todayisholiday)
=== RUN   TestCaesar/no_extra_symbols/Decode(wrgdblvkrolgdb)
=== RUN   TestCaesar/no_extra_symbols/Encode(venividivici)
=== RUN   TestCaesar/no_extra_symbols/Decode(yhqlylglylfl)
=== RUN   TestCaesar/with_extra_symbols
=== RUN   TestCaesar/with_extra_symbols/Encode(Go,_go,_gophers)
    simple_cipher_test.go:46: Encode(Go, go, gophers): got "qqqqq", want "jrjrjrskhuv".
=== RUN   TestCaesar/with_extra_symbols/Decode(jrjrjrskhuv)
=== RUN   TestCaesar/with_extra_symbols/Encode(I_am_a_panda_bear.)
=== RUN   TestCaesar/with_extra_symbols/Decode(ldpdsdqgdehdu)
=== RUN   TestCaesar/with_extra_symbols/Encode(Programming_is_AWESOME!)
=== RUN   TestCaesar/with_extra_symbols/Decode(surjudpplqjlvdzhvrph)
=== RUN   TestCaesar/with_extra_symbols/Encode(today_is_holiday)
=== RUN   TestCaesar/with_extra_symbols/Decode(wrgdblvkrolgdb)
=== RUN   TestCaesar/with_extra_symbols/Encode(Twas_the_night_before_Christmas)
=== RUN   TestCaesar/with_extra_symbols/Decode(wzdvwkhqljkwehiruhfkulvwpdv)
=== RUN   TestCaesar/with_extra_symbols/Encode(_--_@#!)
=== RUN   TestCaesar/with_extra_symbols/Decode()
=== RUN   TestCaesar/with_extra_symbols/Encode()
=== RUN   TestCaesar/with_extra_symbols/Decode()#01
--- FAIL: TestCaesar (0.01s)
    --- PASS: TestCaesar/no_extra_symbols (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Encode(iamapandabear) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Decode(ldpdsdqgdehdu) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Encode(programmingisawesome) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Decode(surjudpplqjlvdzhvrph) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Encode(todayisholiday) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Decode(wrgdblvkrolgdb) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Encode(venividivici) (0.00s)
        --- PASS: TestCaesar/no_extra_symbols/Decode(yhqlylglylfl) (0.00s)
    --- FAIL: TestCaesar/with_extra_symbols (0.00s)
        --- FAIL: TestCaesar/with_extra_symbols/Encode(Go,_go,_gophers) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode(jrjrjrskhuv) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode(I_am_a_panda_bear.) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode(ldpdsdqgdehdu) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode(Programming_is_AWESOME!) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode(surjudpplqjlvdzhvrph) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode(today_is_holiday) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode(wrgdblvkrolgdb) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode(Twas_the_night_before_Christmas) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode(wzdvwkhqljkwehiruhfkulvwpdv) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode(_--_@#!) (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode() (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Encode() (0.00s)
        --- PASS: TestCaesar/with_extra_symbols/Decode()#01 (0.00s)
PS C:\Users\iavto\Documents\exercism_tasks\go\simple-cipher> go test -v -run TestShift 
=== RUN   TestShift
=== RUN   TestShift/key=3
=== RUN   TestShift/key=3/Encode(Go,_go,_gophers)
    simple_cipher_test.go:46: Encode(Go, go, gophers): got "qqqqq", want "jrjrjrskhuv".
=== RUN   TestShift/key=3/Decode(jrjrjrskhuv)
=== RUN   TestShift/key=3/Encode(I_am_a_panda_bear.)
=== RUN   TestShift/key=3/Decode(ldpdsdqgdehdu)
=== RUN   TestShift/key=3/Encode(Programming_is_AWESOME!)
=== RUN   TestShift/key=3/Decode(surjudpplqjlvdzhvrph)
=== RUN   TestShift/key=3/Encode(today_is_holiday)
=== RUN   TestShift/key=3/Decode(wrgdblvkrolgdb)
=== RUN   TestShift/key=3/Encode(Twas_the_night_before_Christmas)
=== RUN   TestShift/key=3/Decode(wzdvwkhqljkwehiruhfkulvwpdv)
=== RUN   TestShift/key=3/Encode(_--_@#!)
=== RUN   TestShift/key=3/Decode()
=== RUN   TestShift/key=3/Encode()
=== RUN   TestShift/key=3/Decode()#01
=== RUN   TestShift/key=-3
=== RUN   TestShift/key=-3/Encode(THE_ENEMY_IS_NEAR)
=== RUN   TestShift/key=-3/Decode(qebbkbjvfpkbxo)
=== RUN   TestShift/key=-3/Encode(SPIES_SEND_SECRET_MESSAGES)
=== RUN   TestShift/key=-3/Decode(pmfbppbkapbzobqjbppxdbp)
=== RUN   TestShift/key=-3/Encode(THOMAS_JEFFERSON_DESIGNED_A_SUBSTITUTION_CIPHER)
=== RUN   TestShift/key=-3/Decode(qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo)
=== RUN   TestShift/key=-3/Encode(the_quick_brown_fox_jumps_over_the_lazy_dog)
=== RUN   TestShift/key=-3/Decode(qebnrfzhyoltkclugrjmplsboqebixwvald)
--- FAIL: TestShift (0.01s)
    --- FAIL: TestShift/key=3 (0.00s)
        --- FAIL: TestShift/key=3/Encode(Go,_go,_gophers) (0.00s)
        --- PASS: TestShift/key=3/Decode(jrjrjrskhuv) (0.00s)
        --- PASS: TestShift/key=3/Encode(I_am_a_panda_bear.) (0.00s)
        --- PASS: TestShift/key=3/Decode(ldpdsdqgdehdu) (0.00s)
        --- PASS: TestShift/key=3/Encode(Programming_is_AWESOME!) (0.00s)
        --- PASS: TestShift/key=3/Decode(surjudpplqjlvdzhvrph) (0.00s)
        --- PASS: TestShift/key=3/Encode(today_is_holiday) (0.00s)
        --- PASS: TestShift/key=3/Decode(wrgdblvkrolgdb) (0.00s)
        --- PASS: TestShift/key=3/Encode(Twas_the_night_before_Christmas) (0.00s)
        --- PASS: TestShift/key=3/Decode(wzdvwkhqljkwehiruhfkulvwpdv) (0.00s)
        --- PASS: TestShift/key=3/Encode(_--_@#!) (0.00s)
        --- PASS: TestShift/key=3/Decode() (0.00s)
        --- PASS: TestShift/key=3/Encode() (0.00s)
        --- PASS: TestShift/key=3/Decode()#01 (0.00s)
    --- PASS: TestShift/key=-3 (0.00s)
        --- PASS: TestShift/key=-3/Encode(THE_ENEMY_IS_NEAR) (0.00s)
        --- PASS: TestShift/key=-3/Decode(qebbkbjvfpkbxo) (0.00s)
        --- PASS: TestShift/key=-3/Encode(SPIES_SEND_SECRET_MESSAGES) (0.00s)
        --- PASS: TestShift/key=-3/Decode(pmfbppbkapbzobqjbppxdbp) (0.00s)
        --- PASS: TestShift/key=-3/Encode(THOMAS_JEFFERSON_DESIGNED_A_SUBSTITUTION_CIPHER) (0.00s)
        --- PASS: TestShift/key=-3/Decode(qeljxpgbccboplkabpfdkbaxprypqfqrqflkzfmebo) (0.00s)
        --- PASS: TestShift/key=-3/Encode(the_quick_brown_fox_jumps_over_the_lazy_dog) (0.00s)
        --- PASS: TestShift/key=-3/Decode(qebnrfzhyoltkclugrjmplsboqebixwvald) (0.00s)
PS C:\Users\iavto\Documents\exercism_tasks\go\simple-cipher> go test -v -run TestVig  
=== RUN   TestVigenere
=== RUN   TestVigenere/key=lemon
=== RUN   TestVigenere/key=lemon/Encode(ATTACKATDAWN)
=== RUN   TestVigenere/key=lemon/Decode(lxfopvefrnhr)
=== RUN   TestVigenere/key=abcdefghij
=== RUN   TestVigenere/key=abcdefghij/Encode(aaaaaaaaaa)
=== RUN   TestVigenere/key=abcdefghij/Decode(abcdefghij)
=== RUN   TestVigenere/key=abcdefghij/Encode(zzzzzzzzzz)
=== RUN   TestVigenere/key=abcdefghij/Decode(zabcdefghi)
=== RUN   TestVigenere/key=iamapandabear
=== RUN   TestVigenere/key=iamapandabear/Encode(I_am_a_panda_bear.)
=== RUN   TestVigenere/key=iamapandabear/Decode(qayaeaagaciai)
=== RUN   TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu
=== RUN   TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu/Encode(Diffie_Hellman)
=== RUN   TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu/Decode(gccwkixcltycv)
=== RUN   TestVigenere/key=qgbvno
=== RUN   TestVigenere/key=qgbvno/Encode(cof-FEE,_123!)
=== RUN   TestVigenere/key=qgbvno/Decode(sugars)
--- PASS: TestVigenere (0.01s)
    --- PASS: TestVigenere/key=lemon (0.00s)
        --- PASS: TestVigenere/key=lemon/Encode(ATTACKATDAWN) (0.00s)
        --- PASS: TestVigenere/key=lemon/Decode(lxfopvefrnhr) (0.00s)
    --- PASS: TestVigenere/key=abcdefghij (0.00s)
        --- PASS: TestVigenere/key=abcdefghij/Encode(aaaaaaaaaa) (0.00s)
        --- PASS: TestVigenere/key=abcdefghij/Decode(abcdefghij) (0.00s)
        --- PASS: TestVigenere/key=abcdefghij/Encode(zzzzzzzzzz) (0.00s)
        --- PASS: TestVigenere/key=abcdefghij/Decode(zabcdefghi) (0.00s)
    --- PASS: TestVigenere/key=iamapandabear (0.00s)
        --- PASS: TestVigenere/key=iamapandabear/Encode(I_am_a_panda_bear.) (0.00s)
        --- PASS: TestVigenere/key=iamapandabear/Decode(qayaeaagaciai) (0.00s)
    --- PASS: TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu (0.00s)
        --- PASS: TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu/Encode(Diffie_Hellman) (0.00s)
        --- PASS: TestVigenere/key=duxrceqyaimciuucnelkeoxjhdyduu/Decode(gccwkixcltycv) (0.00s)
    --- PASS: TestVigenere/key=qgbvno (0.00s)
        --- PASS: TestVigenere/key=qgbvno/Encode(cof-FEE,_123!) (0.00s)
        --- PASS: TestVigenere/key=qgbvno/Decode(sugars) (0.00s)
=== RUN   TestVigenereWrongKey
--- PASS: TestVigenereWrongKey (0.00s)

@anton-ptashnik
Copy link
Contributor Author

additionally, dedicated separate tests for checking wrong cipher keys:

  • TestVigenereWrongKey
  • TestWrongShiftKey

Copy link
Member

@andrerfcsantos andrerfcsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@andrerfcsantos andrerfcsantos merged commit a5f8400 into exercism:main Jul 10, 2022
@andrerfcsantos andrerfcsantos added the x:rep/medium Medium amount of reputation label Jul 10, 2022
@anton-ptashnik anton-ptashnik deleted the improve-simple-cipher-test-output branch July 10, 2022 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:rep/medium Medium amount of reputation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants