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 Java support #5

Closed evgenyigumnov closed 1 day ago

evgenyigumnov commented 2 days ago
  1. Create Folder "java"

    Create a new directory named java.

  2. Copy Files into "java" Folder

    Copy prompt.txt into the java folder.


Launch Example

rustsn --lang=java

Example Query

take 2 params and add them and return result

Example Generation

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>solution</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>

  <description>Minimalistic project</description>

  <properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <junit.version>5.9.0</junit.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Compiler Plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>

      <!-- Surefire Plugin for Testing -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M7</version>
      </plugin>
    </plugins>
  </build>
</project>

src/main/java/com/example/solution/Solution.java

package com.example.solution;

public class Solution {
    public int add(int a, int b) {
        return a + b;
    }

    // Overloaded method to handle String and int
    public String add(String a, int b) {
        return a + b;
    }
}

src/test/java/com/example/solution/SolutionTest.java

package com.example.solution;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class SolutionTest {

    private final Solution solution = new Solution();

    @Test
    void testAddPositiveNumbers() {
        assertEquals(3, solution.add(1, 2));
    }

    @Test
    void testAddNegativeNumbers() {
        assertEquals(-3, solution.add(-1, -2));
    }

    @Test
    void testAddStringAndInt() {
        assertEquals("12", solution.add("1", 2));
    }
}

Example Install Dependencies

mvn install

Example Compile the Project

mvn compile

Example Run Tests

mvn test