Skip to content

two-fer: implementation of two-fer exercise in Kotlin #110

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

Merged
merged 6 commits into from Oct 13, 2017
Merged

two-fer: implementation of two-fer exercise in Kotlin #110

merged 6 commits into from Oct 13, 2017

Conversation

ghost
Copy link

@ghost ghost commented Oct 10, 2017

No description provided.

@ghost
Copy link
Author

ghost commented Oct 11, 2017

In Gitter it was recommended to me by @NobbZ to also change the hello-world exercise to be updated to the new style of hello-world, (which simply asks the user to return the string "hello world!"), instead of the current implementation that requires string manipulation. This then allows string manipulation to be introduced to the user via the two-fer exercise that is implemented in this PR.

@stkent stkent self-assigned this Oct 11, 2017
@stkent
Copy link
Contributor

stkent commented Oct 11, 2017

Hi! Thanks for this contribution!

I'll add review comments inline in a second, but I also wanted to post some information relevant to the hello-world update you are tackling. Here are the PRs where we updated hello-world in the Java track: exercism/java#663 and exercism/java#666. They should give you some pointers as to what updates may need to happen to supporting files in the Kotlin track. Feel free to reach out if you have any questions!

@@ -0,0 +1,10 @@
fun twofer(name: String = ""): String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we don't need to allow null input here, I'd say the closest interpretation of "no name given" would be invoking the twofer function with no parameter, a case that is currently not exercised by the tests. To implement that, we should probably update this signature to

fun twofer(name: String = "you"): String

and have this exercise focus on a more typical use of default parameter values. Then the first test should mimic https://github.com/exercism/java/blob/master/exercises/two-fer/src/test/java/TwoferTest.java#L16-L22 but with no parameter passed instead of a null parameter passed.

The Java track debated what to do with an empty string input, and settled on being very literal about handling it: exercism/java#733. I'd say the same boundary case could be exercised here, since invocation with no parameters is the "right way" to call this function without specifying a name. Any explicit input can therefore be interpreted as something the caller wants to display as the name (even if empty). Does that make sense to fresh eyes?

if(!matched)
tempName = "you"

return "One for $tempName, one for me."
Copy link
Contributor

Choose a reason for hiding this comment

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

In light of the above, this sample implementation can be reduced to a single line.

@@ -0,0 +1,24 @@
import org.junit.Ignore
import org.junit.Test
import org.junit.Assert.assertEquals
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note that https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/assert-equals.html is probably available - I assume it's a wrapper around the JUnit assertion anyway though!

Changed model answer to better suit tests
@ghost
Copy link
Author

ghost commented Oct 11, 2017

Hey @stkent, I believe my latest commit has completed your requested changes? If there is something I am missing or more changes required please let me know. Thanks! 👍

@stkent
Copy link
Contributor

stkent commented Oct 12, 2017

Looking at this tomorrow!

Copy link
Contributor

@stkent stkent left a comment

Choose a reason for hiding this comment

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

Just a few more minor changes requested, then LGTM!

@@ -0,0 +1,3 @@
fun twofer(name: String = "you"): String {
return "One for ${if (name.isBlank()) "you" else name}, one for me."
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be altered to

return "One for $name, one for me."

since supplying a blank string as input implies different intent to providing no input.

@Ignore
fun emptyStringGiven() {
assertEquals("One for you, one for me.", twofer(""))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's mimic the Java tests and (1) have the expected string here be "One for , one for me.", and (2) move this test to the end of the suite.

@Ignore
fun aNameGiven() {
assertEquals("One for Alice, one for me.", twofer("Alice"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this test should be moved above anotherNameGiven?

Copy link
Contributor

@stkent stkent left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for bearing with me through those change requests!

@stkent stkent merged commit 0b49aa7 into exercism:master Oct 13, 2017
@ghost ghost deleted the two-fer-patch branch October 13, 2017 12:34
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.

2 participants