Skip to content

Commit

Permalink
Batch update
Browse files Browse the repository at this point in the history
  • Loading branch information
sierikov committed Jan 24, 2024
1 parent 0467b49 commit 90e2dd1
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 55 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ Stores my solutions to kata problems listed on [Codewars](https://www.codewars.c
[List Filtering](https://www.codewars.com/kata/53dbd5315a3c69eed20002dd),
[Regex validate PIN code](https://www.codewars.com/kata/55f8a9c06c018a0d6e000132),
[Sum of odd numbers](https://www.codewars.com/kata/55fd2d567d94ac3bc9000064),
[Highest and Lowest](https://www.codewars.com/kata/554b4ac871d6813a03000035),

### 8 kuy

[Vaporcode](https://www.codewars.com/kata/5966eeb31b229e44eb00007a),
[Counting sheep](https://www.codewars.com/kata/54edbc7200b811e956000556),
[Lario and Muigi Pipe Problem](https://www.codewars.com/kata/56b29582461215098d00000f),
[Century From Year](https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097),
[Convert a Number to a String!](https://www.codewars.com/kata/5265326f5fda8eb1160004c8/train/scala),
[Return Negative](https://www.codewars.com/kata/55685cd7ad70877c23000102),
[Sum of Positive](https://www.codewars.com/kata/5715eaedb436cf5606000381)
8 changes: 8 additions & 0 deletions src/main/scala/sierikov/codewars/kyu7/HighestAndLowest.scala
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}"
}
}
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
}
5 changes: 5 additions & 0 deletions src/main/scala/sierikov/codewars/kyu8/ReturnNegative.scala
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
}
5 changes: 5 additions & 0 deletions src/main/scala/sierikov/codewars/kyu8/SumOfPositive.scala
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
}
94 changes: 47 additions & 47 deletions src/test/scala/sierikov/codewars/kyu5/LunarDrillSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sierikov.codewars.kyu5
import sierikov.codewars.kyu5.LunarDrill.drill

class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
"Mechanics Tests: Drill Type Detection" should "pass" in {
"Mechanics Tests" should "detect drill" in {
val testCases = List(
(0, "´`:->............"),
(0, "´`:-->..........."),
Expand All @@ -18,16 +18,16 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
(0, "´`:==>>.........."),
(0,
"""´`:->............
´`:-->...........
´`:--->..........
´`:=>............
´`:==>...........
´`:===>..........
´`:->>...........
´`:-->>..........
´`:->>>..........
´`:=>>...........
´`:==>>.........."""
|´`:-->...........
|´`:--->..........
|´`:=>............
|´`:==>...........
|´`:===>..........
|´`:->>...........
|´`:-->>..........
|´`:->>>..........
|´`:=>>...........
|´`:==>>..........""".stripMargin
)
)

Expand All @@ -36,7 +36,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Regular Speed" should "pass" in {
it should "move with regular speed" in {
val testCases = List(
(1, "´`:->*..........."),
(2, "´`:->.*.........."),
Expand Down Expand Up @@ -65,7 +65,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Double Speed" should "pass" in {
it should "move with double speed" in {
val testCases = List(
(1, "´`:->>*.........."),
(2, "´`:->>.*........."),
Expand Down Expand Up @@ -94,7 +94,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Double Power" should "pass" in {
it should "detect double power" in {
val testCases = List(
(1, "´`:=>*..........."),
(2, "´`:=>.*.........."),
Expand Down Expand Up @@ -123,7 +123,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Triple Speed" should "pass" in {
it should "move with tripple speed" in {
val testCases = List(
(1, "´`:->>>*........."),
(2, "´`:->>>.*........"),
Expand Down Expand Up @@ -152,7 +152,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Double Speed - Double Power" should "pass" in {
it should "move with double speed and double power" in {
val testCases = List(
(1, "´`:=>>*.........."),
(2, "´`:=>>.*........."),
Expand Down Expand Up @@ -181,38 +181,38 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Mechanics Tests: Multiple Arms" should "pass" in {
it should "operate with multiple arms" in {
val testCases = List(
(1,
"""´`:->*...........
´`:-->*.........."""
|´`:-->*..........""".stripMargin
),
(4,
"""´`:->@...........
´`:=>@..........."""
|´`:=>@...........""".stripMargin
),
(2,
"""´`:->x...........
´`:=>@..........."""
|´`:=>@...........""".stripMargin
),
(4,
"""´`:->*x..........
´`:->>>@........."""
|´`:->>>@.........""".stripMargin
),
(8,
"""´`:===>@@@.......
´`:->>>..***.....
´`:-->>..xxx....."""
|´`:->>>..***.....
|´`:-->>..xxx.....""".stripMargin
),
(9,
"""´`:===>@@@.......
´`:->>>...***....
´`:-->>...xxx...."""
|´`:->>>...***....
|´`:-->>...xxx....""".stripMargin
),
(10,
"""´`:===>@@@.......
´`:->>>...***....
´`:-->>...xxX...."""
|´`:->>>...***....
|´`:-->>...xxX....""".stripMargin
)
)

Expand All @@ -221,7 +221,7 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Sample Tests: Drillatronino" should "pass" in {
"Drilatronio" should "pass test field" in {
val testCases = List(
(12, "´`:->..**..**..**.."),
(12, "´`:->>..**..**..**."),
Expand All @@ -245,46 +245,46 @@ class LunarDrillSuite extends org.scalatest.flatspec.AnyFlatSpec {
}
}

"Sample Tests: Drillatron" should "pass" in {
it should "pass stress field" in {
val testCases = List(
(41,
"""´`:->...xxxx..****..****..****....
´`:->...****..xxxx..****..****....
´`:->...****..****..xxxx..****....
´`:->...****..****..****..xxxx...."""
|´`:->...****..xxxx..****..****....
|´`:->...****..****..xxxx..****....
|´`:->...****..****..****..xxxx....""".stripMargin
),
(49,
"""´`:->...XXXX..****..****..****....
´`:=>...****..XXXX..****..****....
´`:=>...****..****..XXXX..****....
´`:->...****..****..****..XXXX...."""
|´`:=>...****..XXXX..****..****....
|´`:=>...****..****..XXXX..****....
|´`:->...****..****..****..XXXX....""".stripMargin
),
(32,
"""´`:->>>.@@@@..****..****..****....
´`:=>>..****..@@@@..****..****....
´`:=>>..****..****..@@@@..****....
´`:->>>.****..****..****..@@@@...."""
|´`:=>>..****..@@@@..****..****....
|´`:=>>..****..****..@@@@..****....
|´`:->>>.****..****..****..@@@@....""".stripMargin
),
(32,
"""´`:->...**..xx..XX..@@..
´`:->>..**..xx..XX..@@..
´`:->>>.**..xx..XX..@@.."""
|´`:->>..**..xx..XX..@@..
|´`:->>>.**..xx..XX..@@..""".stripMargin
),
(46,
"""´`:->...x**xx***xx****x.************
´`:->>>.***@xx@@X@.*@@*..@@@XXXxx@.."""
|´`:->>>.***@xx@@X@.*@@*..@@@XXXxx@..""".stripMargin
),
(36,
"""´`:--->***XXX**xx..**xx.xx
´`:-->>>.xx.XX@@@@.***....
´`:===>.X.@@@..XXXX**xxx*.
´`:=>>.xxX..@@.XX**...xxx."""
|´`:-->>>.xx.XX@@@@.***....
|´`:===>.X.@@@..XXXX**xxx*.
|´`:=>>.xxX..@@.XX**...xxx.""".stripMargin
),
(32,
"""´`:========>>XXX**xx.....
´`:->>>.xx.XX@@@@.***....
´`:-->>...@@@..XXXX*****.
´`:=>...xxX..@@.XXXXxxxxx"""
|´`:->>>.xx.XX@@@@.***....
|´`:-->>...@@@..XXXX*****.
|´`:=>...xxX..@@.XXXXxxxxx""".stripMargin
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ class PlayingWithPassphrasesSpec extends AnyFlatSpec {
import PlayingWithPassphrases._

it should "pass basic tests" in {
check("This is a test!", 1, "hsi etTi sats!")
check("This is a test!", 2, "s eT ashi tist!")
check("The quick brown fox jumps over the lazy dog.", 3, "hk oux Cpcn tipq hw 8x bml 1j9 fkh yq 9p")
check("MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015", 2, "4897 NkTrC Hq fT67 GjV Pq aP OqTh gOcE CoPcTi aO")
}

it should "pass additional tests" in {
check("HELLO WORLD", 1, "EmSpX PmMfI")
check("1234567890", 3, "9012345678")
check("THIS IS A TEST", 4, "xWiX E Wm wMlX")
check("PASSWORD123", 5, "678iWtBxXfU")
check("ABCDEF", 6, "lKjIhG")
}

private def check(s: String, n: Int, expect: String): Unit =
assertResult(playPass(s, n), s"playPass($s, $n)") {
expect
assertResult(expect, s"playPass($s, $n)") {
playPass(s, n)
}

}
21 changes: 21 additions & 0 deletions src/test/scala/sierikov/codewars/kyu7/HighestAndLowestSpec.scala
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
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ValidParenthesesSpec extends AnyFlatSpec {
assertResult(expected, s"\nInput: braces = $input")(validParentheses(input))
}

"Valid parentheses" should "return true" in {
it should "return true on valid parentheses" in {
exec(
Seq(
("()", true),
Expand All @@ -23,7 +23,7 @@ class ValidParenthesesSpec extends AnyFlatSpec {
)
}

"Unbalanced parentheses" should "return false" in {
it should "return false on unbalanced parenthese" in {
exec(
Seq(
(")(", false),
Expand All @@ -36,7 +36,7 @@ class ValidParenthesesSpec extends AnyFlatSpec {
)
}

"Empty string" should "return true" in {
it should "return true for empty" in {
exec(Seq(("", true)))
}
}
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 src/test/scala/sierikov/codewars/kyu8/ReturnNegativeSpec.scala
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 src/test/scala/sierikov/codewars/kyu8/SumOfPositiveSpec.scala
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
}
}

}

0 comments on commit 90e2dd1

Please sign in to comment.