Skip to content

Commit

Permalink
test: log test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lbressler13 committed Jan 23, 2024
1 parent f34541e commit 369e77b
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import xyz.lbres.exactnumbers.testutils.TestNumber
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

private val logNum1 = Log(ExactFraction(15, 4))
private val logNum2 = Log(8, 7)
private val logNum3 = Log(ExactFraction(19, 33)).inverse()
private val logNum4 = Log(ExactFraction(25, 121))
private val log1 = Log(ExactFraction(15, 4))
private val log2 = Log(8, 7)
private val log3 = Log(ExactFraction(19, 33)).inverse()
private val log4 = Log(ExactFraction(25, 121))
private val testNumber1 = TestNumber(ExactFraction(5, 6))
private val testNumber2 = TestNumber(ExactFraction.SEVEN)
private val one = ExactFraction.ONE
Expand All @@ -24,20 +24,20 @@ fun runEqualsTests() {
term1 = Term.fromValues(ExactFraction(-17, 4), emptyList())
assertEquals(term1, term1)

term1 = Term.fromValues(one, listOf(logNum1, logNum2))
term1 = Term.fromValues(one, listOf(log1, log2))
assertEquals(term1, term1)

term1 = Term.fromValues(one, listOf(Pi(), Pi()))
assertEquals(term1, term1)

term1 = Term.fromValues(ExactFraction.EIGHT, listOf(logNum4, logNum3, logNum1, Sqrt(15), Pi().inverse(), Pi()))
term1 = Term.fromValues(ExactFraction.EIGHT, listOf(log4, log3, log1, Sqrt(15), Pi().inverse(), Pi()))
assertEquals(term1, term1)

term1 = Term.fromValues(one, listOf(Pi(), TestNumber(ExactFraction(5))))
assertEquals(term1, term1)

term1 = Term.fromValues(ExactFraction.EIGHT, listOf(logNum4, logNum3, logNum1, Sqrt(5), Sqrt(7), Pi().inverse(), Pi()))
var term2 = Term.fromValues(ExactFraction.EIGHT, listOf(logNum4, logNum3, logNum1, Sqrt(35)))
term1 = Term.fromValues(ExactFraction.EIGHT, listOf(log4, log3, log1, Sqrt(5), Sqrt(7), Pi().inverse(), Pi()))
var term2 = Term.fromValues(ExactFraction.EIGHT, listOf(log4, log3, log1, Sqrt(35)))
assertEquals(term1, term2)
assertEquals(term2, term1)

Expand All @@ -46,12 +46,12 @@ fun runEqualsTests() {
assertEquals(term1, term2)
assertEquals(term2, term1)

term1 = Term.fromValues(ExactFraction(-4, 7), listOf(testNumber2, Sqrt(ExactFraction(7, 9)), Pi(), logNum1, logNum1.inverse()))
term1 = Term.fromValues(ExactFraction(-4, 7), listOf(testNumber2, Sqrt(ExactFraction(7, 9)), Pi(), log1, log1.inverse()))
term2 = Term.fromValues(ExactFraction(-4, 3), listOf(Sqrt(7), Pi()))
assertEquals(term1, term2)
assertEquals(term2, term1)

term1 = Term.fromValues(ExactFraction(-4, 7), listOf(testNumber2, Sqrt(ExactFraction(7, 9)), Pi(), logNum1, logNum1.inverse()))
term1 = Term.fromValues(ExactFraction(-4, 7), listOf(testNumber2, Sqrt(ExactFraction(7, 9)), Pi(), log1, log1.inverse()))
term2 = Term.fromValues(ExactFraction(-4, 3), listOf(Sqrt(7), Sqrt.ONE, Pi().inverse(), Pi(), Pi()))
assertEquals(term1, term2)
assertEquals(term2, term1)
Expand All @@ -67,18 +67,18 @@ fun runEqualsTests() {
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

term1 = Term.fromValues(one, listOf(logNum1))
term1 = Term.fromValues(one, listOf(log1))
term2 = Term.ONE
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

term1 = Term.fromValues(one, listOf(logNum1))
term2 = Term.fromValues(one, listOf(logNum1.inverse()))
term1 = Term.fromValues(one, listOf(log1))
term2 = Term.fromValues(one, listOf(log1.inverse()))
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

term1 = Term.fromValues(one, listOf(logNum1))
term2 = Term.fromValues(one, listOf(logNum1, logNum2))
term1 = Term.fromValues(one, listOf(log1))
term2 = Term.fromValues(one, listOf(log1, log2))
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

Expand Down Expand Up @@ -117,13 +117,13 @@ fun runEqualsTests() {
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

term1 = Term.fromValues(ExactFraction(5, 7), listOf(logNum1, logNum1, Pi(), Pi().inverse()))
term2 = Term.fromValues(ExactFraction.FIVE, listOf(logNum1, logNum1, Pi(), Pi().inverse()))
term1 = Term.fromValues(ExactFraction(5, 7), listOf(log1, log1, Pi(), Pi().inverse()))
term2 = Term.fromValues(ExactFraction.FIVE, listOf(log1, log1, Pi(), Pi().inverse()))
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

term1 = Term.fromValues(ExactFraction.EIGHT, listOf(logNum3, logNum4, Pi().inverse()))
term2 = Term.fromValues(ExactFraction(-17, 15), listOf(logNum1, logNum2, logNum3))
term1 = Term.fromValues(ExactFraction.EIGHT, listOf(log3, log4, Pi().inverse()))
term2 = Term.fromValues(ExactFraction(-17, 15), listOf(log1, log2, log3))
assertNotEquals(term1, term2)
assertNotEquals(term2, term1)

Expand Down Expand Up @@ -153,8 +153,8 @@ fun runToStringTests() {
expected = "<1x${Log.ONE}>"
assertEquals(expected, term.toString())

term = Term.fromValues(one, listOf(logNum2, logNum4, logNum1))
expected = "<1x${logNum2}x${logNum4}x$logNum1>"
term = Term.fromValues(one, listOf(log2, log4, log1))
expected = "<1x${log2}x${log4}x$log1>"
assertEquals(expected, term.toString())

// just pi
Expand All @@ -176,16 +176,16 @@ fun runToStringTests() {
assertEquals(expected, term.toString())

// mix
term = Term.fromValues(ExactFraction.EIGHT, listOf(logNum3, Sqrt(12), testNumber2, Pi()))
expected = "<8x${logNum3}x${Sqrt(12)}x${testNumber2}x${Pi()}>"
term = Term.fromValues(ExactFraction.EIGHT, listOf(log3, Sqrt(12), testNumber2, Pi()))
expected = "<8x${log3}x${Sqrt(12)}x${testNumber2}x${Pi()}>"
assertEquals(expected, term.toString())

val sqrt1 = Sqrt(ExactFraction(1000, 109))
val sqrt2 = Sqrt(5096)
term = Term.fromValues(
ExactFraction(-100, 333),
listOf(logNum2, logNum2, logNum4, testNumber1, logNum1, sqrt1, sqrt2, Pi().inverse(), Pi())
listOf(log2, log2, log4, testNumber1, log1, sqrt1, sqrt2, Pi().inverse(), Pi())
)
expected = "<[-100/333]x${logNum2}x${logNum2}x${logNum4}x${testNumber1}x${logNum1}x${sqrt1}x${sqrt2}x${Pi().inverse()}x${Pi()}>"
expected = "<[-100/333]x${log2}x${log2}x${log4}x${testNumber1}x${log1}x${sqrt1}x${sqrt2}x${Pi().inverse()}x${Pi()}>"
assertEquals(expected, term.toString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import xyz.lbres.exactnumbers.testutils.TestNumber
import xyz.lbres.kotlinutils.list.StringList
import kotlin.test.assertEquals

private val logNum1 = Log(ExactFraction(15, 4))
private val logNum2 = Log(8, 7)
private val logNum3 = Log(ExactFraction(19, 33)).inverse()
private val logNum4 = Log(ExactFraction(25, 121))
private val log1 = Log(ExactFraction(15, 4))
private val log2 = Log(8, 7)
private val log3 = Log(ExactFraction(19, 33)).inverse()
private val log4 = Log(ExactFraction(25, 121))
private val testNumber1 = TestNumber(ExactFraction(3, 4))
private val testNumber2 = TestNumber(ExactFraction.SEVEN)
private val one = ExactFraction.ONE
Expand All @@ -25,7 +25,7 @@ fun runGetFactorsByTypeTests() {
var term = Term.fromValues(ExactFraction.ZERO, emptyList())
runSingleIrrationalsByTypeTest(term, types, emptyMap())

term = Term.fromValues(one, listOf(logNum1, logNum2, testNumber1, Pi(), TestNumber(ExactFraction.ZERO)))
term = Term.fromValues(one, listOf(log1, log2, testNumber1, Pi(), TestNumber(ExactFraction.ZERO)))
runSingleIrrationalsByTypeTest(term, types, emptyMap())

// non-zero
Expand All @@ -41,21 +41,21 @@ fun runGetFactorsByTypeTests() {
)
)

term = Term.fromValues(one, listOf(testNumber1, logNum2, testNumber2.inverse(), Pi().inverse()))
term = Term.fromValues(one, listOf(testNumber1, log2, testNumber2.inverse(), Pi().inverse()))
runSingleIrrationalsByTypeTest(
term, types + listOf("Random"),
mapOf(
TestNumber.TYPE to listOf(testNumber1, testNumber2.inverse()),
Log.TYPE to listOf(logNum2),
Log.TYPE to listOf(log2),
Pi.TYPE to listOf(Pi().inverse())
)
)

term = Term.fromValues(one, listOf(logNum4, logNum4, logNum2), listOf(Sqrt.ONE, Sqrt(ExactFraction(17, 7))), -2)
term = Term.fromValues(one, listOf(log4, log4, log2), listOf(Sqrt.ONE, Sqrt(ExactFraction(17, 7))), -2)
runSingleIrrationalsByTypeTest(
term, types,
mapOf(
Log.TYPE to listOf(logNum4, logNum4, logNum2),
Log.TYPE to listOf(log4, log4, log2),
Sqrt.TYPE to listOf(Sqrt.ONE, Sqrt(ExactFraction(17, 7))),
Pi.TYPE to listOf(Pi().inverse(), Pi().inverse())
)
Expand All @@ -77,29 +77,29 @@ fun runGetLogsTests() {
assertEquals(expected, term.getLogs())

// just logs
term = Term.fromValues(one, listOf(logNum1))
expected = listOf(logNum1)
term = Term.fromValues(one, listOf(log1))
expected = listOf(log1)
assertEquals(expected, term.getLogs())

term = Term.fromValues(one, listOf(logNum1, logNum1))
expected = listOf(logNum1, logNum1)
term = Term.fromValues(one, listOf(log1, log1))
expected = listOf(log1, log1)
assertEquals(expected, term.getLogs())

term = Term.fromValues(one, listOf(logNum1, logNum1.inverse()))
expected = listOf(logNum1, logNum1.inverse())
term = Term.fromValues(one, listOf(log1, log1.inverse()))
expected = listOf(log1, log1.inverse())
assertEquals(expected, term.getLogs())

term = Term.fromValues(one, listOf(logNum3, logNum4, logNum1))
expected = listOf(logNum3, logNum4, logNum1)
term = Term.fromValues(one, listOf(log3, log4, log1))
expected = listOf(log3, log4, log1)
assertEquals(expected, term.getLogs())

// mix
term = Term.fromValues(one, listOf(logNum3, Sqrt(2), Pi()))
expected = listOf(logNum3)
term = Term.fromValues(one, listOf(log3, Sqrt(2), Pi()))
expected = listOf(log3)
assertEquals(expected, term.getLogs())

term = Term.fromValues(ExactFraction.EIGHT, listOf(logNum2, logNum2, logNum3, logNum4, Sqrt(15), Pi(), Pi().inverse()))
expected = listOf(logNum2, logNum2, logNum3, logNum4)
term = Term.fromValues(ExactFraction.EIGHT, listOf(log2, log2, log3, log4, Sqrt(15), Pi(), Pi().inverse()))
expected = listOf(log2, log2, log3, log4)
assertEquals(expected, term.getLogs())
}

Expand All @@ -120,10 +120,10 @@ fun runGetPiCountTests() {
term = Term.fromValues(one, listOf(Pi(), Pi().inverse(), Pi(), Pi().inverse(), Pi(), Pi().inverse()))
assertEquals(expected, term.getPiCount())

term = Term.fromValues(one, listOf(logNum1, logNum2, Sqrt(ExactFraction(64, 9))))
term = Term.fromValues(one, listOf(log1, log2, Sqrt(ExactFraction(64, 9))))
assertEquals(expected, term.getPiCount())

term = Term.fromValues(one, listOf(logNum3, logNum4, logNum2, Pi().inverse(), Pi(), Pi().inverse(), Pi()))
term = Term.fromValues(one, listOf(log3, log4, log2, Pi().inverse(), Pi(), Pi().inverse(), Pi()))
assertEquals(expected, term.getPiCount())

// just pi
Expand All @@ -144,11 +144,11 @@ fun runGetPiCountTests() {
assertEquals(expected, term.getPiCount())

// mix
term = Term.fromValues(one, listOf(logNum2, Sqrt(2), Pi().inverse()))
term = Term.fromValues(one, listOf(log2, Sqrt(2), Pi().inverse()))
expected = -1
assertEquals(expected, term.getPiCount())

term = Term.fromValues(ExactFraction.EIGHT, listOf(logNum3, logNum2, Sqrt(36), Pi(), Pi(), Pi().inverse(), Pi()))
term = Term.fromValues(ExactFraction.EIGHT, listOf(log3, log2, Sqrt(36), Pi(), Pi(), Pi().inverse(), Pi()))
expected = 2
assertEquals(expected, term.getPiCount())
}
Expand All @@ -164,7 +164,7 @@ fun runGetSquareRootsTests() {
term = Term.fromValues(ExactFraction.TEN, emptyList())
assertEquals(expected, term.getSquareRoots())

term = Term.fromValues(one, listOf(logNum1, logNum2, Pi(), Pi().inverse()))
term = Term.fromValues(one, listOf(log1, log2, Pi(), Pi().inverse()))
assertEquals(expected, term.getSquareRoots())

// just sqrt
Expand All @@ -185,11 +185,11 @@ fun runGetSquareRootsTests() {
assertEquals(expected, term.getSquareRoots())

// mix
term = Term.fromValues(one, listOf(logNum2, Sqrt(2), Pi().inverse()))
term = Term.fromValues(one, listOf(log2, Sqrt(2), Pi().inverse()))
expected = listOf(Sqrt(2))
assertEquals(expected, term.getSquareRoots())

term = Term.fromValues(ExactFraction.EIGHT, listOf(logNum1, logNum2, Sqrt.ONE, Sqrt(97), Sqrt(ExactFraction(9, 25)), Pi()))
term = Term.fromValues(ExactFraction.EIGHT, listOf(log1, log2, Sqrt.ONE, Sqrt(97), Sqrt(ExactFraction(9, 25)), Pi()))
expected = listOf(Sqrt.ONE, Sqrt(97), Sqrt(ExactFraction(9, 25)))
assertEquals(expected, term.getSquareRoots())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import xyz.lbres.exactnumbers.testutils.TestNumber
import java.math.BigDecimal
import kotlin.test.assertEquals

private val logNum1 = Log(ExactFraction(15, 4))
private val logNum2 = Log(8, 7)
private val log1 = Log(ExactFraction(15, 4))
private val log2 = Log(8, 7)
private val sqrt = Sqrt(ExactFraction(20, 33))
private val testNumber1 = TestNumber(ExactFraction(3, 4))
private val testNumber2 = TestNumber(ExactFraction.SEVEN)
Expand All @@ -25,17 +25,17 @@ fun runCommonSimplifyTests(simplify: (Term) -> Term) {
var expectedCoeff = ExactFraction.EIGHT
checkTerm(result, expectedCoeff)

term = Term.fromValues(ExactFraction(-3, 2), listOf(logNum1, pi, piInverse, pi))
term = Term.fromValues(ExactFraction(-3, 2), listOf(log1, pi, piInverse, pi))
result = simplify(term)
expectedCoeff = ExactFraction(-3, 2)
var expectedFactors: List<IrrationalNumber<*>> = listOf(logNum1, pi)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(logNum1), pis = listOf(pi), piCount = 1)
var expectedFactors: List<IrrationalNumber<*>> = listOf(log1, pi)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(log1), pis = listOf(pi), piCount = 1)

term = Term.fromValues(ExactFraction.HALF, listOf(Log.ONE, logNum1, testNumber2, testNumber2))
term = Term.fromValues(ExactFraction.HALF, listOf(Log.ONE, log1, testNumber2, testNumber2))
result = simplify(term)
expectedCoeff = ExactFraction(49, 2)
expectedFactors = listOf(logNum1)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(logNum1))
expectedFactors = listOf(log1)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(log1))

term = Term.fromValues(-ExactFraction.HALF, listOf(Log.ONE, piInverse))
result = simplify(term)
Expand All @@ -58,11 +58,11 @@ fun runCommonSimplifyTests(simplify: (Term) -> Term) {

term = Term.fromValues(
ExactFraction(18, 5),
listOf(logNum2, logNum2, logNum1, logNum2.inverse(), piInverse, piInverse, piInverse, pi)
listOf(log2, log2, log1, log2.inverse(), piInverse, piInverse, piInverse, pi)
)
result = simplify(term)
expectedCoeff = ExactFraction(18, 5)
var logs = listOf(logNum2, logNum1)
var logs = listOf(log2, log1)
var pis = listOf(piInverse, piInverse)
checkTerm(result, expectedCoeff, logs + pis, logs = logs, pis = pis, piCount = -2)

Expand Down Expand Up @@ -117,11 +117,11 @@ fun runCommonSimplifyTests(simplify: (Term) -> Term) {
expectedCoeff = ExactFraction.EIGHT
checkTerm(result, expectedCoeff)

term = Term.fromValues(ExactFraction.EIGHT, listOf(logNum1))
term = Term.fromValues(ExactFraction.EIGHT, listOf(log1))
result = simplify(term)
expectedCoeff = ExactFraction.EIGHT
expectedFactors = listOf(logNum1)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(logNum1))
expectedFactors = listOf(log1)
checkTerm(result, expectedCoeff, expectedFactors, logs = listOf(log1))

term = Term.fromValues(ExactFraction.EIGHT, listOf(Sqrt(ExactFraction(1, 46))))
result = simplify(term)
Expand All @@ -136,11 +136,11 @@ fun runCommonSimplifyTests(simplify: (Term) -> Term) {
expectedFactors = listOf(piInverse, testNumber1)
checkTerm(result, expectedCoeff, expectedFactors, pis = listOf(piInverse), piCount = -1)

term = Term.fromValues(ExactFraction.SEVEN, listOf(logNum1, logNum1, logNum2.inverse(), Sqrt(5), pi, pi))
term = Term.fromValues(ExactFraction.SEVEN, listOf(log1, log1, log2.inverse(), Sqrt(5), pi, pi))
result = simplify(term)
expectedCoeff = ExactFraction.SEVEN
expectedFactors = listOf(logNum1, logNum1, logNum2.inverse(), Sqrt(5), pi, pi)
logs = listOf(logNum1, logNum1, logNum2.inverse())
expectedFactors = listOf(log1, log1, log2.inverse(), Sqrt(5), pi, pi)
logs = listOf(log1, log1, log2.inverse())
pis = listOf(pi, pi)
checkTerm(result, expectedCoeff, expectedFactors, logs, listOf(Sqrt(5)), pis, 2)
}
Expand All @@ -160,15 +160,15 @@ fun runGetValueTests() {
assertEquals(expected, term.getValue())

// just logs
term = Term.fromValues(one, listOf(logNum1, logNum1.inverse()))
term = Term.fromValues(one, listOf(log1, log1.inverse()))
expected = BigDecimal.ONE
assertEquals(expected, term.getValue())

term = Term.fromValues(one, listOf(Log(3333)))
expected = BigDecimal("3.52283531366053")
assertEquals(expected, term.getValue())

term = Term.fromValues(one, listOf(logNum1, logNum2))
term = Term.fromValues(one, listOf(log1, log2))
expected = BigDecimal("0.61342218956802803344500481172832")
assertEquals(expected, term.getValue())

Expand Down
Loading

0 comments on commit 369e77b

Please sign in to comment.