You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/06/22 13:33:16 UTC
[commons-numbers] 02/15: NUMBERS-118: Generalize test case types
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit 86f4b8946109d75b243443f1117203fa87d9c020
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 11:26:11 2019 +0200
NUMBERS-118: Generalize test case types
---
.../commons/numbers/fraction/BigFractionTest.java | 8 +-
.../commons/numbers/fraction/CommonTestCases.java | 143 +++++++++++----------
.../commons/numbers/fraction/FractionTest.java | 8 +-
3 files changed, 80 insertions(+), 79 deletions(-)
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 8a5b9dd..ab79b07 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -39,11 +39,11 @@ public class BigFractionTest {
@Test
public void testConstructor() {
- for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+ for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
assertFraction(
testCase.expectedNumerator,
testCase.expectedDenominator,
- BigFraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+ BigFraction.of(testCase.operandNumerator, testCase.operandDenominator)
);
}
@@ -98,11 +98,11 @@ public class BigFractionTest {
// MATH-179
@Test
public void testDoubleConstructor() throws Exception {
- for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+ for (CommonTestCases.DoubleToFractionTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
assertFraction(
testCase.expectedNumerator,
testCase.expectedDenominator,
- BigFraction.from(testCase.constructorArgument, 1.0e-5, 100)
+ BigFraction.from(testCase.operand, 1.0e-5, 100)
);
}
}
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
index cbaa029..cc6127f 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
@@ -11,111 +11,112 @@ import java.util.List;
* numerators and denominators in the {@code int} range.
*/
public class CommonTestCases {
- private static final List<NumDenConstructorTestCase> numDenConstructorTestCasesList;
+ private static final List<UnaryOperatorTestCase> numDenConstructorTestCasesList;
- private static final List<DoubleConstructorTestCase> doubleConstructorTestCasesList;
+ private static final List<DoubleToFractionTestCase> doubleConstructorTestCasesList;
static {
numDenConstructorTestCasesList = new ArrayList<>();
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 1, 0, 1));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 2, 0, 1));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, -1, 0, 1));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, 2, 1, 2));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, 4, 1, 2));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-1, 2, -1, 2));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, -2, -1, 2));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-2, 4, -1, 2));
- numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, -4, -1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 1, 0, 1));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 2, 0, 1));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, -1, 0, 1));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, 2, 1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, 4, 1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-1, 2, -1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, -2, -1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-2, 4, -1, 2));
+ numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, -4, -1, 2));
doubleConstructorTestCasesList = new ArrayList<>();
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/2d, 1, 2));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/3d, 1, 3));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/3d, 2, 3));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/4d, 1, 4));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/4d, 3, 4));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/5d, 1, 5));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/5d, 2, 5));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/5d, 3, 5));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/5d, 4, 5));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/6d, 1, 6));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/6d, 5, 6));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/7d, 1, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/7d, 2, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/7d, 3, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/7d, 4, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/7d, 5, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/7d, 6, 7));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/8d, 1, 8));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/8d, 3, 8));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/8d, 5, 8));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/8d, 7, 8));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/9d, 1, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/9d, 2, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/9d, 4, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/9d, 5, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/9d, 7, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/9d, 8, 9));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/10d, 1, 10));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/10d, 3, 10));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/10d, 7, 10));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/10d, 9, 10));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/11d, 1, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/11d, 2, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/11d, 3, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/11d, 4, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/11d, 5, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/11d, 6, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/11d, 7, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/11d, 8, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/11d, 9, 11));
- doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(10d/11d, 10, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/2d, 1, 2));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/3d, 1, 3));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/3d, 2, 3));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/4d, 1, 4));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/4d, 3, 4));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/5d, 1, 5));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/5d, 2, 5));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/5d, 3, 5));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/5d, 4, 5));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/6d, 1, 6));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/6d, 5, 6));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/7d, 1, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/7d, 2, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/7d, 3, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/7d, 4, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/7d, 5, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/7d, 6, 7));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/8d, 1, 8));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/8d, 3, 8));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/8d, 5, 8));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/8d, 7, 8));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/9d, 1, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/9d, 2, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/9d, 4, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/9d, 5, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/9d, 7, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/9d, 8, 9));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/10d, 1, 10));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/10d, 3, 10));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/10d, 7, 10));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/10d, 9, 10));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/11d, 1, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/11d, 2, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/11d, 3, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/11d, 4, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/11d, 5, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/11d, 6, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/11d, 7, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/11d, 8, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/11d, 9, 11));
+ doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(10d/11d, 10, 11));
}
- public static List<NumDenConstructorTestCase> numDenConstructorTestCases() {
+ public static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
return Collections.unmodifiableList(numDenConstructorTestCasesList);
}
- public static List<DoubleConstructorTestCase> doubleConstructorTestCases() {
+ public static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
return Collections.unmodifiableList(doubleConstructorTestCasesList);
}
/**
- * Represents a test case where a fraction should be created from a
- * specified numerator and denominator, both in the {@code int} range.
+ * Represents a test case where a unary operation should be performed on a specified combination
+ * of numerator and denominator, both in the {@code int} range, and the numerator and
+ * denominator of the expected result are also in the {@code int} range.
*/
- public static class NumDenConstructorTestCase {
- public final int constructorNumerator;
- public final int constructorDenominator;
+ public static class UnaryOperatorTestCase {
+ public final int operandNumerator;
+ public final int operandDenominator;
public final int expectedNumerator;
public final int expectedDenominator;
- public NumDenConstructorTestCase(
- int constructorNumerator,
- int constructorDenominator,
+ public UnaryOperatorTestCase(
+ int operandNumerator,
+ int operandDenominator,
int expectedNumerator,
int expectedDenominator) {
- this.constructorNumerator = constructorNumerator;
- this.constructorDenominator = constructorDenominator;
+ this.operandNumerator = operandNumerator;
+ this.operandDenominator = operandDenominator;
this.expectedNumerator = expectedNumerator;
this.expectedDenominator = expectedDenominator;
}
}
/**
- * Represents a test case where a fraction should be created from a
- * {@code double} value and the expected numerator and denominator
+ * Represents a test case where an operation that yields a fraction should be performed
+ * on a {@code double} value and the numerator and denominator of the expected result
* are in the {@code int} range.
*/
- public static class DoubleConstructorTestCase {
- public final double constructorArgument;
+ public static class DoubleToFractionTestCase {
+ public final double operand;
public final int expectedNumerator;
public final int expectedDenominator;
- public DoubleConstructorTestCase(
- double constructorArgument,
+ public DoubleToFractionTestCase(
+ double operand,
int expectedNumerator,
int expectedDenominator) {
- this.constructorArgument = constructorArgument;
+ this.operand = operand;
this.expectedNumerator = expectedNumerator;
this.expectedDenominator = expectedDenominator;
}
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
index 293ffbd..c47d51a 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
@@ -33,11 +33,11 @@ public class FractionTest {
@Test
public void testConstructor() {
- for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+ for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
assertFraction(
testCase.expectedNumerator,
testCase.expectedDenominator,
- Fraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+ Fraction.of(testCase.operandNumerator, testCase.operandDenominator)
);
}
@@ -65,11 +65,11 @@ public class FractionTest {
// MATH-179
@Test
public void testDoubleConstructor() throws Exception {
- for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+ for (CommonTestCases.DoubleToFractionTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
assertFraction(
testCase.expectedNumerator,
testCase.expectedDenominator,
- Fraction.from(testCase.constructorArgument)
+ Fraction.from(testCase.operand)
);
}
}