Skip to content

Commit

Permalink
add ut and fix for string comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Nov 24, 2023
1 parent cf0c445 commit 453f96f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ object MathUtils {
case byteValue: Byte => byteValue >= 0
case shortValue: Short => shortValue >= 0
case charValue: Char => charValue >= 0
case _ => Try { o.toString.toDouble >= 0.0d }.isSuccess
case _ => try {
o.toString.toDouble >= 0.0d
} catch {
case _: Exception => false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kyuubi.util

// scalastyle:off

import org.apache.kyuubi.util.MathUtils.isNonNegativeNumber
import org.scalatest.funsuite.AnyFunSuite
// scalastyle:on

// scalastyle:off
class MathUtilsSuite extends AnyFunSuite {
// scalastyle:on
test("check non-negative number") {
assert(isNonNegativeNumber(0))
assert(isNonNegativeNumber(0L))
assert(isNonNegativeNumber(0.0f))
assert(isNonNegativeNumber(0.0d))
assert(isNonNegativeNumber(Long.MaxValue))
assert(!isNonNegativeNumber(Long.MinValue))
assert(isNonNegativeNumber(Double.MaxValue))
assert(!isNonNegativeNumber(Double.MinValue))
assert(isNonNegativeNumber(Float.MaxValue))
assert(!isNonNegativeNumber(Float.MinValue))

assert(isNonNegativeNumber("1"))
assert(isNonNegativeNumber("1.23"))
assert(!isNonNegativeNumber("-1"))
assert(!isNonNegativeNumber("-1.23"))
assert(isNonNegativeNumber(" 1"))
}
}

0 comments on commit 453f96f

Please sign in to comment.