Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers 188.refactor unary functions #118

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -223,19 +223,21 @@ static void assertComplex(Complex c1, Complex c2,
/**
* Assert the operation using the data loaded from test resources.
*
* @param name the operation name
* @param operation the operation
* @param maxUlps the maximum units of least precision between the two values
* @param name Operation name.
* @param operation1 Operation on the Complex object.
* @param operation2 Operation on the complex real and imaginary parts.
* @param maxUlps Maximum units of least precision between the two values.
*/
private static void assertOperation(String name,
UnaryOperator<Complex> operation, long maxUlps) {
UnaryOperator<Complex> operation1,
ComplexUnaryOperator<ComplexNumber> operation2,
long maxUlps) {
final List<Complex[]> data = loadTestData(name);
final long ulps = getTestUlps(maxUlps);
for (final Complex[] pair : data) {
assertComplex(pair[0], name, operation, pair[1], ulps);
assertComplex(pair[0], name, operation1, operation2, pair[1], ulps);
}
}

/**
* Assert the operation using the data loaded from test resources.
*
Expand All @@ -252,25 +254,6 @@ private static void assertBiOperation(String name,
}
}

/**
* Assert the operation using the data loaded from test resources.
*
* @param name Operation name.
* @param operation1 Operation on the Complex object.
* @param operation2 Operation on the complex real and imaginary parts.
* @param maxUlps Maximum units of least precision between the two values.
*/
private static void assertOperation(String name,
UnaryOperator<Complex> operation1,
ComplexUnaryOperator<ComplexNumber> operation2,
long maxUlps) {
final List<Complex[]> data = loadTestData(name);
final long ulps = getTestUlps(maxUlps);
for (final Complex[] pair : data) {
assertComplex(pair[0], name, operation1, operation2, pair[1], ulps);
}
}

/**
* Assert the operation using the data loaded from test resources.
*
Expand Down Expand Up @@ -314,47 +297,47 @@ private static long getTestUlps(long ulps) {

@Test
void testAcos() {
assertOperation("acos", Complex::acos, 2);
assertOperation("acos", Complex::acos, ComplexFunctions::acos, 2);
}

@Test
void testAcosh() {
assertOperation("acosh", Complex::acosh, 2);
assertOperation("acosh", Complex::acosh, ComplexFunctions::acosh, 2);
}

@Test
void testAsinh() {
// Odd function: negative real cases defined by positive real cases
assertOperation("asinh", Complex::asinh, 3);
assertOperation("asinh", Complex::asinh, ComplexFunctions::asinh, 3);
}

@Test
void testAtanh() {
// Odd function: negative real cases defined by positive real cases
assertOperation("atanh", Complex::atanh, 1);
assertOperation("atanh", Complex::atanh, ComplexFunctions::atanh, 1);
}

@Test
void testCosh() {
// Even function: negative real cases defined by positive real cases
assertOperation("cosh", Complex::cosh, 2);
assertOperation("cosh", Complex::cosh, ComplexFunctions::cosh, 2);
}

@Test
void testSinh() {
// Odd function: negative real cases defined by positive real cases
assertOperation("sinh", Complex::sinh, 2);
assertOperation("sinh", Complex::sinh, ComplexFunctions::sinh, 2);
}

@Test
void testTanh() {
// Odd function: negative real cases defined by positive real cases
assertOperation("tanh", Complex::tanh, 2);
assertOperation("tanh", Complex::tanh, ComplexFunctions::tanh, 2);
}

@Test
void testExp() {
assertOperation("exp", Complex::exp, 2);
assertOperation("exp", Complex::exp, ComplexFunctions::exp, 2);
}

@Test
Expand All @@ -364,7 +347,7 @@ void testLog() {

@Test
void testSqrt() {
assertOperation("sqrt", Complex::sqrt, 1);
assertOperation("sqrt", Complex::sqrt, ComplexFunctions::sqrt, 1);
}

@Test
Expand Down