test(evaluator): Add more tests

Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
Myzel394 2024-07-21 19:04:52 +02:00
parent 84ddb6b6fa
commit b53a0b1f92
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 51 additions and 43 deletions

View File

@ -60,47 +60,4 @@ class ExpressionComplexTest {
@Test @Test
fun shouldDivideRootAndDivideInCorrectOrder() = assertExpr("(√9)÷6", "0.5") fun shouldDivideRootAndDivideInCorrectOrder() = assertExpr("(√9)÷6", "0.5")
@Test
fun singleNumber() = assertExpr("42", "42")
@Test(expected = NumberFormatException::class)
fun divisionByZero() = assertExpr("1÷0", "")
@Test(expected = NumberFormatException::class)
fun invalidExpressionMissingOperand() = assertExpr("42+", "")
@Test
fun largeNumbers() = assertExpr("9999999999*9999999999", "99999999980000000001")
@Test
fun highPrecision() = assertExpr("1÷3", "0.3333333333")
@Test
fun deeplyNestedParentheses() = assertExpr("((((((42))))))", "42")
@Test
fun constantsAndFunctions() = assertExpr("π+e", "${Math.PI + Math.E}")
@Test
fun edgeMathematicalCases() =
assertExpr("0^0", "1") // Depending on the mathematical interpretation used
@Test
fun trigonometricLimits() = assertExpr("sin(0)", "0")
@Test
fun sinAtPi() = assertExpr("sin(π)", "0")
@Test
fun sinAtHalfPi() = assertExpr("sin(π÷2)", "1")
@Test
fun cosAtPi() = assertExpr("cos(π)", "-1")
@Test
fun cosAtHalfPi() = assertExpr("cos(π÷2)", "0")
@Test
fun cosAtPiOverThree() = assertExpr("cos(π÷3)", "0.5")
} }

View File

@ -111,4 +111,55 @@ class ExpressionSimpleTest {
@Test @Test
fun expression29() = assertExpr("0!", "1") fun expression29() = assertExpr("0!", "1")
@Test
fun factorial() = assertExpr("5!", "120")
@Test
fun singleNumber() = assertExpr("42", "42")
@Test(expected = NumberFormatException::class)
fun divisionByZero() = assertExpr("1÷0", "")
@Test(expected = NumberFormatException::class)
fun invalidExpressionMissingOperand() = assertExpr("42+", "")
@Test
fun largeNumbers() = assertExpr("9999999999*9999999999", "99999999980000000001")
@Test
fun highPrecision() = assertExpr("1÷3", "0.3333333333")
@Test
fun deeplyNestedParentheses() = assertExpr("((((((42))))))", "42")
@Test
fun constantsAndFunctions() = assertExpr("π+e", "${Math.PI + Math.E}")
@Test(expected = NumberFormatException::class)
fun edgeMathematicalCases() = assertExpr("0^0", "")
@Test
fun zeroExponent() = assertExpr("5^0", "1")
@Test
fun negativeExponent() = assertExpr("5^-1", "0.2")
@Test
fun trigonometricLimits() = assertExpr("sin(0)", "0")
@Test
fun sinAtPi() = assertExpr("sin(π)", "0")
@Test
fun sinAtHalfPi() = assertExpr("sin(π÷2)", "1")
@Test
fun cosAtPi() = assertExpr("cos(π)", "-1")
@Test
fun cosAtHalfPi() = assertExpr("cos(π÷2)", "0")
@Test
fun cosAtPiOverThree() = assertExpr("cos(π÷3)", "0.5")
} }