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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@

]
},
{
"uuid": "fa4194c5-084d-f780-4db6-707ef7bcc30c00e9ee5",
"slug": "two-fer",
"core": false,
"unlocked_by": null,
"difficulty": 2,
"topics": [

]
},
{
"uuid": "9772c916-c619-445c-834d-af7dbf1ad2d9",
"slug": "rna-transcription",
Expand Down Expand Up @@ -633,3 +643,4 @@
],
"solution_pattern": "reference"
}

1 change: 1 addition & 0 deletions exercises/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ include 'strain'
include 'sublist'
include 'sum-of-multiples'
include 'triangle'
include 'two-fer'
include 'word-count'
3 changes: 3 additions & 0 deletions exercises/two-fer/.meta/src/reference/kotlin/Twofer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun twofer(name: String = "you"): String {
return "One for $name, one for me."
}
18 changes: 18 additions & 0 deletions exercises/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.

```text
"One for X, one for me."
```

When X is a name or "you".

If the given name is "Alice", the result should be "One for Alice, one for me."
If no name is given, the result should be "One for you, one for me."

## Instructions

Submissions are encouraged to be general, within reason. Having said that, it's
also important not to over-engineer a solution.

It's important to remember that the goal is to make code as expressive and
readable as we can.
28 changes: 28 additions & 0 deletions exercises/two-fer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'kotlin'

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
test {
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
}
}
Empty file.
31 changes: 31 additions & 0 deletions exercises/two-fer/src/test/kotlin/TwoferTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.junit.Ignore
import org.junit.Test
import kotlin.test.assertEquals


class TwoferTest {

@Test
fun noNameGiven() {
assertEquals("One for you, one for me.", twofer())
}

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

@Test
@Ignore
fun anotherNameGiven() {
assertEquals("One for Bob, one for me.", twofer("Bob"))
}

@Test
@Ignore
fun emptyStringGiven() {
assertEquals("One for , 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.

I believe this test should be moved above anotherNameGiven?


}