diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-12 14:59:12 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-12 14:59:12 +0000 |
commit | c8ad9ef2d129e29c945ca86144b8ee875ad72a9b (patch) | |
tree | fa93109a58e0dee6833de77e7d9c885efa0b3363 /test/files/run/OrderingTest.scala | |
parent | e326df2c225eefcfd058e19963d3a7fdf366637d (diff) | |
download | scala-c8ad9ef2d129e29c945ca86144b8ee875ad72a9b.tar.gz scala-c8ad9ef2d129e29c945ca86144b8ee875ad72a9b.tar.bz2 scala-c8ad9ef2d129e29c945ca86144b8ee875ad72a9b.zip |
Test for default Ordering implementations.
Diffstat (limited to 'test/files/run/OrderingTest.scala')
-rw-r--r-- | test/files/run/OrderingTest.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/OrderingTest.scala b/test/files/run/OrderingTest.scala new file mode 100644 index 0000000000..2d60e5a451 --- /dev/null +++ b/test/files/run/OrderingTest.scala @@ -0,0 +1,31 @@ +object Test extends Application { + def test[T](t1 : T, t2 : T)(implicit ord : Ordering[T]) = { + val cmp = ord.compare(t1, t2); + val cmp2 = ord.compare(t2, t1); + + assert((cmp == 0) == (cmp2 == 0)) + assert((cmp > 0) == (cmp2 < 0)) + assert((cmp < 0) == (cmp2 > 0)) + } + + def testAll[T](t1 : T, t2 : T)(implicit ord : Ordering[T]) = { + assert(ord.compare(t1, t2) < 0) + test(t1, t2); + test(t1, t1); + test(t2, t2); + } + + assert(Ordering[String].compare("australopithecus", "brontausaurus") < 0) + assert(Ordering[Unit].compare((), ()) == 0) + + testAll("bar", "foo"); + testAll[Byte](0, 1); + testAll(false, true) + testAll(1, 2); + testAll(1.0, 2.0); + testAll(None, Some(1)); + testAll[Iterable[Int]](List(1), List(1, 2)); + testAll[Iterable[Int]](List(1, 2), List(2)); + testAll((1, "bar"), (1, "foo")) + testAll((1, "foo"), (2, "bar")) +} |