Skip to content

Commit

Permalink
Testdata to transpile Go into Java
Browse files Browse the repository at this point in the history
Part of #201
  • Loading branch information
ruiAzevedo19 committed Jul 8, 2024
1 parent d4d8b94 commit 6f2e4c5
Show file tree
Hide file tree
Showing 20 changed files with 593 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package balancedBrackets

func hasBalancedBrackets(charArray string) bool {
brackets := 0
for _, ch := range charArray {
if ch == '[' {
brackets++
} else if ch == ']' {
brackets--
} else {
return false // Non-bracket characters.
}
}

if brackets < 0 { // Closing bracket before opening bracket.
return false
}

return brackets == 0
}
50 changes: 50 additions & 0 deletions testdata/java/transpile/balancedBrackets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>eval.dev.quality</groupId>
<artifactId>balanced-brackets</artifactId>
<version>SNAPSHOT</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.5.2</version>
<configuration>
<generateHtml>false</generateHtml>
<generateJson>false</generateJson>
<generatePdf>false</generatePdf>
<generateXml>true</generateXml>
<includeFailedTestCoverage>true</includeFailedTestCoverage>
<showInnerFunctions>true</showInnerFunctions>
<showLambdaFunctions>true</showLambdaFunctions>
<singleCloverDatabase>true</singleCloverDatabase>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.eval;

public class BalancedBrackets {
static boolean hasBalancedBrackets(char[] charArray) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.eval;

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

public class BalancedBracketsTest {
@Test
public void hasBalancedBrackets1() {
char[] charArray = {};
boolean actual = BalancedBrackets.hasBalancedBrackets(charArray);

assertTrue(actual);
}

@Test
public void hasBalancedBrackets2() {
char[] charArray = { '[' };
boolean actual = BalancedBrackets.hasBalancedBrackets(charArray);

assertFalse(actual);
}

@Test
public void hasBalancedBrackets3() {
char[] charArray = { '[', '[', '[', ']', ']' };
boolean actual = BalancedBrackets.hasBalancedBrackets(charArray);

assertFalse(actual);
}

@Test
public void hasBalancedBrackets4() {
char[] charArray = { '[', '[', ']', ']' };
boolean actual = BalancedBrackets.hasBalancedBrackets(charArray);

assertTrue(actual);
}

@Test
public void hasBalancedBrackets5() {
char[] charArray = { '[', '[', '[', '[', ']', ']', ']', ']' };
boolean actual = BalancedBrackets.hasBalancedBrackets(charArray);

assertTrue(actual);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package binarySearch

func binarySearch(a []int, x int) int {
index := -1

min := 0
max := len(a) - 1

for index == -1 && min <= max {
m := (min + max) / 2

if x == a[m] {
index = m
} else if x < a[m] {
max = m - 1
} else {
min = m + 1
}
}

return index
}
50 changes: 50 additions & 0 deletions testdata/java/transpile/binarySearch/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>eval.dev.quality</groupId>
<artifactId>binary-search</artifactId>
<version>SNAPSHOT</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.5.2</version>
<configuration>
<generateHtml>false</generateHtml>
<generateJson>false</generateJson>
<generatePdf>false</generatePdf>
<generateXml>true</generateXml>
<includeFailedTestCoverage>true</includeFailedTestCoverage>
<showInnerFunctions>true</showInnerFunctions>
<showLambdaFunctions>true</showLambdaFunctions>
<singleCloverDatabase>true</singleCloverDatabase>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.eval;

class BinarySearch {
static int binarySearch(int[] a, int x) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.eval;

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

public class BinarySearchTest {

@Test
public void binarySearch1() {
int[] a = {};
int x = 0;
int expected = -1;
int actual = BinarySearch.binarySearch(a, x);

assertEquals(expected, actual);
}

@Test
public void binarySearch2() {
int[] a = { 0 };
int x = 5;
int expected = -1;
int actual = BinarySearch.binarySearch(a, x);

assertEquals(expected, actual);
}

@Test
public void binarySearch3() {
int[] a = { 1, 2, 3, 4, 5 };
int x = 6;
int expected = -1;
int actual = BinarySearch.binarySearch(a, x);

assertEquals(expected, actual);
}

@Test
public void binarySearch4() {
int[] a = { 1, 2, 3, 4, 5 };
int x = 3;
int expected = 2;
int actual = BinarySearch.binarySearch(a, x);

assertEquals(expected, actual);
}

@Test
public void binarySearch5() {
int[] a = { 1, 5, 10, 15, 20, 25 };
int x = 25;
int expected = 5;
int actual = BinarySearch.binarySearch(a, x);

assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cascadingIfElse

func cascadingIfElse(i int) int {
if i == 1 {
return 2
} else if i == 3 {
return 4
} else {
return 5
}
}
50 changes: 50 additions & 0 deletions testdata/java/transpile/cascadingIfElse/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>eval.dev.quality</groupId>
<artifactId>cascading-if-else</artifactId>
<version>SNAPSHOT</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.5.2</version>
<configuration>
<generateHtml>false</generateHtml>
<generateJson>false</generateJson>
<generatePdf>false</generatePdf>
<generateXml>true</generateXml>
<includeFailedTestCoverage>true</includeFailedTestCoverage>
<showInnerFunctions>true</showInnerFunctions>
<showLambdaFunctions>true</showLambdaFunctions>
<singleCloverDatabase>true</singleCloverDatabase>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.eval;

class CascadingIfElse {
static int cascadingIfElse(int i) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.eval;

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

public class CascadingIfElseTest {
@Test
public void cascadingIfElse1() {
int i = 0;
int expected = 5;
int actual = CascadingIfElse.cascadingIfElse(i);

assertEquals(expected, actual);
}

@Test
public void cascadingIfElse2() {
int i = 1;
int expected = 2;
int actual = CascadingIfElse.cascadingIfElse(i);

assertEquals(expected, actual);
}

@Test
public void cascadingIfElse3() {
int i = 3;
int expected = 4;
int actual = CascadingIfElse.cascadingIfElse(i);

assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pascalsTriangle

import "errors"

func pascalsTriangle(rows int) ([][]int, error) {
if rows < 0 {
return nil, errors.New("Rows can't be negative!")
}

triangle := make([][]int, rows)

for i := 0; i < rows; i++ {
triangle[i] = make([]int, i+1)
triangle[i][0] = 1
for j := 1; j < i; j++ {
triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]
}
triangle[i][i] = 1
}
return triangle, nil
}
Loading

0 comments on commit 6f2e4c5

Please sign in to comment.