evgenyigumnov / rustsn

Code snippets generator via LLMs and compiler/tester via build tools
GNU General Public License v3.0
18 stars 5 forks source link

Add Scala support #6

Closed evgenyigumnov closed 1 day ago

evgenyigumnov commented 2 days ago
  1. Create folder "scala"
  2. 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")
  }
}

Example install dependencies

sbt update

Example compile the project

sbt compile

Example run tests

sbt test