Skip to content

Commit

Permalink
test: finish test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lbressler13 committed Jan 23, 2024
1 parent 369e77b commit a5b611b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class SqrtTest {
expected = "[√(1/2)]"
assertEquals(expected, sqrt.toString())

sqrt = Sqrt(ExactFraction(12, 35))
expected = "[√(12/35)]"
sqrt = Sqrt(ExactFraction(35, 12))
expected = "[√(35/12)]"
assertEquals(expected, sqrt.toString())
}

Expand All @@ -116,8 +116,8 @@ class SqrtTest {
expected = "[sqrt(1/2)]"
assertEquals(expected, sqrt.toPlainString())

sqrt = Sqrt(ExactFraction(12, 35))
expected = "[sqrt(12/35)]"
sqrt = Sqrt(ExactFraction(35, 12))
expected = "[sqrt(35/12)]"
assertEquals(expected, sqrt.toPlainString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ fun runEqualsTests() {
sqrt1 = Sqrt(ExactFraction(9, 400))
assertEquals(sqrt1, sqrt1)

sqrt1 = Sqrt(ExactFraction(400, 9))
assertEquals(sqrt1, sqrt1)

// not equal
sqrt1 = Sqrt.ZERO
var sqrt2 = Sqrt.ONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fun runExtractWholeOfTests() {
)
)

// incorrect value
// incorrect memoization
num = BigInteger("100")
expected = BigInteger("95")
runSingleExtractWholeOfTest(num, expected, mapOf(BigInteger("100") to BigInteger("95")), emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fun runGetSimplifiedTests() {
expected = Pair(ExactFraction.FIVE, Sqrt(ExactFraction.TWO))
assertEquals(expected, sqrt.getSimplified())

sqrt = Sqrt(3000)
expected = Pair(ExactFraction.TEN, Sqrt(ExactFraction(30)))
sqrt = Sqrt(ExactFraction(1, 3000))
expected = Pair(ExactFraction(1, 10), Sqrt(ExactFraction(1, 30)))
assertEquals(expected, sqrt.getSimplified())

sqrt = Sqrt(ExactFraction(50, 27))
Expand Down Expand Up @@ -92,7 +92,7 @@ fun runSimplifySetTests() {
assertEquals(expected, Sqrt.simplifySet(numbers))

// partial whole
numbers = constMultiSetOf(Sqrt(2), Sqrt(6))
numbers = constMultiSetOf(Sqrt(2), Sqrt(6), Sqrt(1))
expected = Pair(ExactFraction.TWO, constMultiSetOf(Sqrt(3)))
assertEquals(expected, Sqrt.simplifySet(numbers))

Expand All @@ -119,6 +119,7 @@ fun runSimplifySetTests() {
Sqrt(ExactFraction(15, 2)),
Sqrt(ExactFraction(2, 27)),
Sqrt(ExactFraction(1, 17)),
Sqrt.ONE,
Sqrt(4)
)
expected = Pair(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun assertDivByZero(test: () -> Unit) {
*
* @param message [String]: expected error message
* @param test () -> Unit: test to run
* @return [Exception] the exception that was thrown
* @return T: the exception that was thrown
*/
inline fun <reified T : Exception> assertFailsWithMessage(message: String, test: () -> Unit): T {
val error = assertFailsWith<T> { test() }
Expand All @@ -27,7 +27,7 @@ inline fun <reified T : Exception> assertFailsWithMessage(message: String, test:
}

/**
* Validate that a test succeeds, and throw error if it fails
* Validate that an operation succeeds, and throw an AssertionError if it fails
*
* @param errorMessage [String]: error message to throw if test fails
* @param test () -> Unit: test to run
Expand Down

0 comments on commit a5b611b

Please sign in to comment.