-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
179 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
object HighestAndLowest { | ||
def highAndLow(numbers: String): String = { | ||
val numbersList = numbers.split(" ").map(_.toInt) | ||
s"${numbersList.max} ${numbersList.min}" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/scala/sierikov/codewars/kyu8/ConvertNumberToString.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
object ConvertNumberToString { | ||
def numberToString(n: Int): String = n.toString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
object ReturnNegative { | ||
def makeNegative(n: Int): Int = if (n < 0) n else n * -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
object SumOfPositive { | ||
def positiveSum(arr: Array[Int]): Int = arr.filter(_ > 0).sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/test/scala/sierikov/codewars/kyu7/HighestAndLowestSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sierikov.codewars.kyu7 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldEqual | ||
|
||
class HighestAndLowestSpec extends AnyFlatSpec { | ||
import HighestAndLowest._ | ||
|
||
val testCases = List( | ||
("1 2 3 4 5", "5 1"), | ||
("1 2 -3 4 5", "5 -3"), | ||
("1 9 3 4 -5", "9 -5") | ||
) | ||
|
||
it should "return highest and lowest numbers" in { | ||
testCases.map { case (numbers, expected) => | ||
highAndLow(numbers) shouldEqual expected | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/scala/sierikov/codewars/kyu8/ConvertNumberToStringSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldEqual | ||
|
||
class ConvertNumberToStringSpec extends AnyFlatSpec { | ||
|
||
import ConvertNumberToString._ | ||
|
||
val testCases = List( | ||
(7, "7"), | ||
(42, "42"), | ||
(0, "0"), | ||
(-13, "-13"), | ||
(123, "123"), | ||
(999, "999") | ||
) | ||
|
||
it should "convert numbers to strings" in { | ||
testCases.map { case (number, expected) => | ||
numberToString(number) shouldEqual expected | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/scala/sierikov/codewars/kyu8/ReturnNegativeSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldEqual | ||
|
||
class ReturnNegativeSpec extends AnyFlatSpec { | ||
|
||
import ReturnNegative._ | ||
|
||
val testCases = List( | ||
(42, -42), | ||
(0, 0), | ||
(1, -1), | ||
(-1, -1) | ||
) | ||
|
||
it should "return negative numbers" in { | ||
testCases.map { case (number, expected) => | ||
makeNegative(number) shouldEqual expected | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/scala/sierikov/codewars/kyu8/SumOfPositiveSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sierikov.codewars.kyu8 | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers.shouldEqual | ||
|
||
class SumOfPositiveSpec extends AnyFlatSpec { | ||
|
||
import SumOfPositive._ | ||
|
||
val testCases = List( | ||
(Array(2, 2), 4), | ||
(Array(1, -2, 3, 4, 5), 13), | ||
(Array(-1, -2, -3, -4, -5), 0) | ||
) | ||
|
||
it should "return negative numbers" in { | ||
testCases.map { case (arr, expected) => | ||
positiveSum(arr) shouldEqual expected | ||
} | ||
} | ||
|
||
} |