diff --git a/testdata/java/transpile/balancedBrackets/implementation/balancedBrackets.go b/testdata/java/transpile/balancedBrackets/implementation/balancedBrackets.go new file mode 100644 index 00000000..a5516528 --- /dev/null +++ b/testdata/java/transpile/balancedBrackets/implementation/balancedBrackets.go @@ -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 +} diff --git a/testdata/java/transpile/balancedBrackets/pom.xml b/testdata/java/transpile/balancedBrackets/pom.xml new file mode 100644 index 00000000..76c04cc4 --- /dev/null +++ b/testdata/java/transpile/balancedBrackets/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + eval.dev.quality + balanced-brackets + SNAPSHOT + + 11 + 11 + + + + + org.openclover + clover-maven-plugin + 4.5.2 + + false + false + false + true + true + true + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.apache.commons + commons-lang3 + 3.14.0 + + + diff --git a/testdata/java/transpile/balancedBrackets/src/main/java/com/eval/BalancedBrackets.java b/testdata/java/transpile/balancedBrackets/src/main/java/com/eval/BalancedBrackets.java new file mode 100644 index 00000000..91ea17be --- /dev/null +++ b/testdata/java/transpile/balancedBrackets/src/main/java/com/eval/BalancedBrackets.java @@ -0,0 +1,6 @@ +package com.eval; + +public class BalancedBrackets { + static boolean hasBalancedBrackets(char[] charArray) { + } +} diff --git a/testdata/java/transpile/balancedBrackets/src/test/java/com/eval/BalancedBracketsTest.java b/testdata/java/transpile/balancedBrackets/src/test/java/com/eval/BalancedBracketsTest.java new file mode 100644 index 00000000..39141529 --- /dev/null +++ b/testdata/java/transpile/balancedBrackets/src/test/java/com/eval/BalancedBracketsTest.java @@ -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); + } +} diff --git a/testdata/java/transpile/binarySearch/implementation/binarySearch.go b/testdata/java/transpile/binarySearch/implementation/binarySearch.go new file mode 100644 index 00000000..939fb024 --- /dev/null +++ b/testdata/java/transpile/binarySearch/implementation/binarySearch.go @@ -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 +} diff --git a/testdata/java/transpile/binarySearch/pom.xml b/testdata/java/transpile/binarySearch/pom.xml new file mode 100644 index 00000000..272bde38 --- /dev/null +++ b/testdata/java/transpile/binarySearch/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + eval.dev.quality + binary-search + SNAPSHOT + + 11 + 11 + + + + + org.openclover + clover-maven-plugin + 4.5.2 + + false + false + false + true + true + true + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.apache.commons + commons-lang3 + 3.14.0 + + + diff --git a/testdata/java/transpile/binarySearch/src/main/java/com/eval/BinarySearch.java b/testdata/java/transpile/binarySearch/src/main/java/com/eval/BinarySearch.java new file mode 100644 index 00000000..1855e960 --- /dev/null +++ b/testdata/java/transpile/binarySearch/src/main/java/com/eval/BinarySearch.java @@ -0,0 +1,6 @@ +package com.eval; + +class BinarySearch { + static int binarySearch(int[] a, int x) { + } +} diff --git a/testdata/java/transpile/binarySearch/src/test/java/com/eval/BinarySearchTest.java b/testdata/java/transpile/binarySearch/src/test/java/com/eval/BinarySearchTest.java new file mode 100644 index 00000000..f8745b55 --- /dev/null +++ b/testdata/java/transpile/binarySearch/src/test/java/com/eval/BinarySearchTest.java @@ -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); + } +} diff --git a/testdata/java/transpile/cascadingIfElse/implementation/cascadingIfElse.go b/testdata/java/transpile/cascadingIfElse/implementation/cascadingIfElse.go new file mode 100644 index 00000000..0eabe88b --- /dev/null +++ b/testdata/java/transpile/cascadingIfElse/implementation/cascadingIfElse.go @@ -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 + } +} diff --git a/testdata/java/transpile/cascadingIfElse/pom.xml b/testdata/java/transpile/cascadingIfElse/pom.xml new file mode 100644 index 00000000..8c4d5487 --- /dev/null +++ b/testdata/java/transpile/cascadingIfElse/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + eval.dev.quality + cascading-if-else + SNAPSHOT + + 11 + 11 + + + + + org.openclover + clover-maven-plugin + 4.5.2 + + false + false + false + true + true + true + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.apache.commons + commons-lang3 + 3.14.0 + + + diff --git a/testdata/java/transpile/cascadingIfElse/src/main/java/com/eval/CascadingIfElse.java b/testdata/java/transpile/cascadingIfElse/src/main/java/com/eval/CascadingIfElse.java new file mode 100644 index 00000000..002f67e4 --- /dev/null +++ b/testdata/java/transpile/cascadingIfElse/src/main/java/com/eval/CascadingIfElse.java @@ -0,0 +1,6 @@ +package com.eval; + +class CascadingIfElse { + static int cascadingIfElse(int i) { + } +} diff --git a/testdata/java/transpile/cascadingIfElse/src/test/java/com/eval/CascadingIfElseTest.java b/testdata/java/transpile/cascadingIfElse/src/test/java/com/eval/CascadingIfElseTest.java new file mode 100644 index 00000000..6ca20c2d --- /dev/null +++ b/testdata/java/transpile/cascadingIfElse/src/test/java/com/eval/CascadingIfElseTest.java @@ -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); + } +} diff --git a/testdata/java/transpile/pascalsTriangle/implementation/pascalsTriangle.go b/testdata/java/transpile/pascalsTriangle/implementation/pascalsTriangle.go new file mode 100644 index 00000000..76ec109f --- /dev/null +++ b/testdata/java/transpile/pascalsTriangle/implementation/pascalsTriangle.go @@ -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 +} diff --git a/testdata/java/transpile/pascalsTriangle/pom.xml b/testdata/java/transpile/pascalsTriangle/pom.xml new file mode 100644 index 00000000..8c4d5487 --- /dev/null +++ b/testdata/java/transpile/pascalsTriangle/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + eval.dev.quality + cascading-if-else + SNAPSHOT + + 11 + 11 + + + + + org.openclover + clover-maven-plugin + 4.5.2 + + false + false + false + true + true + true + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.apache.commons + commons-lang3 + 3.14.0 + + + diff --git a/testdata/java/transpile/pascalsTriangle/src/main/java/com/eval/PascalsTriangle.java b/testdata/java/transpile/pascalsTriangle/src/main/java/com/eval/PascalsTriangle.java new file mode 100644 index 00000000..1a3735e7 --- /dev/null +++ b/testdata/java/transpile/pascalsTriangle/src/main/java/com/eval/PascalsTriangle.java @@ -0,0 +1,6 @@ +package com.eval; + +public class PascalsTriangle { + [][] generateTriangle(int rows) { + } +} diff --git a/testdata/java/transpile/pascalsTriangle/src/test/java/com/eval/PascalsTriangleTest.java b/testdata/java/transpile/pascalsTriangle/src/test/java/com/eval/PascalsTriangleTest.java new file mode 100644 index 00000000..2beabe03 --- /dev/null +++ b/testdata/java/transpile/pascalsTriangle/src/test/java/com/eval/PascalsTriangleTest.java @@ -0,0 +1,46 @@ +package com.eval; + +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; +import org.apache.commons.lang3.builder.EqualsBuilder; + +public class PascalsTriangleTest { + @Test + public void generateTriangle1() { + PascalsTriangle p = new PascalsTriangle(); + int rows = -1; + assertThrows(IllegalArgumentException.class, () -> { + p.generateTriangle(rows); + }); + } + + @Test + public void generateTriangle2() { + PascalsTriangle p = new PascalsTriangle(); + int rows = 0; + int[][] expected = {}; + int[][] actual = p.generateTriangle(rows); + + assertTrue(EqualsBuilder.reflectionEquals(expected, actual, false, null, true)); + } + + @Test + public void generateTriangle3() { + PascalsTriangle p = new PascalsTriangle(); + int rows = 1; + int[][] expected = { { 1 } }; + int[][] actual = p.generateTriangle(rows); + + assertTrue(EqualsBuilder.reflectionEquals(expected, actual, false, null, true)); + } + + @Test + public void generateTriangle4() { + PascalsTriangle p = new PascalsTriangle(); + int rows = 5; + int[][] expected = { { 1 }, { 1, 1 }, { 1, 2, 1 }, { 1, 3, 3, 1 }, { 1, 4, 6, 4, 1 } }; + int[][] actual = p.generateTriangle(rows); + + assertTrue(EqualsBuilder.reflectionEquals(expected, actual, false, null, true)); + } +} diff --git a/testdata/java/transpile/sort/implementation/sort.go b/testdata/java/transpile/sort/implementation/sort.go new file mode 100644 index 00000000..73e7e9f1 --- /dev/null +++ b/testdata/java/transpile/sort/implementation/sort.go @@ -0,0 +1,10 @@ +package sort + +func isSorted(a []int) bool { + i := 0 + for i < len(a)-1 && a[i] <= a[i+1] { + i++ + } + + return i == len(a)-1 +} diff --git a/testdata/java/transpile/sort/pom.xml b/testdata/java/transpile/sort/pom.xml new file mode 100644 index 00000000..e7e9282d --- /dev/null +++ b/testdata/java/transpile/sort/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + eval.dev.quality + sort + SNAPSHOT + + 11 + 11 + + + + + org.openclover + clover-maven-plugin + 4.5.2 + + false + false + false + true + true + true + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + + org.junit.jupiter + junit-jupiter + 5.8.2 + test + + + org.apache.commons + commons-lang3 + 3.14.0 + + + diff --git a/testdata/java/transpile/sort/src/main/java/com/eval/Sort.java b/testdata/java/transpile/sort/src/main/java/com/eval/Sort.java new file mode 100644 index 00000000..4fa3406c --- /dev/null +++ b/testdata/java/transpile/sort/src/main/java/com/eval/Sort.java @@ -0,0 +1,6 @@ +package com.eval; + +class Sort { + static boolean isSorted(int[] a) { + } +} diff --git a/testdata/java/transpile/sort/src/test/java/com/eval/SortTest.java b/testdata/java/transpile/sort/src/test/java/com/eval/SortTest.java new file mode 100644 index 00000000..e59f8b75 --- /dev/null +++ b/testdata/java/transpile/sort/src/test/java/com/eval/SortTest.java @@ -0,0 +1,47 @@ +package com.eval; + +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +public class SortTest { + + @Test + public void isSorted1() { + int[] a = {}; + boolean actual = Sort.isSorted(a); + + assertFalse(actual); + } + + @Test + public void isSorted2() { + int[] a = { 5, 4, 3, 2, 1 }; + boolean actual = Sort.isSorted(a); + + assertFalse(actual); + } + + @Test + public void isSorted3() { + int[] a = { 0 }; + boolean actual = Sort.isSorted(a); + + assertTrue(actual); + } + + @Test + public void isSorted4() { + int[] a = { 1, 2, 3, 4, 5 }; + boolean actual = Sort.isSorted(a); + + assertTrue(actual); + } + + @Test + public void isSorted5() { + int[] a = { 1, 2, 10, 11, 20, 21 }; + boolean actual = Sort.isSorted(a); + + assertTrue(actual); + } +}