Create copies of "prompt.txt" in the "scala" folder
Launch example
rustsn --lang=scala
Example query:
take 2 params and add them and return result
Example generation:
build.sbt
name := "solution"
version := "0.1.0"
scalaVersion := "2.13.10"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % Test
src/main/scala/Solution.scala
object Solution {
def solution(a: Any, b: Any): Any = (a, b) match {
case (x: Int, y: Int) => x + y
case (x: String, y: Int) => x + y.toString
case (x: Int, y: String) => x.toString + y
case _ => throw new IllegalArgumentException("Unsupported types")
}
}
src/test/scala/SolutionTest.scala
import org.scalatest.funsuite.AnyFunSuite
class SolutionTest extends AnyFunSuite {
test("test1: adding two positive integers") {
assert(Solution.solution(1, 2) === 3)
}
test("test2: adding two negative integers") {
assert(Solution.solution(-1, -2) === -3)
}
test("test3: adding a string and an integer") {
assert(Solution.solution("1", 2) === "12")
}
}
Launch example
Example query:
Example generation:
build.sbt
src/main/scala/Solution.scala
src/test/scala/SolutionTest.scala
Example install dependencies
Example compile the project
Example run tests