Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- run: |
ant clean dist
cd dist; zip -r ../funz-client.zip ./*; cd ..
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
path: dist
- uses: softprops/action-gh-release@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
continue-on-error: true
timeout-minutes: 100
- if: steps.anttest.outcome != 'success'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.Rserver }}-unit
path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/use.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
continue-on-error: true
timeout-minutes: 60
- if: steps.anttest.outcome != 'success'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.Rserver }}-Main
path: |
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
continue-on-error: true
timeout-minutes: 60
- if: steps.anttest.outcome != 'success'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.Rserver }}-${{ matrix.CLI }}
path: |
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/funz/run/CalculatorsPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import java.net.MulticastSocket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.*;

import org.funz.api.Funz_v1;
import static org.funz.Protocol.PING_PERIOD;
import org.funz.conf.Configuration;
Expand All @@ -23,7 +21,6 @@
import org.funz.run.Computer.ComputerGuard;
import org.funz.run.Computer.ComputerStatusListener;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Collections;

/**
*
Expand Down Expand Up @@ -350,7 +347,7 @@ public void update(DatagramSocket s) throws IOException {
s.receive(p); // blocking as long as a packet not received / or SoTimeout exceeded
} catch (SocketTimeoutException t) {
force_close(s);
if (!shutdown) s = getSocket(_port); // Do not rebuild socket if shutdown
if (!shutdown) UDP_socket = getSocket(_port); // Do not rebuild socket if shutdown
return;
} catch (Exception t) {
Log.err(t,2);
Expand Down
311 changes: 197 additions & 114 deletions src/main/java/org/funz/script/ParseExpression.java

Large diffs are not rendered by default.

183 changes: 160 additions & 23 deletions src/test/java/org/funz/script/ParseExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.io.File;
import java.io.FilenameFilter;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.net.URL;
import java.util.*;

import org.funz.util.Data;
import org.funz.util.Format;
import static org.funz.util.Format.repeat;
Expand All @@ -14,7 +14,7 @@

public class ParseExpressionTest {

public static void main(String args[]) {
public static void main(String[] args) {
org.junit.runner.JUnitCore.main(ParseExpressionTest.class.getName());
}

Expand All @@ -26,19 +26,16 @@ public void testParseExpression() throws Exception {
LinkedList<String> expressions;
LinkedList<Object> results;

params = new HashMap<String, Object>();
params = new HashMap<>();
params.put(ParseExpression.FILES, new File("./src/test/samples/").listFiles(new FilenameFilter() {

public boolean accept(File dir, String name) {
return !name.startsWith(".");
}
}));
/*for (File f : (File[]) params.get(JavaParseExpression.FILES)) {
System.out.println(f.getName());
}*/

expressions = new LinkedList<String>();
results = new LinkedList<Object>();
expressions = new LinkedList<>();
results = new LinkedList<>();

expressions.add("CSV(\"toto.csv\",\",\")>>asString()");
results.add("{a=[1.0,2.0,3.0],b=[4.0,5.0,6.0],c=[7.0,8.0,9.0]}");
Expand Down Expand Up @@ -147,12 +144,10 @@ public void testCall() throws Exception {
LinkedList<String> expressions;
LinkedList<Object> results;

Parser p = new Parser(new File[0]);
expressions = new LinkedList<String>();
results = new LinkedList<Object>();
Parser p = new Parser();

expressions = new LinkedList<String>();
results = new LinkedList<Object>();
expressions = new LinkedList<>();
results = new LinkedList<>();

expressions.add("1+1");
results.add(2.0);
Expand Down Expand Up @@ -182,7 +177,7 @@ public void testCall() throws Exception {
Object res = results.get(i);

long tic = Calendar.getInstance().getTimeInMillis();
Object o = null;
Object o;
try {
o = ParseExpression.CallAlgebra(p, ex);
System.err.println(o);
Expand Down Expand Up @@ -287,19 +282,161 @@ public void testSerialLogic() {

}

@Test
public void testConcatString() {
System.err.println("testStringConcat");
testEvalEquality("concatString('1','1')", "11");
testEvalInequality("concatString('1','1')", 2);
}

@Test
public void testDoubleToInt() {
System.err.println("testDoubleToInt");
testEvalEquality("doubleToInt(2.3)", 2);
testEvalEquality("doubleToInt(2.0)", 2);
testEvalEquality("doubleToInt(1.9)", 1);
testEvalInequality("doubleToInt(1.9)", 2);
}

@Test
public void testBooleanComparison() {
System.err.println("testBooleanComparison");
testEvalEquality("1 > 2", false);
testEvalEquality("1 < 2", true);
testEvalInequality("1 > 2", true);
testEvalEquality("asNumeric(\"1.2\")", 1.2);
testEvalEquality("asNumeric(\"1.2\") < 2", true);
testEvalEquality("asNumeric(\"1.2\") > asNumeric(\"1.2\")", false);
}

@Test
public void testBooleanConversion() {
System.err.println("testBooleanConversion");
testEvalEquality("asNumeric(1>2)", 0.0);
testEvalEquality("asNumeric(1<2)", 1.0);
testEvalInequality("asNumeric(1>2)", 1.0);
testEvalEquality("asNumeric(asNumeric(\"1.2\") > asNumeric(\"1.2\"))", 0.0);
}

@Test
public void testBetween() {
System.err.println("testBetween");
testEvalEquality("between(\"1abc2\", \"1\", \"2\")", "abc");
testEvalInequality("between(\"1abc2\", \"1\", \"2\")", "1abc2");
testEvalEquality("between(\"1a<bc2\", \"1\", \"2\")", "a<bc");
testEvalEquality("between(\"1a>bc2\", \"1\", \"2\")", "a>bc");
testEvalEquality("between(\"1a+bc2\", \"1\", \"2\")", "a+bc");
testEvalEquality("between(\"1a-bc2\", \"1\", \"2\")", "a-bc");
testEvalEquality("between(\"1a*bc2\", \"1\", \"2\")", "a*bc");
testEvalEquality("between(\"1a/bc2\", \"1\", \"2\")", "a/bc");
testEvalEquality("between(\"+1a/bc-2\", \"+1\", \"-2\")", "a/bc");
testEvalEquality("between(\"<1a/bc>2\", \"<1\", \">2\")", "a/bc");
testEvalEquality("between(1abc2, 1a, c2)", "b");
testEvalEquality("between(\"<mean>.10000000E+31 .20000000E+31 .30000000E+31 <\\mean>\", \"<mean>\", \" \")", ".10000000E+31");
testEvalEquality("between(\"<?xml version=\"1.0\" encoding=\"UTF-16\"?><mean>.10000000E+31 .20000000E+31 .30000000E+31 <\\mean>\", \"<mean>\", \" \")", ".10000000E+31");
}

@Test
public void testReturnIf() {
System.err.println("returnIf");
testEvalEquality("returnIf(1>2, \"a\", \"b\")", "b");
testEvalEquality("returnIf(1<2, \"a\", \"b\")", "a");
testEvalInequality("returnIf(1>2, \"a\", \"b\")", "a");
testEvalEquality("returnIf(asNumeric(\"1.2\") > asNumeric(\"1.2\"), \"a\", \"b\")", "b");
}

/**
* Test if the evaluation of an expression is equals to the expected result
*
* @param expr expression to evaluate
* @param expected expected result
*/
private static void testEvalEquality(String expr, Object expected) {
testEvalEquality(expr, expected, null);
}

/**
* Test if the evaluation of an expression is equals to the expected result
*
* @param expr expression to evaluate
* @param expected expected result
*/
private static void testEvalEquality(String expr, Object expected, File file) {
Map fileMap = Data.newMap("files", new File[]{file});
Object evalRes = ParseExpression.eval(expr, fileMap);
assert expected.equals(evalRes) : "Result not matching when eval " + expr + ": [" + evalRes + "] != [" + expected + "] ";
}


@Test
public void testXpath() {
File xmlFile = loadTestXmlFile();
assert Parser.XPath(xmlFile, "/calculation/keff/esti[@name=\"SOURCE-COLLISION\"]/mean").equals("<?xml version=\"1.0\" encoding=\"UTF-16\"?><mean>.99580215 .99584567 .99587032 .99586262 </mean>") : "XPath evaluation failed";
}

private static File loadTestXmlFile() {
// Load xpath-test.xml from resources
String testFileName = "xpath-test.xml";
URL resource = ParseExpressionTest.class.getClassLoader().getResource(testFileName);

File xmlFile;
if (resource != null) {
xmlFile = new File(resource.getFile());
System.out.println("Found file: " + xmlFile.getAbsolutePath());
} else {
System.out.println("File not found!");
throw new RuntimeException("XML file not found: " + testFileName);

}
return xmlFile;
}

@Test
public void testExtractMinStdValues() {
File xmlFile = loadTestXmlFile();
String expectedMean = ".19580215";
String expectedStd = ".56892243E-03";
List<String> meanAndStdList = Parser.extractMinValues(
xmlFile,
"/calculation/keff/esti",
"mean",
"std");
assert meanAndStdList.size() == 2 : "Expected 2 values, got: " + meanAndStdList.size();
assert meanAndStdList.get(0).equals(expectedMean) : "Expected " + expectedMean +", got: " + meanAndStdList.get(0);
assert meanAndStdList.get(1).equals(expectedStd) : "Expected " + expectedStd + ", got: " + meanAndStdList.get(1);

List<String> expectResult = new ArrayList<>();
expectResult.add(expectedMean);
expectResult.add(expectedStd);

testEvalEquality("extractMinValues(\"" + xmlFile.getAbsolutePath() + "\", \"/calculation/keff/esti\", \"mean\", \"std\")", expectResult, xmlFile);
testEvalEquality("extractMinValues(\"" + xmlFile.getAbsolutePath() + "\", \"/calculation/keff/esti\", \"mean\", \"std\") >> get(1)", expectedMean, xmlFile);
testEvalEquality("extractMinValues(\"" + xmlFile.getAbsolutePath() + "\", \"/calculation/keff/esti\", \"mean\", \"std\") >> get(0)", expectedStd, xmlFile);
}

/**
* Test the evaluation of an expression is not equals to the expected result
*
* @param expr expression to evaluate
* @param expected not expected result
*/
private static void testEvalInequality(String expr, Object expected) {
Object evalRes = ParseExpression.eval(expr, new HashMap<>());
assert !expected.equals(evalRes) : "Result SHOULD NOT match when eval " + expr + ": [" + evalRes + "] == [" + expected + "] ";

}

@Test
public void testCallMethod() throws Exception {
System.err.println("testCallMethod");

LinkedList<String> expressions;
LinkedList<Object> results;

Parser p = new Parser(new File[0]);
expressions = new LinkedList<String>();
results = new LinkedList<Object>();
Parser p = new Parser();

expressions = new LinkedList<String>();
results = new LinkedList<Object>();
expressions = new LinkedList<>();
results = new LinkedList<>();

// test basic algebra
expressions.add("1+1");
Expand Down Expand Up @@ -368,7 +505,7 @@ public void testCallMethod() throws Exception {
Object res = results.get(i);

long tic = Calendar.getInstance().getTimeInMillis();
Object o = null;
Object o;
try {
o = ParseExpression.CallMethod(p, ex);
System.err.println(o);
Expand All @@ -382,7 +519,7 @@ public void testCallMethod() throws Exception {
if (o == null && res != null) {
throw new Exception("Parsing returned null !");
} else {
if (o != null || res != null) {
if (o != null) {
String ostr = o.toString();
if (o instanceof double[]) {
ostr = ArrayString.printDoubleArray((double[]) o);
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/xpath-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<calculation>
<keff system="initial" min_nb_of_initial_cycles_suppressed="0" max_nb_of_initial_cycles_suppressed="732">
<esti name="SOURCE-COLLISION">
<mean>.99580215 .99584567 .99587032 .99586262 </mean>
<std>.66892243E-03 .66841771E-03 .66887750E-03 </std>
</esti>
<esti name="SOURCE-TRACK-LENGTH">
<mean>.19580215 .99584567 .99587032 .99586262 </mean>
<std>.56892243E-03 .66841771E-03 .66887750E-03 </std>
</esti>
</keff>
</calculation>
42 changes: 42 additions & 0 deletions src/test/test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-test-resource" />
</content>
<orderEntry type="jdk" jdkName="21" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="module" module-name="main" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="funz-calculator-1.15" level="project" />
<orderEntry type="library" name="opencsv-2.3" level="project" />
</component>
</module>
Loading