mirror of
https://github.com/marcin-szczepanski/jFuzzyLogic.git
synced 2024-12-18 16:35:27 +01:00
Tests cases: Reduced verbosity
This commit is contained in:
parent
5f76ffbef0
commit
ecae013c7d
10
.classpath
Normal file
10
.classpath
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="lib/antlrworks-1.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/jcommon-1.0.14.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/jfreechart-1.0.11.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/junit_4.11.0.jar"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
18
.project
Normal file
18
.project
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>jFuzzyLogic</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ package net.sourceforge.jFuzzyLogic.testCases;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sourceforge.jFuzzyLogic.FIS;
|
import net.sourceforge.jFuzzyLogic.FIS;
|
||||||
|
import net.sourceforge.jFuzzyLogic.Gpr;
|
||||||
import net.sourceforge.jFuzzyLogic.JFuzzyLogic;
|
import net.sourceforge.jFuzzyLogic.JFuzzyLogic;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -13,6 +14,8 @@ public class TestCaseCommandLine extends TestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// Prepare command line
|
// Prepare command line
|
||||||
String fileName = "tests/tipper.fcl";
|
String fileName = "tests/tipper.fcl";
|
||||||
String args[] = { "-noCharts", "-e", fileName, "8.5", "9" };
|
String args[] = { "-noCharts", "-e", fileName, "8.5", "9" };
|
||||||
|
@ -16,10 +16,6 @@ import net.sourceforge.jFuzzyLogic.Gpr;
|
|||||||
import net.sourceforge.jFuzzyLogic.rule.Rule;
|
import net.sourceforge.jFuzzyLogic.rule.Rule;
|
||||||
import net.sourceforge.jFuzzyLogic.rule.RuleBlock;
|
import net.sourceforge.jFuzzyLogic.rule.RuleBlock;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,26 +26,11 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class TestCaseJfuzzy extends TestCase {
|
public class TestCaseJfuzzy extends TestCase {
|
||||||
|
|
||||||
// A small number
|
static double EPSILON = 0.000001; // A small number
|
||||||
static double EPSILON = 0.000001;
|
static boolean verbose = false; // Verbose?
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that De Morgan's laws are OK
|
* Verify that De Morgan's laws are OK
|
||||||
* @param fis
|
|
||||||
*/
|
*/
|
||||||
void checkDeMorgan(FIS fis) {
|
void checkDeMorgan(FIS fis) {
|
||||||
// De Morgan's laws test
|
// De Morgan's laws test
|
||||||
@ -84,10 +65,59 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for membership function
|
||||||
|
*/
|
||||||
|
public void checkMembershipFunction(String title, FIS fis, String membershipFunctionFile) {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
int mem[][] = loadMembershipFile(membershipFunctionFile);
|
||||||
|
|
||||||
|
if (verbose) System.out.println(fis);
|
||||||
|
FunctionBlock fb = fis.getFunctionBlock(null);
|
||||||
|
|
||||||
|
for (int ind = 1; ind < mem.length; ind++) {
|
||||||
|
double value = int100ToDOuble(mem[ind][0]);
|
||||||
|
|
||||||
|
fb.setVariable("inVar", value);
|
||||||
|
|
||||||
|
int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
|
||||||
|
int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
|
||||||
|
int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));
|
||||||
|
|
||||||
|
if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDOuble(mem[ind][1]) + ", but it is " + int100ToDOuble(poor));
|
||||||
|
if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDOuble(mem[ind][2]) + ", but it is " + int100ToDOuble(good));
|
||||||
|
if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDOuble(mem[ind][3]) + ", but it is " + int100ToDOuble(excellent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for membership function
|
||||||
|
*/
|
||||||
|
public void checkMembershipFunction(String title, String fclFile, String membershipFunctionFile) {
|
||||||
|
int mem[][] = loadMembershipFile(membershipFunctionFile);
|
||||||
|
|
||||||
|
FIS fis = FIS.load(fclFile);
|
||||||
|
if (verbose) System.out.println(fis);
|
||||||
|
FunctionBlock fb = fis.getFunctionBlock(null);
|
||||||
|
|
||||||
|
for (int ind = 1; ind < mem.length; ind++) {
|
||||||
|
double value = int100ToDOuble(mem[ind][0]);
|
||||||
|
|
||||||
|
fb.setVariable("inVar", value);
|
||||||
|
|
||||||
|
int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
|
||||||
|
int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
|
||||||
|
int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));
|
||||||
|
|
||||||
|
if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDOuble(mem[ind][1]) + ", but it is " + int100ToDOuble(poor));
|
||||||
|
if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDOuble(mem[ind][2]) + ", but it is " + int100ToDOuble(good));
|
||||||
|
if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDOuble(mem[ind][3]) + ", but it is " + int100ToDOuble(excellent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Round a double to an integer (time 100)
|
* Round a double to an integer (time 100)
|
||||||
* @param d
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
int doubleToInt100(double d) {
|
int doubleToInt100(double d) {
|
||||||
return ((int) Math.round(d * 100));
|
return ((int) Math.round(d * 100));
|
||||||
@ -99,8 +129,6 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a table of numbers as an array of integers
|
* Read a table of numbers as an array of integers
|
||||||
* @param fileName
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
int[][] loadMembershipFile(String fileName) {
|
int[][] loadMembershipFile(String fileName) {
|
||||||
String file = Gpr.readFile(fileName);
|
String file = Gpr.readFile(fileName);
|
||||||
@ -124,23 +152,7 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
* Show a 'separator' line
|
* Show a 'separator' line
|
||||||
*/
|
*/
|
||||||
public void separator() {
|
public void separator() {
|
||||||
System.out.println("-------------------------------------------------------------------------------");
|
if (verbose) System.out.println("-------------------------------------------------------------------------------");
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,34 +160,36 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeMorgan() {
|
public void testDeMorgan() {
|
||||||
System.out.println("Testing De Morgan's law: AND=MIN / OR=MAX");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
if (verbose) System.out.println("Testing De Morgan's law: AND=MIN / OR=MAX");
|
||||||
FIS fis = FIS.load("fcl/testDeMorgan_1.fcl");
|
FIS fis = FIS.load("fcl/testDeMorgan_1.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
|
|
||||||
System.out.println("Testing De Morgan's law: AND=PROD / OR=ASUM (a.k.a. PROB_OR)");
|
if (verbose) System.out.println("Testing De Morgan's law: AND=PROD / OR=ASUM (a.k.a. PROB_OR)");
|
||||||
fis = FIS.load("fcl/testDeMorgan_2.fcl");
|
fis = FIS.load("fcl/testDeMorgan_2.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
|
|
||||||
System.out.println("Testing De Morgan's law: AND=BDIF / OR=BSUM");
|
if (verbose) System.out.println("Testing De Morgan's law: AND=BDIF / OR=BSUM");
|
||||||
fis = FIS.load("fcl/testDeMorgan_3.fcl");
|
fis = FIS.load("fcl/testDeMorgan_3.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
|
|
||||||
System.out.println("Testing De Morgan's law: AND=DMIN / OR=DMAX");
|
if (verbose) System.out.println("Testing De Morgan's law: AND=DMIN / OR=DMAX");
|
||||||
fis = FIS.load("fcl/testDeMorgan_4.fcl");
|
fis = FIS.load("fcl/testDeMorgan_4.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
|
|
||||||
System.out.println("Testing De Morgan's law: AND=NIPMIN / OR=NIPMAX");
|
if (verbose) System.out.println("Testing De Morgan's law: AND=NIPMIN / OR=NIPMAX");
|
||||||
fis = FIS.load("fcl/testDeMorgan_5.fcl");
|
fis = FIS.load("fcl/testDeMorgan_5.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
|
|
||||||
System.out.println("Testing De Morgan's law: AND=HAMACHER / OR=EINSTEIN");
|
if (verbose) System.out.println("Testing De Morgan's law: AND=HAMACHER / OR=EINSTEIN");
|
||||||
fis = FIS.load("fcl/testDeMorgan_6.fcl");
|
fis = FIS.load("fcl/testDeMorgan_6.fcl");
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
checkDeMorgan(fis);
|
checkDeMorgan(fis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +198,10 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileParsing1() {
|
public void testFileParsing1() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/junit1.fcl", true);
|
FIS fis = FIS.load("./tests/junit1.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
separator();
|
separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,8 +210,10 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileParsing2() {
|
public void testFileParsing2() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/junit2.fcl", true);
|
FIS fis = FIS.load("./tests/junit2.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
separator();
|
separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,8 +222,10 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileParsing3() {
|
public void testFileParsing3() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/junit3.fcl", true);
|
FIS fis = FIS.load("./tests/junit3.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
separator();
|
separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,8 +234,10 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileParsing4() {
|
public void testFileParsing4() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/junit4.fcl", true);
|
FIS fis = FIS.load("./tests/junit4.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
separator();
|
separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +246,8 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFunctions() {
|
public void testFunctions() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// Load tipper fuzzy system
|
// Load tipper fuzzy system
|
||||||
FIS fis = FIS.load("./tests/junit_functions.fcl", true);
|
FIS fis = FIS.load("./tests/junit_functions.fcl", true);
|
||||||
FunctionBlock fb = fis.getFunctionBlock(null);
|
FunctionBlock fb = fis.getFunctionBlock(null);
|
||||||
@ -248,61 +272,14 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for membership function
|
|
||||||
*/
|
|
||||||
public void testMembershipFunction(String title, FIS fis, String membershipFunctionFile) {
|
|
||||||
int mem[][] = loadMembershipFile(membershipFunctionFile);
|
|
||||||
|
|
||||||
System.out.println(fis);
|
|
||||||
FunctionBlock fb = fis.getFunctionBlock(null);
|
|
||||||
|
|
||||||
for (int ind = 1; ind < mem.length; ind++) {
|
|
||||||
double value = int100ToDOuble(mem[ind][0]);
|
|
||||||
|
|
||||||
fb.setVariable("inVar", value);
|
|
||||||
|
|
||||||
int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
|
|
||||||
int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
|
|
||||||
int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));
|
|
||||||
|
|
||||||
if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDOuble(mem[ind][1]) + ", but it is " + int100ToDOuble(poor));
|
|
||||||
if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDOuble(mem[ind][2]) + ", but it is " + int100ToDOuble(good));
|
|
||||||
if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDOuble(mem[ind][3]) + ", but it is " + int100ToDOuble(excellent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for membership function
|
|
||||||
*/
|
|
||||||
public void testMembershipFunction(String title, String fclFile, String membershipFunctionFile) {
|
|
||||||
int mem[][] = loadMembershipFile(membershipFunctionFile);
|
|
||||||
|
|
||||||
FIS fis = FIS.load(fclFile);
|
|
||||||
System.out.println(fis);
|
|
||||||
FunctionBlock fb = fis.getFunctionBlock(null);
|
|
||||||
|
|
||||||
for (int ind = 1; ind < mem.length; ind++) {
|
|
||||||
double value = int100ToDOuble(mem[ind][0]);
|
|
||||||
|
|
||||||
fb.setVariable("inVar", value);
|
|
||||||
|
|
||||||
int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
|
|
||||||
int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
|
|
||||||
int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));
|
|
||||||
|
|
||||||
if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDOuble(mem[ind][1]) + ", but it is " + int100ToDOuble(poor));
|
|
||||||
if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDOuble(mem[ind][2]) + ", but it is " + int100ToDOuble(good));
|
|
||||||
if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDOuble(mem[ind][3]) + ", but it is " + int100ToDOuble(excellent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for membership function
|
* Test method for membership function
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionCosine() {
|
public void testMembershipFunctionCosine() {
|
||||||
testMembershipFunction("Cosine", "./tests/junit_cosine.fcl", "./tests/junit_cosine.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Cosine", "./tests/junit_cosine.fcl", "./tests/junit_cosine.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,7 +287,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionDsigm() {
|
public void testMembershipFunctionDsigm() {
|
||||||
testMembershipFunction("Dsigm", "./tests/junit_dsigm.fcl", "./tests/junit_dsigm.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Dsigm", "./tests/junit_dsigm.fcl", "./tests/junit_dsigm.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,7 +297,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionGauss() {
|
public void testMembershipFunctionGauss() {
|
||||||
testMembershipFunction("Gauss", "./tests/junit_gauss.fcl", "./tests/junit_gauss.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Gauss", "./tests/junit_gauss.fcl", "./tests/junit_gauss.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,7 +307,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionGbell() {
|
public void testMembershipFunctionGbell() {
|
||||||
testMembershipFunction("Gbell", "./tests/junit_gbell.fcl", "./tests/junit_gbell.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Gbell", "./tests/junit_gbell.fcl", "./tests/junit_gbell.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -334,6 +317,8 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionOnLine4() {
|
public void testMembershipFunctionOnLine4() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
||||||
|
|
||||||
double i = 4.0;
|
double i = 4.0;
|
||||||
@ -341,7 +326,7 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
fis.setVariable("inputZeroMed", i);
|
fis.setVariable("inputZeroMed", i);
|
||||||
fis.setVariable("inputZeroMax", i + 1.0);
|
fis.setVariable("inputZeroMax", i + 1.0);
|
||||||
|
|
||||||
testMembershipFunction("Online", fis, "./tests/on_line_variable_4.txt");
|
checkMembershipFunction("Online", fis, "./tests/on_line_variable_4.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -349,6 +334,8 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionOnLine5() {
|
public void testMembershipFunctionOnLine5() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
||||||
|
|
||||||
double i = 5.0;
|
double i = 5.0;
|
||||||
@ -356,7 +343,7 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
fis.setVariable("inputZeroMed", i);
|
fis.setVariable("inputZeroMed", i);
|
||||||
fis.setVariable("inputZeroMax", i + 1.0);
|
fis.setVariable("inputZeroMax", i + 1.0);
|
||||||
|
|
||||||
testMembershipFunction("Online", fis, "./tests/on_line_variable_5.txt");
|
checkMembershipFunction("Online", fis, "./tests/on_line_variable_5.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,6 +351,8 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionOnLine6() {
|
public void testMembershipFunctionOnLine6() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
FIS fis = FIS.load("./tests/on_line_variable.fcl");
|
||||||
|
|
||||||
double i = 6.0;
|
double i = 6.0;
|
||||||
@ -371,7 +360,7 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
fis.setVariable("inputZeroMed", i);
|
fis.setVariable("inputZeroMed", i);
|
||||||
fis.setVariable("inputZeroMax", i + 1.0);
|
fis.setVariable("inputZeroMax", i + 1.0);
|
||||||
|
|
||||||
testMembershipFunction("Online", fis, "./tests/on_line_variable_6.txt");
|
checkMembershipFunction("Online", fis, "./tests/on_line_variable_6.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -379,7 +368,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionPiecewiseLinear() {
|
public void testMembershipFunctionPiecewiseLinear() {
|
||||||
testMembershipFunction("Piecewise_linear", "./tests/junit_piecewise_linear.fcl", "./tests/junit_piecewise_linear.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Piecewise_linear", "./tests/junit_piecewise_linear.fcl", "./tests/junit_piecewise_linear.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,7 +378,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionSigmoid() {
|
public void testMembershipFunctionSigmoid() {
|
||||||
testMembershipFunction("Sigmoid", "./tests/junit_sigmoid.fcl", "./tests/junit_sigmoid.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Sigmoid", "./tests/junit_sigmoid.fcl", "./tests/junit_sigmoid.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,7 +388,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionSingletons() {
|
public void testMembershipFunctionSingletons() {
|
||||||
testMembershipFunction("Singleton", "./tests/junit_singletons.fcl", "./tests/junit_singletons.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Singleton", "./tests/junit_singletons.fcl", "./tests/junit_singletons.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -403,7 +398,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionTrapezoid() {
|
public void testMembershipFunctionTrapezoid() {
|
||||||
testMembershipFunction("Trapezoid", "./tests/junit_trape.fcl", "./tests/junit_trape.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Trapezoid", "./tests/junit_trape.fcl", "./tests/junit_trape.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -411,7 +408,9 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMembershipFunctionTriangular() {
|
public void testMembershipFunctionTriangular() {
|
||||||
testMembershipFunction("Triangular", "./tests/junit_triang.fcl", "./tests/junit_triang.txt");
|
Gpr.debug("Test");
|
||||||
|
|
||||||
|
checkMembershipFunction("Triangular", "./tests/junit_triang.fcl", "./tests/junit_triang.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -420,9 +419,11 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNAmembership() {
|
public void testNAmembership() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// FCL.debug = true;
|
// FCL.debug = true;
|
||||||
FIS fis = FIS.load("./tests/junit_shashankrao.fcl", true);
|
FIS fis = FIS.load("./tests/junit_shashankrao.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
|
|
||||||
// This set of values used to produce a 'NaN' output
|
// This set of values used to produce a 'NaN' output
|
||||||
double ra = 0.5;
|
double ra = 0.5;
|
||||||
@ -438,8 +439,10 @@ public class TestCaseJfuzzy extends TestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoRule() {
|
public void testNoRule() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// FCL.debug = true;
|
// FCL.debug = true;
|
||||||
FIS fis = FIS.load("tests/noRules.fcl", true);
|
FIS fis = FIS.load("tests/noRules.fcl", true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import net.sourceforge.jFuzzyLogic.Gpr;
|
|||||||
|
|
||||||
import org.antlr.runtime.RecognitionException;
|
import org.antlr.runtime.RecognitionException;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestCaseTipper extends TestCase {
|
public class TestCaseTipper extends TestCase {
|
||||||
|
|
||||||
public static final double EPSILON = 0.001; // Error tolerated
|
public static final double EPSILON = 0.001; // Error tolerated
|
||||||
|
static boolean verbose = false; // Verbose?
|
||||||
|
|
||||||
public void createTxtFile() {
|
public void createTxtFile() {
|
||||||
// Load from 'FCL' file
|
// Load from 'FCL' file
|
||||||
@ -42,8 +42,6 @@ public class TestCaseTipper extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Round a double to an integer (time 100)
|
* Round a double to an integer (time 100)
|
||||||
* @param d
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
int doubleToInt100(double d) {
|
int doubleToInt100(double d) {
|
||||||
return ((int) Math.round(d * 100));
|
return ((int) Math.round(d * 100));
|
||||||
@ -55,8 +53,6 @@ public class TestCaseTipper extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a table of numbers as an array of integers
|
* Read a table of numbers as an array of integers
|
||||||
* @param fileName
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
int[][] loadMembershipFile(String fileName) {
|
int[][] loadMembershipFile(String fileName) {
|
||||||
String file = Gpr.readFile(fileName);
|
String file = Gpr.readFile(fileName);
|
||||||
@ -76,13 +72,10 @@ public class TestCaseTipper extends TestCase {
|
|||||||
return vals;
|
return vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// Load from 'FCL' file
|
// Load from 'FCL' file
|
||||||
String fileName = "tests/tipper.fcl";
|
String fileName = "tests/tipper.fcl";
|
||||||
FIS fis = FIS.load(fileName, true);
|
FIS fis = FIS.load(fileName, true);
|
||||||
@ -122,6 +115,8 @@ public class TestCaseTipper extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStringParsing() {
|
public void testStringParsing() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
String fcl = "FUNCTION_BLOCK tipper_parsed_from_string // Block definition (there may be more than one block per file)\n" + //
|
String fcl = "FUNCTION_BLOCK tipper_parsed_from_string // Block definition (there may be more than one block per file)\n" + //
|
||||||
"\n" + //
|
"\n" + //
|
||||||
"VAR_INPUT // Define input variables\n" + //
|
"VAR_INPUT // Define input variables\n" + //
|
||||||
@ -166,7 +161,7 @@ public class TestCaseTipper extends TestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
FIS fis = FIS.createFromString(fcl, true);
|
FIS fis = FIS.createFromString(fcl, true);
|
||||||
System.out.println(fis);
|
if (verbose) System.out.println(fis);
|
||||||
} catch (RecognitionException e) {
|
} catch (RecognitionException e) {
|
||||||
fail("RecognitionException:" + e);
|
fail("RecognitionException:" + e);
|
||||||
}
|
}
|
||||||
@ -177,6 +172,8 @@ public class TestCaseTipper extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTipper() {
|
public void testTipper() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// Load tipper fuzzy system
|
// Load tipper fuzzy system
|
||||||
FIS fis = FIS.load("./tests/junit_tipper.fcl", true);
|
FIS fis = FIS.load("./tests/junit_tipper.fcl", true);
|
||||||
FunctionBlock fb = fis.getFunctionBlock(null);
|
FunctionBlock fb = fis.getFunctionBlock(null);
|
||||||
@ -208,6 +205,8 @@ public class TestCaseTipper extends TestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
public void testToString() {
|
||||||
|
Gpr.debug("Test");
|
||||||
|
|
||||||
// Load system
|
// Load system
|
||||||
String fileName = "tests/tipper.fcl";
|
String fileName = "tests/tipper.fcl";
|
||||||
FIS fis = FIS.load(fileName, true);
|
FIS fis = FIS.load(fileName, true);
|
||||||
@ -222,9 +221,8 @@ public class TestCaseTipper extends TestCase {
|
|||||||
|
|
||||||
// Compare both fis (should be identical)
|
// Compare both fis (should be identical)
|
||||||
boolean ok = fis.toString().equals(fis2.toString());
|
boolean ok = fis.toString().equals(fis2.toString());
|
||||||
System.out.println("Are both fis equal?: " + ok);
|
if (verbose) System.out.println("Are both fis equal?: " + ok);
|
||||||
if (!ok) throw new RuntimeException("FCL code for both fis is not the same.");
|
if (!ok) throw new RuntimeException("FCL code for both fis is not the same.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package net.sourceforge.jFuzzyLogic.testCases;
|
|||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
import net.sourceforge.jFuzzyLogic.testCases.TestCaseCommandLine;
|
||||||
|
import net.sourceforge.jFuzzyLogic.testCases.TestCaseJfuzzy;
|
||||||
|
import net.sourceforge.jFuzzyLogic.testCases.TestCaseTipper;
|
||||||
|
|
||||||
public class TestSuiteAll {
|
public class TestSuiteAll {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user