-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
593 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
testdata/java/transpile/balancedBrackets/implementation/balancedBrackets.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
testdata/java/transpile/balancedBrackets/src/main/java/com/eval/BalancedBrackets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
testdata/java/transpile/balancedBrackets/src/test/java/com/eval/BalancedBracketsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
testdata/java/transpile/binarySearch/implementation/binarySearch.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
testdata/java/transpile/binarySearch/src/main/java/com/eval/BinarySearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
testdata/java/transpile/binarySearch/src/test/java/com/eval/BinarySearchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
testdata/java/transpile/cascadingIfElse/implementation/cascadingIfElse.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
testdata/java/transpile/cascadingIfElse/src/main/java/com/eval/CascadingIfElse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.eval; | ||
|
||
class CascadingIfElse { | ||
static int cascadingIfElse(int i) { | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
testdata/java/transpile/cascadingIfElse/src/test/java/com/eval/CascadingIfElseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
testdata/java/transpile/pascalsTriangle/implementation/pascalsTriangle.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.