Skip to content

Pig-Latin Exercise Updates - #1249

Merged
FridaTveit merged 8 commits into
exercism:masterfrom
Kyle-Pu:patch-1
Feb 7, 2018
Merged

FridaTveit merged 8 commits into
exercism:masterfrom
Kyle-Pu:patch-1

Conversation

@Kyle-Pu

@Kyle-Pu Kyle-Pu commented Jan 27, 2018 •

Copy link
Copy Markdown
Contributor

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

Updated tests.

Could someone please double-check that this test class works as intended?

@sjwarner-bp sjwarner-bp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@sjwarner-bp sjwarner-bp Jan 27, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, thanks @sjwarner-bp and @c-thornton! I'll update it to "hythmray." How can I run the tests locally?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, thanks! Two questions:

  1. Is it feasible to set up the same TravisCI builds in my fork (I'd rather run the tests online than
    locally)?
  2. Does updating the reference solution mean changing the canonical data?

Thank you!

@sjwarner-bp

Copy link
Copy Markdown
Contributor

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 .meta. Just imagine you were completing the exercise on exercism!

Fixed reference solution so words with "y" after a consonant cluster are taken care of properly.
Fix test to match correct reference solution.

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking really good @Kyle-P! Just a few minor comments 🙂

.collect(Collectors.joining(" "));
}

private static int yLocation;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great idea. I'll take care of it. Thanks!

return word + AY;
}

if(hasYAfterConsonantCluster(word)){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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++){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for making these changes @Kyle-P! Just a couple more little changes needed 🙂

}

if(hasYAfterConsonantCluster(word)){
if (getLocationOfYAfterConsonantCluster(word) != -1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, thanks @Kyle-P! 🙂

@FridaTveit
FridaTveit merged commit d46a18f into exercism:master Feb 7, 2018
@Kyle-Pu
Kyle-Pu deleted the patch-1 branch March 12, 2018 21:29
hgvanpariya pushed a commit to hgvanpariya/java that referenced this pull request May 13, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants