Repository navigation
Pig-Latin Exercise Updates - #1249
Conversation
Updated tests. Could someone please double-check that this test class works as intended?
sjwarner-bp
left a comment
There was a problem hiding this comment.
Looks like the build is failing because one of the tests is failing:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':pig-latin:test'.
> There were failing tests. See the report at: file:///home/travis/build/exercism/java/exercises/pig-latin/build/reports/tests/test/index.html
It's the following test:
PigLatinTranslatorTest > test[19: expected "rhythm" to translate to the pig latin phrase "ythmrhay"] FAILED
org.junit.ComparisonFailure: expected:<[ythmrh]ay> but was:<[hythmr]ay>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at PigLatinTranslatorTest.test(PigLatinTranslatorTest.java:82)
The reference solution may need to be tweaked to allow this test to pass!
| {"yellow", "ellowyay"}, | ||
|
|
||
| // 'Y' is treated like a vowel at the end of a consonant cluster | ||
| {"rhythm", "ythmrhay"}, |
There was a problem hiding this comment.
So this line is why the build failed. Below is what is showed on the Travis Tests.
PigLatinTranslatorTest > test[19: expected "rhythm" to translate to the pig latin phrase "ythmrhay"] FAILED
org.junit.ComparisonFailure: expected:<[ythmrh]ay> but was:<[hythmr]ay>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at PigLatinTranslatorTest.test(PigLatinTranslatorTest.java:82)
Not sure why it failed though, because the the canonical-data lists exactly that as the test case. Maybe someone from @exercism can look into it more and find out why.
There was a problem hiding this comment.
As said above - just because the test is the correct test, doesn't mean the build will pass!
We also need the reference solution store in .meta to pass all of the tests as well. As we can see here, all of the tests pass apart from this one (probably because this 'y' is an edge case where it will be treated as a vowel after a consonant).
The current version of the reference solution gives us hythmray instead of ythmrhay!
As noted in the relevant issue #1249, I suggested the reference solution might need updating for this test suite.
It's also worth bearing in mind that the tests can be run locally before pushing to reduce your feedback cycle!
There was a problem hiding this comment.
Thanks @sjwarner-bp for the explanation, I was writing this comment at the same time you posted the one on the PR so I didn't see that one.
There was a problem hiding this comment.
Alright, thanks @sjwarner-bp and @c-thornton! I'll update it to "hythmray." How can I run the tests locally?
There was a problem hiding this comment.
@Kyle-P I remember @sjwarner-bp made a comment a while ago about it. I don't know who to link to it directly but it was in PR #1222. Basically you need to install gradle and run the tests locally. You can find some more information about how to set it up in the contributing guide found here.
https://github.com/exercism/java/blob/master/CONTRIBUTING.md#advanced-complete-local-setup
There was a problem hiding this comment.
Thansk @c-thornton! I'd rather keep things done online for personal reasons, but I definitely see how it's better to run tests locally. Would setting up TravisCI on my fork be a plausible option?
Build failed last time.
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking good @Kyle-P! One case is different from the canonical data so it needs to be updated 🙂
| {"yellow", "ellowyay"}, | ||
|
|
||
| // 'Y' is treated like a vowel at the end of a consonant cluster | ||
| {"rhythm", "hythmray"}, |
There was a problem hiding this comment.
This should map to "ythmrhay". If the build doesn't pass when you do that then you need to update the reference solution so that it maps it correctly. Does that make sense? 🙂
There was a problem hiding this comment.
Alright, thanks! Two questions:
- Is it feasible to set up the same TravisCI builds in my fork (I'd rather run the tests online than
locally)? - Does updating the reference solution mean changing the canonical data?
Thank you!
|
I'd say while it's possible to set up similar build processes on a fork, it might not be worth it - the feedback cycles will be pretty similar, so if you want to test online then I'd recommend leaving it as is! Updating the reference solution means to change the example stored in |
Fixed reference solution so words with "y" after a consonant cluster are taken care of properly.
Fix test to match correct reference solution.
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking really good @Kyle-P! Just a few minor comments 🙂
| .collect(Collectors.joining(" ")); | ||
| } | ||
|
|
||
| private static int yLocation; |
There was a problem hiding this comment.
Having a private variable which is set in one method and used in another like this makes the code a bit confusing to read. If you need to use this straight after having called hasYAfterConsonantCluster then you could just make the method return the yLocation (and rename it something like getLocationOfYAfterConsonantCluster)? And it can return -1 if there isn't one. What do you think? 🙂
There was a problem hiding this comment.
Great idea. I'll take care of it. Thanks!
| return word + AY; | ||
| } | ||
|
|
||
| if(hasYAfterConsonantCluster(word)){ |
There was a problem hiding this comment.
There should be white space after if and before {, like the other if statements already in this file 🙂
| } | ||
|
|
||
| private static boolean hasYAfterConsonantCluster(String word) { | ||
| for(int i = 0; i < word.length() - 1; i++){ |
There was a problem hiding this comment.
There should be white space after for and before {. And please try to keep the indentation consistent, everything should be indented with four spaces like the rest of the file 🙂
Made method more efficient and fixed up formatting
FridaTveit
left a comment
There was a problem hiding this comment.
Thanks for making these changes @Kyle-P! Just a couple more little changes needed 🙂
| } | ||
|
|
||
| if(hasYAfterConsonantCluster(word)){ | ||
| if (getLocationOfYAfterConsonantCluster(word) != -1) { |
There was a problem hiding this comment.
You need to store the result of this method call in a variable and use it inside the if statement. Right now the build is failing because you're using the variable yLocation which doesn't exist anymore 🙂
There was a problem hiding this comment.
Oops. Thanks for catching that one.
| for (int i = 0; i < word.length() - 1; i++) { | ||
| if (word.substring(i, i + 1).matches(VOWELS_REGEX)) { | ||
| return -1; | ||
| }else if ((i != 0) && word.substring(i, i + 1).equals("y")) { |
There was a problem hiding this comment.
There should be a white space before else 🙂 Also you could use word.charAt(i) in both the if and else statements (e.g. word.charAt(i) == 'y') instead of using substring, that might make it a bit more obvious what you're doing 🙂
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great, thanks @Kyle-P! 🙂
* Create version File for Pig-Latin Challenge * Update PigLatinTranslator.java Updated tests. Could someone please double-check that this test class works as intended? * Update PigLatin Tests Build failed last time. * Update PigLatinTranslator.java Fixed reference solution so words with "y" after a consonant cluster are taken care of properly. * Update PigLatinTranslatorTest.java Fix test to match correct reference solution. * Update PigLatinTranslator.java Made method more efficient and fixed up formatting * Update PigLatinTranslator.java * Fix Character and String Comparison
Updated Pig-Latin tests file and added a version file. Could someone please double-check that the test class works as intended? Thanks!
Closes #1140
Reviewer Resources:
Track Policies