summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorNiko Vuokko <niko.vuokko@gmail.com>2015-06-06 01:50:53 +0300
committerNiko Vuokko <niko.vuokko@gmail.com>2015-06-17 15:48:02 +0300
commit8e0bc0bffd31d994a6911116f170347004934c55 (patch)
tree5981ebbdfb39309d7a5d9caf146b4fb663151a7e /test/junit
parent43a56fb5a1b6450ce2bdf8f73ab30ca1b16d0778 (diff)
downloadscala-8e0bc0bffd31d994a6911116f170347004934c55.tar.gz
scala-8e0bc0bffd31d994a6911116f170347004934c55.tar.bz2
scala-8e0bc0bffd31d994a6911116f170347004934c55.zip
SI-9348 Fix missing last element in exclusive floating point ranges
Fix exclusive floating point ranges to contain also the last element when the end-start difference is not an integer multiple of step.
Diffstat (limited to 'test/junit')
-rw-r--r--test/junit/scala/collection/immutable/RangeConsistencyTest.scala11
-rw-r--r--test/junit/scala/math/NumericTest.scala28
2 files changed, 38 insertions, 1 deletions
diff --git a/test/junit/scala/collection/immutable/RangeConsistencyTest.scala b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
index 3980c31577..135796979d 100644
--- a/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
+++ b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
@@ -137,4 +137,15 @@ class RangeConsistencyTest {
assert( (-3 to Int.MaxValue).dropWhile(_ <= 0).length == Int.MaxValue )
assert( (-3 to Int.MaxValue).span(_ <= 0) match { case (a,b) => a.length == 4 && b.length == Int.MaxValue } )
}
+
+ @Test
+ def testSI9348() {
+ // Test exclusive range with (end-start) != 0 (mod step)
+ assert( (0.0f until 0.4f by 0.25f) sameElements List(0.0f, 0.25f) )
+ assert( (1.0 until 2.2 by 0.5) sameElements List(1.0, 1.5, 2.0) )
+
+ def bd(d: Double) = BigDecimal(d)
+ val bdRange = bd(-10.0) until bd(0.0) by bd(4.5)
+ assert( bdRange sameElements List(bd(-10.0), bd(-5.5), bd(-1.0)) )
+ }
}
diff --git a/test/junit/scala/math/NumericTest.scala b/test/junit/scala/math/NumericTest.scala
index 9bf7d4f1e4..682dcbfd75 100644
--- a/test/junit/scala/math/NumericTest.scala
+++ b/test/junit/scala/math/NumericTest.scala
@@ -5,6 +5,9 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import scala.math.Numeric.FloatAsIfIntegral
+
+
@RunWith(classOf[JUnit4])
class NumericTest {
@@ -14,5 +17,28 @@ class NumericTest {
assertTrue(-0.0.abs equals 0.0)
assertTrue(-0.0f.abs equals 0.0f)
}
-}
+
+ /* Test for SI-9348 */
+ @Test
+ def testFloatAsIfIntegral {
+ val num = scala.math.Numeric.FloatAsIfIntegral
+ assertTrue(num.quot(1.0f, 0.5f) equals 2.0f)
+ assertTrue(num.quot(1.0f, 0.3f) equals 3.0f)
+ }
+
+ /* Test for SI-9348 */
+ @Test
+ def testDoubleAsIfIntegral {
+ val num = scala.math.Numeric.DoubleAsIfIntegral
+ assertTrue(num.quot(1.0, 0.25) equals 4.0)
+ assertTrue(num.quot(0.5, 0.15) equals 3.0)
+ }
+
+ /* Test for SI-9348 */
+ @Test
+ def testBigDecimalAsIfIntegral {
+ val num = scala.math.Numeric.BigDecimalAsIfIntegral
+ assertTrue(num.quot(BigDecimal(2.5), BigDecimal(0.5)) equals BigDecimal(5.0))
+ assertTrue(num.quot(BigDecimal(5.0), BigDecimal(2.0)) equals BigDecimal(2.0))
+ }}