Skip to content

Commit

Permalink
chore: var renames, use method in test
Browse files Browse the repository at this point in the history
  • Loading branch information
lbressler13 committed Jan 23, 2024
1 parent a5b611b commit f02a2c6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ internal class ExactFractionImpl private constructor(numerator: BigInteger, deno

override fun inverse(): ExactFraction {
return when {
numerator.isZero() -> throw divideByZero
numerator.isNegative() -> ExactFractionImpl(-denominator, -numerator, fullySimplified = true)
isZero() -> throw divideByZero
isNegative() -> ExactFractionImpl(-denominator, -numerator, fullySimplified = true)
else -> ExactFractionImpl(denominator, numerator, fullySimplified = true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xyz.lbres.exactnumbers.exactfraction

/**
* [ArithmeticException] for ExactFraction overflow.
* Has field for value of string that caused overflow.
* Has field for string of value that caused overflow.
*/
class ExactFractionOverflowException() : ArithmeticException() {
override var message: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.math.MathContext
import java.math.RoundingMode

/**
* Simplify a numerator and denominator values to smallest values with same ratio, and move all negatives into numerator
* Simplify numerator and denominator values to smallest values with same ratio, and move all negatives into numerator
*
* @param numerator [BigInteger]: numerator of fraction to simplify
* @param denominator [BigInteger]: denominator of fraction to simplify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ internal fun parseDecimal(s: String): ExactFraction {
val decimalIndex = rawDecimalString.indexOf('.')
val decimalString = rawDecimalString.substring(decimalIndex + 1) // starts from 0 if decimalIndex == -1

val zeros = "0".repeat(decimalString.length)
val denomString = "1$zeros"
val denomZeroes = "0".repeat(decimalString.length)
val denomString = "1$denomZeroes"

val denominator = BigInteger(denomString)
val numerator = whole * denominator + BigInteger(decimalString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import xyz.lbres.exactnumbers.exactfraction.ExactFraction
import xyz.lbres.exactnumbers.irrationals.IrrationalNumber
import xyz.lbres.kotlinutils.collection.ext.toConstMultiSet
import xyz.lbres.kotlinutils.general.simpleIf
import xyz.lbres.kotlinutils.set.multiset.anyConsistent
import xyz.lbres.kotlinutils.set.multiset.const.ConstMultiSet
import xyz.lbres.kotlinutils.set.multiset.const.ConstMutableMultiSet
import xyz.lbres.kotlinutils.set.multiset.const.constMutableMultiSetOf
Expand Down Expand Up @@ -41,9 +40,8 @@ sealed class Log : IrrationalNumber<Log>() {
*/
// TODO: improve simplification by looking at bases
internal fun simplifySet(numbers: ConstMultiSet<Log>): Pair<ExactFraction, ConstMultiSet<Log>> {
when {
numbers.isEmpty() -> return Pair(ExactFraction.ONE, emptyConstMultiSet())
numbers.anyConsistent(Log::isZero) -> return Pair(ExactFraction.ZERO, emptyConstMultiSet())
if (numbers.isEmpty()) {
return Pair(ExactFraction.ONE, emptyConstMultiSet())
}

val simplifiedNumbers = numbers.mapToSetConsistent { it.getSimplified() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ExactFractionTest {
@Test fun testIsWholeNumber() = runIsWholeNumberTests()

// parsing + toString
@Test fun testIsEFString() = runCommonCheckEFStringTests { ExactFraction.isEFString(it) }
@Test fun testIsEFString() = runCommonCheckEFStringTests(ExactFraction.Companion::isEFString)
@Test fun testToDecimalString() = runToDecimalStringTests()
@Test fun testToFractionString() = runToFractionStringTests()
@Test fun testToPairString() = runToPairStringTests()
Expand Down

0 comments on commit f02a2c6

Please sign in to comment.