Skip to content

Instantly share code, notes, and snippets.

@non
Created July 29, 2015 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save non/3dcc7a1bf86fea973a94 to your computer and use it in GitHub Desktop.
Save non/3dcc7a1bf86fea973a94 to your computer and use it in GitHub Desktop.
Test demonstrating possible scala.js/algebra bug.
package algebra
package laws
import org.scalatest.FunSuite
class AdHocTest extends FunSuite {
test("literal ops") {
val x0 = -2147483648
val y0 = 2147483647
assert(x0 < y0)
assert(x0 <= y0)
assert(x0 != y0)
assert(y0 > x0)
assert(y0 >= x0)
assert(y0 != x0)
}
val x = -2147483648
val y = 2147483647
test("direct ops") {
assert(x < y)
assert(x <= y)
assert(x != y)
assert(y > x)
assert(y >= x)
assert(y != x)
}
val o = algebra.std.int.intAlgebra
test("std ops") {
assert(o.lt(x, y))
assert(o.lteqv(x, y))
assert(o.neqv(x, y))
assert(o.gt(y, x))
assert(o.gteqv(y, x))
assert(o.neqv(y, x))
}
object p extends Order[Int] {
def compare(x: Int, y: Int): Int = x compare y
}
test("compare-based ops") {
assert(p.lt(x, y))
assert(p.lteqv(x, y))
assert(p.neqv(x, y))
assert(p.gt(y, x))
assert(p.gteqv(y, x))
assert(p.neqv(y, x))
}
object q extends Order[Int] {
def compare(x: Int, y: Int): Int = x compare y
override def eqv(x: Int, y: Int) = x == y
override def neqv(x: Int, y: Int) = x != y
override def gt(x: Int, y: Int) = x > y
override def gteqv(x: Int, y: Int) = x >= y
override def lt(x: Int, y: Int) = x < y
override def lteqv(x: Int, y: Int) = x <= y
}
test("custom ops") {
assert(q.lt(x, y))
assert(q.lteqv(x, y))
assert(q.neqv(x, y))
assert(q.gt(y, x))
assert(q.gteqv(y, x))
assert(q.neqv(y, x))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment