Skip to content

Commit 7b64378

Browse files
committed
Update CforSuite for current Java 8 changes.
Use lower precision for native platform for NRootSuite
1 parent 4e3d7e7 commit 7b64378

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package spire.tests
2+
3+
object Platform {
4+
5+
final val isJVM = false
6+
final val isJS = true
7+
final val isNative = false
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package spire.tests
2+
3+
object Platform {
4+
5+
final val isJVM = true
6+
final val isJS = false
7+
final val isNative = false
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package spire.tests
2+
3+
object Platform {
4+
5+
final val isJVM = false
6+
final val isJS = false
7+
final val isNative = true
8+
9+
}

tests/shared/src/test/scala/spire/algebra/NRootSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class NRootSuite extends munit.FunSuite {
5656
}
5757
}
5858

59-
val HighPrecision = new java.math.MathContext(250)
59+
val HighPrecision = new java.math.MathContext(if (spire.tests.Platform.isNative) 150 else 250)
6060

6161
val bases = Seq(
6262
BigDecimal(2),

tests/shared/src/test/scala/spire/syntax/CforSuite.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class CforSuite extends munit.FunSuite {
3535
cfor(0)(_ < 10, _ + 1) { x =>
3636
cfor(10)(_ < 100, _ + 10) { y =>
3737
s.add(x + y)
38+
()
3839
}
3940
}
4041
assertEquals(s.toSet, (10 to 99).toSet)
4142
}
4243

4344
test("symbol collision cfor") {
4445
val b = mutable.ArrayBuffer.empty[Int]
45-
cfor(0)(_ < 3, _ + 1) { x =>
46+
cfor(0)(_ < 3, _ + 1) { _ =>
4647
cfor(0)(_ < 2, _ + 1) { y =>
4748
val x = y
4849
b += x
@@ -100,17 +101,21 @@ class CforSuite extends munit.FunSuite {
100101
}
101102

102103
test("capture value in closure") {
103-
val b1 = collection.mutable.ArrayBuffer.empty[() => Int]
104+
val capturedValues = collection.mutable.ArrayBuffer.empty[Int]
105+
val b1 = collection.mutable.ArrayBuffer.empty[() => Unit]
104106
cfor(0)(_ < 3, _ + 1) { x =>
105-
b1 += (() => x)
107+
val value = x // Explicitly define. Avoids failures on certain JDKs
108+
val closure = () => { capturedValues += value; () }
109+
b1 += closure
106110
}
107-
val b2 = collection.mutable.ArrayBuffer[() => Int]()
108-
var i = 0
109-
while (i < 3) {
110-
b2 += (() => i)
111-
i += 1
111+
b1.foreach(_.apply())
112+
113+
val b2 = collection.mutable.ArrayBuffer.empty[() => Int]
114+
cfor(0)(_ < 3, _ + 1) { i =>
115+
val value = i
116+
b2 += (() => value)
112117
}
113-
assertEquals(b1.map(_.apply()).toList, b2.map(_.apply()).toList)
118+
assertEquals(capturedValues.toList, b2.map(_.apply()).toList)
114119
}
115120

116121
test("capture value in inner class") {
@@ -168,7 +173,7 @@ class CforSuite extends munit.FunSuite {
168173

169174
test("cforRange(0 to 0 by -1)") {
170175
var t = 0
171-
cforRange(0 to 0 by -1) { x =>
176+
cforRange(0 to 0 by -1) { _ =>
172177
t += 1
173178
}
174179
assertEquals(t, 1)

0 commit comments

Comments
 (0)