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

DivideExpressionTest.testDivideByZeroXXX #720

Merged
merged 1 commit into from
Mar 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import walkingkooka.collect.list.Lists;
import walkingkooka.visit.Visiting;

import java.math.MathContext;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

public final class DivideExpressionTest extends BinaryArithmeticExpressionTestCase2<DivideExpression> {

Expand Down Expand Up @@ -80,6 +82,37 @@ protected void visit(final ValueExpression<?> t) {
"visited");
}

@Test
public void testEvaluateDivideByZeroBigDecimal() {
this.divideByZeroAndCheck(ExpressionNumberKind.BIG_DECIMAL);
}

@Test
public void testEvaluateDivideByZeroDouble() {
this.divideByZeroAndCheck(ExpressionNumberKind.DOUBLE);
}

private void divideByZeroAndCheck(final ExpressionNumberKind kind) {
final ExpressionEvaluationException thrown = assertThrows(
ExpressionEvaluationException.class,
() -> kind.one()
.divide(
kind.zero(),
new FakeExpressionNumberContext() {
@Override
public MathContext mathContext() {
return MathContext.DECIMAL32;
}
}
)
);

this.checkEquals(
"Division by zero",
thrown.getMessage()
);
}

// toBoolean...............................................................................................

@Test
Expand Down
Loading