Function names rename according to changes in exercises
This commit is contained in:
parent
5f56fb5713
commit
31b188a5e5
|
@ -12,7 +12,7 @@ enum class Result {
|
|||
DRAW, FIRST_WINS, SECOND_WINS
|
||||
}
|
||||
|
||||
fun findWinner(first: Rochambeau, second: Rochambeau): Result {
|
||||
fun winner(first: Rochambeau, second: Rochambeau): Result {
|
||||
if (first == second) return DRAW
|
||||
val winningCombinations = mapOf(
|
||||
ROCK to SCISSORS,
|
||||
|
@ -25,7 +25,7 @@ fun findWinner(first: Rochambeau, second: Rochambeau): Result {
|
|||
}
|
||||
|
||||
fun main() {
|
||||
findWinner(ROCK, SCISSORS) eq FIRST_WINS
|
||||
findWinner(SCISSORS, ROCK) eq SECOND_WINS
|
||||
findWinner(PAPER, PAPER) eq DRAW
|
||||
winner(ROCK, SCISSORS) eq FIRST_WINS
|
||||
winner(SCISSORS, ROCK) eq SECOND_WINS
|
||||
winner(PAPER, PAPER) eq DRAW
|
||||
}
|
|
@ -3,7 +3,7 @@ files:
|
|||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 305
|
||||
- offset: 301
|
||||
length: 224
|
||||
placeholder_text: TODO()
|
||||
- name: test/Tests.kt
|
||||
|
|
|
@ -12,7 +12,7 @@ import util.TIMEOUT
|
|||
class TestEnumerationsExercise3 {
|
||||
private fun checkResult(first: Rochambeau, second: Rochambeau, expected: Result) {
|
||||
Assert.assertEquals("Wrong answer for 'findWinner($first, $second)':",
|
||||
expected, findWinner(first, second))
|
||||
expected, winner(first, second))
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
|
|
|
@ -3,8 +3,8 @@ package whenExpressionsExercise1
|
|||
import atomictest.capture
|
||||
import atomictest.eq
|
||||
|
||||
fun getCloudinessDescription(cloudiness: Int): String =
|
||||
when (cloudiness) {
|
||||
fun cloudiness(cloudPercent: Int): String =
|
||||
when (cloudPercent) {
|
||||
in 81..100 -> "Sunny"
|
||||
in 61..80 -> "Mostly Sunny"
|
||||
in 41..60 -> "Partly Sunny"
|
||||
|
@ -15,12 +15,12 @@ fun getCloudinessDescription(cloudiness: Int): String =
|
|||
}
|
||||
|
||||
fun main() {
|
||||
getCloudinessDescription(100) eq "Sunny"
|
||||
getCloudinessDescription(70) eq "Mostly Sunny"
|
||||
getCloudinessDescription(50) eq "Partly Sunny"
|
||||
getCloudinessDescription(30) eq "Mostly Cloudy"
|
||||
getCloudinessDescription(0) eq "Cloudy"
|
||||
cloudiness(100) eq "Sunny"
|
||||
cloudiness(70) eq "Mostly Sunny"
|
||||
cloudiness(50) eq "Partly Sunny"
|
||||
cloudiness(30) eq "Mostly Cloudy"
|
||||
cloudiness(0) eq "Cloudy"
|
||||
capture {
|
||||
getCloudinessDescription(1000)
|
||||
cloudiness(1000)
|
||||
} eq "IllegalArgumentException: Cloudiness value should be between 0 and 100"
|
||||
}
|
|
@ -3,8 +3,8 @@ files:
|
|||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 140
|
||||
length: 269
|
||||
- offset: 128
|
||||
length: 271
|
||||
placeholder_text: TODO()
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
||||
|
|
|
@ -23,13 +23,13 @@ class TestWhenExpressionsExercise1 {
|
|||
fun test1CorrectValues() {
|
||||
for (cloudiness in 0..100) {
|
||||
Assert.assertEquals("Wrong result for cloudiness=$cloudiness:",
|
||||
expected(cloudiness), getCloudinessDescription(cloudiness))
|
||||
expected(cloudiness), cloudiness(cloudiness))
|
||||
}
|
||||
}
|
||||
|
||||
private fun testIncorrectValue(cloudiness: Int) {
|
||||
try {
|
||||
getCloudinessDescription(cloudiness)
|
||||
cloudiness(cloudiness)
|
||||
throw AssertionError("Expected an IllegalArgumentException for cloudiness=$cloudiness")
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
Assert.assertEquals("Incorrect error message", "Cloudiness value should be between 0 and 100", exception.message)
|
||||
|
|
|
@ -2,7 +2,7 @@ package whenExpressionsExercise2
|
|||
|
||||
import atomictest.eq
|
||||
|
||||
fun getTemperatureDescription(temperature: Int): String =
|
||||
fun temperature(temperature: Int): String =
|
||||
when {
|
||||
temperature >= 25 -> "Hot"
|
||||
temperature in 15..24 -> "Warm"
|
||||
|
@ -12,7 +12,7 @@ fun getTemperatureDescription(temperature: Int): String =
|
|||
}
|
||||
|
||||
fun main() {
|
||||
getTemperatureDescription(30) eq "Hot"
|
||||
getTemperatureDescription(10) eq "Cool"
|
||||
getTemperatureDescription(-30) eq "Freezing"
|
||||
temperature(30) eq "Hot"
|
||||
temperature(10) eq "Cool"
|
||||
temperature(-30) eq "Freezing"
|
||||
}
|
|
@ -3,7 +3,7 @@ files:
|
|||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 116
|
||||
- offset: 102
|
||||
length: 170
|
||||
placeholder_text: TODO()
|
||||
- name: test/Tests.kt
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestWhenExpressionsExercise2 {
|
|||
fun test() {
|
||||
for (temperature in -100..110) {
|
||||
Assert.assertEquals("Wrong value for temperature=$temperature",
|
||||
expected(temperature), getTemperatureDescription(temperature))
|
||||
expected(temperature), temperature(temperature))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package whenExpressionsExercise3
|
|||
|
||||
import atomictest.eq
|
||||
|
||||
fun isBalanced(input: String): Boolean {
|
||||
fun balanced(input: String): Boolean {
|
||||
var leftUnmatched = 0
|
||||
for (c in input) {
|
||||
when (c) {
|
||||
|
@ -19,6 +19,6 @@ fun isBalanced(input: String): Boolean {
|
|||
}
|
||||
|
||||
fun main() {
|
||||
isBalanced("(()) ()") eq true
|
||||
isBalanced(")(") eq false
|
||||
balanced("(()) ()") eq true
|
||||
balanced(")(") eq false
|
||||
}
|
|
@ -3,7 +3,7 @@ files:
|
|||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 99
|
||||
- offset: 97
|
||||
length: 337
|
||||
placeholder_text: TODO()
|
||||
- name: test/Tests.kt
|
||||
|
|
|
@ -9,7 +9,7 @@ import util.TIMEOUT
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
class TestWhenExpressionsExercise3 {
|
||||
private fun checkBalanced(s: String, expected: Boolean) {
|
||||
Assert.assertEquals("isBalanced($s) should return $expected", isBalanced(s), expected)
|
||||
Assert.assertEquals("isBalanced($s) should return $expected", balanced(s), expected)
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
|
@ -41,7 +41,7 @@ class TestWhenExpressionsExercise3 {
|
|||
|
||||
private fun checkWrongInput(s: String) {
|
||||
try {
|
||||
isBalanced(s)
|
||||
balanced(s)
|
||||
throw AssertionError("""IllegalArgumentException should be thrown for 'isBalanced("$s")'""")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
// ok
|
||||
|
|
Loading…
Reference in New Issue