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
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
<scope>test</scope>
</dependency>

<!-- JUnit 5 Jupiter API for new tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.1</version>
<scope>test</scope>
</dependency>

<!-- JUnit 5 Jupiter Engine for running JUnit 5 tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.1</version>
<scope>test</scope>
</dependency>

<!-- JUnit Platform Vintage Engine to run JUnit 3/4 tests under Surefire -->
<dependency>
<groupId>org.junit.vintage</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lsmp/djep/groupJep/function/GAdd.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 05-Mar-2004
*/
package org.lsmp.djep.groupJep.function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lsmp/djep/vectorJep/function/Id.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lsmp/djep/vectorJep/function/Length.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 27-Jul-2003
*/
package org.lsmp.djep.vectorJep.function;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lsmp/djep/vectorJep/function/MDot.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

JEP - Java Math Expression Parser 2.24
December 30 2002
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 27-Jul-2003
*/
package org.lsmp.djep.vectorJep.function;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/Binomial.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @author rich
/* @author rich
* Created on 13-Feb-2005
*
* See LICENSE.txt for license information.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/Conjugate.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

@header@
@date@
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/Ele.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Created 26-May-2006 - Richard Morris
*/
package org.nfunk.jep.function;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/Imaginary.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

@header@
@date@
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/SquareRoot.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

@header@
@date@
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/Sum.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

@header@
@date@
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nfunk/jep/function/UMinus.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************

@header@
@date@
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/org/nfunk/jeptesting/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public static void main (String[] args) {

public static Test suite() {
TestSuite suite = new TestSuite("All JUnit Tests");
suite.addTest(new JEPTest("testParseExpression"));
suite.addTest(new LogarithmTest("testLogarithm"));
suite.addTest(new NaturalLogarithmTest("testNaturalLogarithm"));
// TODO: Update these when JEPTest is fully migrated to JUnit 5
// For now, these tests will run directly via JUnit 5 discovery
// suite.addTest(new JEPTest("testParseExpression"));
// suite.addTest(new LogarithmTest("testLogarithm"));
// suite.addTest(new NaturalLogarithmTest("testNaturalLogarithm"));
return suite;
}
}
123 changes: 63 additions & 60 deletions src/test/java/org/nfunk/jeptesting/JEPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import java.io.*;

import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.nfunk.jep.*;
import org.nfunk.jep.type.Complex;
Expand All @@ -28,8 +29,10 @@
* <pre>1+2
*3.</pre>
* The expressions '1+2' and '3' are evaluated with JEP and the results compared.
*
* This class uses JUnit 5 for testing.
*/
public class JEPTest extends TestCase {
public class JEPTest {

/** The parser */
JEP myParser;
Expand All @@ -52,15 +55,16 @@ public JEPTester() {
}*/

/**
* Creates a new JEPTest instance
* Default constructor for JUnit 5
*/
public JEPTest(String name) {
super(name);
public JEPTest() {
// No need to call super() for Object
}

/**
* Sets up the parser.
* Sets up the parser - works for JUnit 5
*/
@BeforeEach
public void setUp() {
// Set up the parser
myParser = new JEP();
Expand All @@ -75,12 +79,57 @@ public void setUp() {
/**
* Runs the test.
*/
public void runTest() {
@Test
public void testExpressionFile() {
String fileName = "JEPTestExpressions.txt";
testWithFile(fileName);
testGetValue();
testGetComplexValue();
testOpSetBug();
}

@Test
public void testGetValue() {
// Test whether a normal double value is returned correctly
myParser.parseExpression("2.1345");
Assertions.assertEquals(myParser.getValue(), 2.1345, 0);

// Test whether NaN is returned for Complex numbers
myParser.parseExpression("i");
Assertions.assertTrue(Double.isNaN(myParser.getValue()));

// Test whether NaN is returned for String results
myParser.parseExpression("\"asdf\"");
Assertions.assertTrue(Double.isNaN(myParser.getValue()));
}

@Test
public void testGetComplexValue() {
// Test whether a normal double value is returned as a Complex
myParser.parseExpression("2.1345");
Assertions.assertTrue(new Complex(2.1345, 0).equals(
myParser.getComplexValue(), 0));

// Test whether (0, 1) is returned for i
myParser.parseExpression("i");
Complex z = myParser.getComplexValue();
Assertions.assertNotNull(z);
Assertions.assertEquals(0, z.re());
Assertions.assertEquals(1, z.im());

// Test whether NaN is returned for String results
myParser.parseExpression("\"asdf\"");
Assertions.assertTrue(Double.isNaN(myParser.getValue()));
}

/**
* Backwards compatibility method for old test suite
*/
public void testParseExpression() {
testExpressionFile();
}

@Test
public void testOpSetBug() {
JEP j = new JEP(false, true, true, null);
Assertions.assertNotNull(j.getOperatorSet());
}

/**
Expand All @@ -101,7 +150,7 @@ public static void main(String args[]) {
}

// Create an instance of this class and analyse the file
JEPTest jt = new JEPTest("JEP Test");
JEPTest jt = new JEPTest();
jt.setUp();
jt.testWithFile(fileName);
}
Expand All @@ -119,12 +168,12 @@ public void testWithFile(String fileName) {
try {
InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
if (is == null) {
Assert.fail("File \""+fileName+"\" not found in resources");
Assertions.fail("File \""+fileName+"\" not found in resources");
return;
}
reader = new BufferedReader(new InputStreamReader(is));
} catch (Exception e) {
Assert.fail("Error reading file: " + e.getMessage());
Assertions.fail("Error reading file: " + e.getMessage());
return;
}

Expand Down Expand Up @@ -236,52 +285,6 @@ private boolean equal(Object param1, Object param2) throws Exception
// throw new Exception("Unable to compare the values of this type");
}

/**
* Test the getValue() method.
*/
public void testGetValue() {
// Test whether a normal double value is returned correctly
myParser.parseExpression("2.1345");
Assert.assertEquals(myParser.getValue(), 2.1345, 0);

// Test whether NaN is returned for Somplex numbers
myParser.parseExpression("i");
Assert.assertTrue(Double.isNaN(myParser.getValue()));

// Test whether NaN is returned for String results
myParser.parseExpression("\"asdf\"");
Assert.assertTrue(Double.isNaN(myParser.getValue()));
}

/**
* Test the getComplexValue() method.
*/
public void testGetComplexValue() {
// Test whether a normal double value is returned as a Complex
myParser.parseExpression("2.1345");
Assert.assertTrue(new Complex(2.1345, 0).equals(
myParser.getComplexValue(), 0));

// Test whether (0, 1) is returned for i
myParser.parseExpression("i");
Complex z = myParser.getComplexValue();
Assert.assertTrue(z != null);
Assert.assertTrue(z.re() == 0);
Assert.assertTrue(z.im() == 1);

// Test whether NaN is returned for String results
myParser.parseExpression("\"asdf\"");
Assert.assertTrue(Double.isNaN(myParser.getValue()));
}

/**
* Tests the uninitialized OperatorSet bug 1061200
*/
public void testOpSetBug() {
JEP j = new JEP(false, true, true, null);
Assert.assertNotNull(j.getOperatorSet());
}

/**
* Helper function for printing.
*/
Expand Down
17 changes: 7 additions & 10 deletions src/test/java/org/nfunk/jeptesting/LogarithmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@
import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.Logarithm;

import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class LogarithmTest extends TestCase {

public LogarithmTest(String name) {
super(name);
}
public class LogarithmTest {

/**
* Test method for 'org.nfunk.jep.function.Logarithm.run(Stack)'
* Tests the return value of log(NaN). This is a test for bug #1177557
*/
@Test
public void testLogarithm() {
Logarithm logFunction = new Logarithm();
java.util.Stack stack = new java.util.Stack();
stack.push(Double.valueOf(Double.NaN));
try {
logFunction.run(stack);
} catch (ParseException e) {
Assert.fail();
Assertions.fail();
}
Object returnValue = stack.pop();

if (returnValue instanceof Double) {
Assert.assertTrue(Double.isNaN(((Double)returnValue).doubleValue()));
Assertions.assertTrue(Double.isNaN(((Double)returnValue).doubleValue()));
} else {
Assert.fail();
Assertions.fail();
}
}

Expand Down
Loading