-
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.
* Updated README.md * Added github workflow * Added github workflow * Added tests --------- Co-authored-by: danilarassohin <danilarassohin@gmail.com>
- Loading branch information
1 parent
72f7a0b
commit b3775af
Showing
12 changed files
with
232 additions
and
17 deletions.
There are no files selected for viewing
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,23 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: [ "dev" ] | ||
pull_request: | ||
branches: [ "main", "dev" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn -B test --file pom.xml |
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
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
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
33 changes: 33 additions & 0 deletions
33
core/src/test/java/tech/hiddenproject/compaj/core/data/base/RealFunctionTest.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 tech.hiddenproject.compaj.core.data.base; | ||
|
||
import java.util.Random; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayName("RealFunctionTest should > ") | ||
public class RealFunctionTest { | ||
|
||
@Test | ||
@DisplayName("bind and execute function success") | ||
public void valueTest() { | ||
int expected = 5; | ||
|
||
RealFunction realFunction = new RealFunction("MyFunction"); | ||
realFunction.b(x -> x[0] + x[1]); | ||
Assertions.assertEquals(expected, realFunction.value(3, 2)); | ||
} | ||
|
||
@Test | ||
@DisplayName("bind single value and execute function success") | ||
public void singleValueTest() { | ||
RealFunction realFunction = new RealFunction("MyFunction"); | ||
|
||
double expected = new Random().nextDouble(); | ||
realFunction.b(expected); | ||
|
||
Assertions.assertEquals(expected, realFunction.value()); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
core/src/test/java/tech/hiddenproject/compaj/core/data/base/RealVectorFunctionTest.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,32 @@ | ||
package tech.hiddenproject.compaj.core.data.base; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayName("RealVectorFunctionTest should > ") | ||
public class RealVectorFunctionTest { | ||
|
||
@Test | ||
@DisplayName("bind and execute function success") | ||
public void valueTest() { | ||
Double[] expected = new Double[]{0d, 1d}; | ||
|
||
RealVectorFunction realFunction = new RealVectorFunction("MyFunction"); | ||
realFunction.b(x -> x); | ||
|
||
Assertions.assertEquals(expected, realFunction.value(expected)); | ||
} | ||
|
||
@Test | ||
@DisplayName("bind single value and execute function success") | ||
public void singleValueTest() { | ||
Double[] expected = new Double[]{0d, 1d}; | ||
|
||
RealVectorFunction realFunction = new RealVectorFunction("MyFunction"); | ||
realFunction.b(expected); | ||
|
||
Assertions.assertEquals(expected, realFunction.value()); | ||
} | ||
|
||
} |
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
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
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
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
97 changes: 97 additions & 0 deletions
97
repl/src/test/java/tech/hiddenproject/compaj/repl/REPLTest.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,97 @@ | ||
package tech.hiddenproject.compaj.repl; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.DoubleStream; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import tech.hiddenproject.compaj.extension.CompaJComplex; | ||
|
||
@DisplayName("REPLTest should > ") | ||
public class REPLTest { | ||
|
||
private static final PrintStream STANDARD_OUT = System.out; | ||
private static final ByteArrayOutputStream OUTPUT_CAPTOR = new ByteArrayOutputStream(); | ||
private static final ClassLoader CLASS_LOADER = REPLTest.class.getClassLoader(); | ||
|
||
@BeforeAll | ||
public static void init() { | ||
System.setOut(new PrintStream(OUTPUT_CAPTOR)); | ||
Main.init(); | ||
} | ||
|
||
@BeforeEach | ||
public void resetCaptor() { | ||
OUTPUT_CAPTOR.reset(); | ||
} | ||
|
||
@AfterAll | ||
public static void release() { | ||
System.setOut(STANDARD_OUT); | ||
} | ||
|
||
@Test | ||
@DisplayName("read input from string") | ||
public void inputStringTest() { | ||
String expected = "5"; | ||
|
||
String script = "print " + expected; | ||
CompaJ.readInput(script); | ||
|
||
Assertions.assertEquals(expected, OUTPUT_CAPTOR.toString().trim()); | ||
} | ||
|
||
@Test | ||
@DisplayName("read input from file") | ||
public void inputFileTest() { | ||
URL fileUrl = CLASS_LOADER.getResource("test_script_1.cjn"); | ||
|
||
Assertions.assertNotNull(fileUrl); | ||
|
||
String expected = "5"; | ||
|
||
CompaJ.readFile(fileUrl.getPath()); | ||
|
||
Assertions.assertEquals(expected, OUTPUT_CAPTOR.toString().trim()); | ||
} | ||
|
||
@Test | ||
@DisplayName("load CompaJComplex extension") | ||
public void complexExtensionTest() { | ||
String expected = new CompaJComplex(0, 1).toString(); | ||
|
||
String script = "print new CompaJComplex(0, 1)"; | ||
CompaJ.readInput(script); | ||
|
||
Assertions.assertEquals(expected, OUTPUT_CAPTOR.toString().trim()); | ||
} | ||
|
||
@Test | ||
@DisplayName("load Math extension") | ||
public void mathExtensionTest() { | ||
String expected = doubleList().stream() | ||
.map(Math::sin) | ||
.collect(Collectors.toList()).toString(); | ||
|
||
String script = "print sin(" + doubleList().toString() + ")"; | ||
|
||
CompaJ.readInput("print \"\""); | ||
CompaJ.readInput(script); | ||
|
||
Assertions.assertEquals(expected, OUTPUT_CAPTOR.toString().trim()); | ||
} | ||
|
||
private List<Double> doubleList() { | ||
return DoubleStream.iterate(0.0, d -> d <= 10.0, d -> d + 1) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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 @@ | ||
print 5 |