Skip to content

Commit

Permalink
update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Dec 1, 2023
1 parent fab49e1 commit 58991ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ object MathUtils {
case byteValue: Byte => byteValue > 0
case shortValue: Short => shortValue > 0
case charValue: Char => charValue > 0
case stringValue: String => stringValue.toDouble >= 0.0d
case stringValue: String => stringValue.toDouble > 0.0d
}
} catch {
case t: Throwable =>
throw new IllegalArgumentException(s"Cannot check if $o is a positive number.", t)
throw new IllegalArgumentException(s"Cannot check if '$o' is a positive number.", t)
}

/**
Expand All @@ -55,6 +55,6 @@ object MathUtils {
}
} catch {
case t: Throwable =>
throw new IllegalArgumentException(s"Cannot check if $o is a non-negative number.", t)
throw new IllegalArgumentException(s"Cannot check if '$o' is a non-negative number.", t)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.apache.kyuubi.util

import org.scalatest.funsuite.AnyFunSuite

import org.apache.kyuubi.util.AssertionUtils._
import org.apache.kyuubi.util.MathUtils._
// scalastyle:on

Expand All @@ -46,12 +47,15 @@ class MathUtilsSuite extends AnyFunSuite {
assert(!isPositiveNumber("-1.23"))
assert(isPositiveNumber(" 1"))
assert(isPositiveNumber(" 1.23 "))
assert(!isPositiveNumber(" 1. 23 "))
assert(!isPositiveNumber(" 1. 23 abc "))
assert(isPositiveNumber(1.123456789012345678901234567890123456789012345678901234567890d))
assert(!isPositiveNumber(-1.123456789012345678901234567890123456789012345678901234567890d))
assert(isPositiveNumber("1.123456789012345678901234567890123456789012345678901234567890"))
assert(!isPositiveNumber("-1.123456789012345678901234567890123456789012345678901234567890"))

Seq(" 1. 23 ", " 1. 23 abc ").foreach { str =>
interceptContains[IllegalArgumentException](isPositiveNumber(str))(
s"Cannot check if '$str' is a positive number.")
}
}

test("check non-negative number") {
Expand All @@ -73,11 +77,14 @@ class MathUtilsSuite extends AnyFunSuite {
assert(!isNonNegativeNumber("-1.23"))
assert(isNonNegativeNumber(" 1"))
assert(isNonNegativeNumber(" 1.23 "))
assert(!isNonNegativeNumber(" 1. 23 "))
assert(!isNonNegativeNumber(" 1. 23 abc "))
assert(isNonNegativeNumber(1.123456789012345678901234567890123456789012345678901234567890d))
assert(!isNonNegativeNumber(-1.123456789012345678901234567890123456789012345678901234567890d))
assert(isNonNegativeNumber("1.123456789012345678901234567890123456789012345678901234567890"))
assert(!isNonNegativeNumber("-1.123456789012345678901234567890123456789012345678901234567890"))

Seq(" 1. 23 ", " 1. 23 abc ").foreach { str =>
interceptContains[IllegalArgumentException](isNonNegativeNumber(str))(
s"Cannot check if '$str' is a non-negative number.")
}
}
}

0 comments on commit 58991ad

Please sign in to comment.