From dc5ea1e78eee529090d739774889639fab1c181c Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Wed, 14 Jan 2015 14:12:03 +0100 Subject: Assignment No.13 after correction --- .classpath | 15 ++- .../inf/java1/aufgabe13/BinaryOperatorTests.java | 148 --------------------- .../fhswf/in/inf/java1/aufgabe13/GeneralTests.java | 75 ----------- .../fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java | 22 --- .../in/inf/java1/aufgabe13/UnaryOperatorTests.java | 60 --------- .../inf/java1/aufgabe13/BinaryOperatorTests.java | 148 +++++++++++++++++++++ .../fhswf/in/inf/java1/aufgabe13/GeneralTests.java | 75 +++++++++++ .../fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java | 22 +++ .../in/inf/java1/aufgabe13/UnaryOperatorTests.java | 60 +++++++++ 9 files changed, 313 insertions(+), 312 deletions(-) delete mode 100644 src/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java delete mode 100644 src/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java delete mode 100644 src/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java delete mode 100644 src/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java create mode 100644 tests/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java create mode 100644 tests/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java create mode 100644 tests/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java create mode 100644 tests/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java diff --git a/.classpath b/.classpath index 373dce4..59486dc 100644 --- a/.classpath +++ b/.classpath @@ -1,7 +1,8 @@ - - - - - - - + + + + + + + + diff --git a/src/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java b/src/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java deleted file mode 100644 index 238c865..0000000 --- a/src/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * - */ -package de.fhswf.in.inf.java1.aufgabe13; - -import static org.junit.Assert.assertEquals; - -import java.util.Stack; - -import org.junit.Test; - -import de.fhswf.in.inf.java1.aufgabe12.Addition; -import de.fhswf.in.inf.java1.aufgabe12.BinaryOperator; -import de.fhswf.in.inf.java1.aufgabe12.BinaryTemplate; -import de.fhswf.in.inf.java1.aufgabe12.Division; -import de.fhswf.in.inf.java1.aufgabe12.Modulo; -import de.fhswf.in.inf.java1.aufgabe12.Multiplication; -import de.fhswf.in.inf.java1.aufgabe12.Subtraction; - -/** - * Tests the BinaryOperators. - * - * @author $Author: $ - * @version $Revision: $, $Date: $ UTC - */ -public class BinaryOperatorTests -{ - - /** - * Test for the Addition class. - */ - @Test - public final void testOperatorAddition() - { - // Sin is tested - BinaryOperator tester = new Addition(); - - // Test - Stack test = new Stack<>(); - - test.add(1.0); - test.add(1.0); - tester.eval(test); - - assertEquals(2.0, (double) test.pop(), 0); - } - - /** - * Test for the Division class. - */ - @Test - public final void testOperatorDivision() - { - // Sin is tested - BinaryOperator tester = new Division(); - - // Test - Stack test = new Stack<>(); - - test.add(2.0); - test.add(2.0); - tester.eval(test); - - assertEquals(1.0, (double) test.pop(), 0); - } - - /** - * Test for the Modulo class. - */ - @Test - public final void testOperatorModulo() - { - // Sin is tested - BinaryOperator tester = new Modulo(); - - // Test - Stack test = new Stack<>(); - - final double firstOperator = 3.0; - test.add(firstOperator); - test.add(2.0); - tester.eval(test); - - assertEquals(1.0, (double) test.pop(), 0); - } - - /** - * Test for the Multiplication class. - */ - @Test - public final void testOperatorMultiplication() - { - // Sin is tested - BinaryOperator tester = new Multiplication(); - - // Test - Stack test = new Stack<>(); - - test.add(2.0); - test.add(2.0); - tester.eval(test); - - final double expected = 4.0; - assertEquals(expected, (double) test.pop(), 0); - } - - /** - * Test for the Subtraction class. - */ - @Test - public final void testOperatorSubtraction() - { - // Sin is tested - BinaryOperator tester = new Subtraction(); - - // Test - Stack test = new Stack<>(); - - test.add(2.0); - test.add(2.0); - tester.eval(test); - - assertEquals(0.0, (double) test.pop(), 0); - } - - /** - * Test for the BinaryTemplate class initialized with pow. - */ - @Test - public final void testOperatorPow() - { - // Sin is tested - BinaryOperator tester = new BinaryTemplate("pow"); - - // Test - Stack test = new Stack<>(); - - final double exponent = 3.0; - - test.add(2.0); - test.add(exponent); - tester.eval(test); - - final double expected = 8.0; - assertEquals(expected, (double) test.pop(), 0); - } - -} diff --git a/src/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java b/src/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java deleted file mode 100644 index 4cbdf76..0000000 --- a/src/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * - */ -package de.fhswf.in.inf.java1.aufgabe13; - -import org.junit.Test; - -import de.fhswf.in.inf.java1.aufgabe12.UPN; - -/** - * Test the UPN class. - * - * @author $Author: $ - * @version $Revision: $, $Date: $ UTC - */ -public class GeneralTests -{ - - /** - * Test method for - * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. - */ - @Test(expected = IllegalArgumentException.class) - public final void testInvalidNumbers() - { - // UPN is tested - UPN tester = new UPN(); - - // Test - tester.calculate("1g 3 +"); - } - - /** - * Test method for - * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. - */ - @Test(expected = IllegalArgumentException.class) - public final void testInvalidOperator() - { - // UPN is tested - UPN tester = new UPN(); - - // Test - tester.calculate("1 cinus"); - } - - /** - * Test method for - * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. - */ - @Test(expected = IllegalArgumentException.class) - public final void testMissingOperands() - { - // UPN is tested - UPN tester = new UPN(); - - // Test - tester.calculate("1 +"); - } - - /** - * Test method for - * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. - */ - @Test(expected = IllegalArgumentException.class) - public final void testDevisionByZero() - { - // UPN is tested - UPN tester = new UPN(); - - // Test - tester.calculate("1 0 /"); - } - -} diff --git a/src/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java b/src/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java deleted file mode 100644 index 545e0be..0000000 --- a/src/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package de.fhswf.in.inf.java1.aufgabe13; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Test the assignments from paper 11 and 12. - * - * @author $Author: $ - * @version $Revision: $, $Date: $ UTC - */ -@RunWith(Suite.class) -@SuiteClasses({ BinaryOperatorTests.class, GeneralTests.class, - UnaryOperatorTests.class }) -public class UPNTestSuite -{ - -} diff --git a/src/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java b/src/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java deleted file mode 100644 index 997f71e..0000000 --- a/src/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * - */ -package de.fhswf.in.inf.java1.aufgabe13; - -import static org.junit.Assert.assertEquals; - -import java.util.Stack; - -import org.junit.Test; - -import de.fhswf.in.inf.java1.aufgabe12.UnaryOperator; -import de.fhswf.in.inf.java1.aufgabe12.UnaryTemplate; - -/** - * Tests the BinaryOperators. - * - * @author $Author: $ - * @version $Revision: $, $Date: $ UTC - */ -public class UnaryOperatorTests -{ - - /** - * Test for the UnaryTemplate class initialized with sin. - */ - @Test - public final void testOperatorSin() - { - // Sin is tested - UnaryOperator tester = new UnaryTemplate("sin"); - - // Test - Stack test = new Stack<>(); - - test.add(0.0); - tester.eval(test); - - assertEquals(0.0, (double) test.pop(), 0); - } - - /** - * Test for the UnaryTemplate class initialized with cos. - */ - @Test - public final void testOperatorCos() - { - // Cos is tested - UnaryOperator tester = new UnaryTemplate("cos"); - - // Test - Stack test = new Stack<>(); - - test.add(0.0); - tester.eval(test); - - assertEquals(1.0, (double) test.pop(), 0); - } - -} diff --git a/tests/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java b/tests/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java new file mode 100644 index 0000000..238c865 --- /dev/null +++ b/tests/de/fhswf/in/inf/java1/aufgabe13/BinaryOperatorTests.java @@ -0,0 +1,148 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe13; + +import static org.junit.Assert.assertEquals; + +import java.util.Stack; + +import org.junit.Test; + +import de.fhswf.in.inf.java1.aufgabe12.Addition; +import de.fhswf.in.inf.java1.aufgabe12.BinaryOperator; +import de.fhswf.in.inf.java1.aufgabe12.BinaryTemplate; +import de.fhswf.in.inf.java1.aufgabe12.Division; +import de.fhswf.in.inf.java1.aufgabe12.Modulo; +import de.fhswf.in.inf.java1.aufgabe12.Multiplication; +import de.fhswf.in.inf.java1.aufgabe12.Subtraction; + +/** + * Tests the BinaryOperators. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public class BinaryOperatorTests +{ + + /** + * Test for the Addition class. + */ + @Test + public final void testOperatorAddition() + { + // Sin is tested + BinaryOperator tester = new Addition(); + + // Test + Stack test = new Stack<>(); + + test.add(1.0); + test.add(1.0); + tester.eval(test); + + assertEquals(2.0, (double) test.pop(), 0); + } + + /** + * Test for the Division class. + */ + @Test + public final void testOperatorDivision() + { + // Sin is tested + BinaryOperator tester = new Division(); + + // Test + Stack test = new Stack<>(); + + test.add(2.0); + test.add(2.0); + tester.eval(test); + + assertEquals(1.0, (double) test.pop(), 0); + } + + /** + * Test for the Modulo class. + */ + @Test + public final void testOperatorModulo() + { + // Sin is tested + BinaryOperator tester = new Modulo(); + + // Test + Stack test = new Stack<>(); + + final double firstOperator = 3.0; + test.add(firstOperator); + test.add(2.0); + tester.eval(test); + + assertEquals(1.0, (double) test.pop(), 0); + } + + /** + * Test for the Multiplication class. + */ + @Test + public final void testOperatorMultiplication() + { + // Sin is tested + BinaryOperator tester = new Multiplication(); + + // Test + Stack test = new Stack<>(); + + test.add(2.0); + test.add(2.0); + tester.eval(test); + + final double expected = 4.0; + assertEquals(expected, (double) test.pop(), 0); + } + + /** + * Test for the Subtraction class. + */ + @Test + public final void testOperatorSubtraction() + { + // Sin is tested + BinaryOperator tester = new Subtraction(); + + // Test + Stack test = new Stack<>(); + + test.add(2.0); + test.add(2.0); + tester.eval(test); + + assertEquals(0.0, (double) test.pop(), 0); + } + + /** + * Test for the BinaryTemplate class initialized with pow. + */ + @Test + public final void testOperatorPow() + { + // Sin is tested + BinaryOperator tester = new BinaryTemplate("pow"); + + // Test + Stack test = new Stack<>(); + + final double exponent = 3.0; + + test.add(2.0); + test.add(exponent); + tester.eval(test); + + final double expected = 8.0; + assertEquals(expected, (double) test.pop(), 0); + } + +} diff --git a/tests/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java b/tests/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java new file mode 100644 index 0000000..4cbdf76 --- /dev/null +++ b/tests/de/fhswf/in/inf/java1/aufgabe13/GeneralTests.java @@ -0,0 +1,75 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe13; + +import org.junit.Test; + +import de.fhswf.in.inf.java1.aufgabe12.UPN; + +/** + * Test the UPN class. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public class GeneralTests +{ + + /** + * Test method for + * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. + */ + @Test(expected = IllegalArgumentException.class) + public final void testInvalidNumbers() + { + // UPN is tested + UPN tester = new UPN(); + + // Test + tester.calculate("1g 3 +"); + } + + /** + * Test method for + * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. + */ + @Test(expected = IllegalArgumentException.class) + public final void testInvalidOperator() + { + // UPN is tested + UPN tester = new UPN(); + + // Test + tester.calculate("1 cinus"); + } + + /** + * Test method for + * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. + */ + @Test(expected = IllegalArgumentException.class) + public final void testMissingOperands() + { + // UPN is tested + UPN tester = new UPN(); + + // Test + tester.calculate("1 +"); + } + + /** + * Test method for + * {@link de.fhswf.in.inf.java1.aufgabe12.UPN#calculate(java.lang.String)}. + */ + @Test(expected = IllegalArgumentException.class) + public final void testDevisionByZero() + { + // UPN is tested + UPN tester = new UPN(); + + // Test + tester.calculate("1 0 /"); + } + +} diff --git a/tests/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java b/tests/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java new file mode 100644 index 0000000..545e0be --- /dev/null +++ b/tests/de/fhswf/in/inf/java1/aufgabe13/UPNTestSuite.java @@ -0,0 +1,22 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe13; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Test the assignments from paper 11 and 12. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +@RunWith(Suite.class) +@SuiteClasses({ BinaryOperatorTests.class, GeneralTests.class, + UnaryOperatorTests.class }) +public class UPNTestSuite +{ + +} diff --git a/tests/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java b/tests/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java new file mode 100644 index 0000000..997f71e --- /dev/null +++ b/tests/de/fhswf/in/inf/java1/aufgabe13/UnaryOperatorTests.java @@ -0,0 +1,60 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe13; + +import static org.junit.Assert.assertEquals; + +import java.util.Stack; + +import org.junit.Test; + +import de.fhswf.in.inf.java1.aufgabe12.UnaryOperator; +import de.fhswf.in.inf.java1.aufgabe12.UnaryTemplate; + +/** + * Tests the BinaryOperators. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public class UnaryOperatorTests +{ + + /** + * Test for the UnaryTemplate class initialized with sin. + */ + @Test + public final void testOperatorSin() + { + // Sin is tested + UnaryOperator tester = new UnaryTemplate("sin"); + + // Test + Stack test = new Stack<>(); + + test.add(0.0); + tester.eval(test); + + assertEquals(0.0, (double) test.pop(), 0); + } + + /** + * Test for the UnaryTemplate class initialized with cos. + */ + @Test + public final void testOperatorCos() + { + // Cos is tested + UnaryOperator tester = new UnaryTemplate("cos"); + + // Test + Stack test = new Stack<>(); + + test.add(0.0); + tester.eval(test); + + assertEquals(1.0, (double) test.pop(), 0); + } + +} -- cgit v1.2.3-70-g09d2