From 915b4d5e2a05db250c6de8ccda94821db96673d2 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 26 May 2011 22:24:26 -0400 Subject: [PATCH] forgot a test --- util/collection/src/test/scala/KeyTest.scala | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 util/collection/src/test/scala/KeyTest.scala diff --git a/util/collection/src/test/scala/KeyTest.scala b/util/collection/src/test/scala/KeyTest.scala new file mode 100644 index 000000000..9ac4f86bb --- /dev/null +++ b/util/collection/src/test/scala/KeyTest.scala @@ -0,0 +1,35 @@ +package sbt + + import org.scalacheck._ + import Prop._ + +object KeyTest extends Properties("AttributeKey") +{ + property("equality") = { + compare(AttributeKey[Int]("test"), AttributeKey[Int]("test"), true) && + compare(AttributeKey[Int]("test"), AttributeKey[Int]("test", "description"), true) && + compare(AttributeKey[Int]("test", "a"), AttributeKey[Int]("test", "b"), true) && + compare(AttributeKey[Int]("test"), AttributeKey[Int]("tests"), false) && + compare(AttributeKey[Int]("test"), AttributeKey[Double]("test"), false) && + compare(AttributeKey[java.lang.Integer]("test"), AttributeKey[Int]("test"), false) && + compare(AttributeKey[Map[Int, String]]("test"), AttributeKey[Map[Int, String]]("test"), true) && + compare(AttributeKey[Map[Int, String]]("test"), AttributeKey[Map[Int, _]]("test"), false) + } + + def compare(a: AttributeKey[_], b: AttributeKey[_], same: Boolean) = + ("a.label: " + a.label) |: + ("a.manifest: " + a.manifest) |: + ("b.label: " + b.label) |: + ("b.manifest: " + b.manifest) |: + ("expected equal? " + same) |: + compare0(a, b, same) + + def compare0(a: AttributeKey[_], b: AttributeKey[_], same: Boolean) = + if(same) + { + ("equality" |: (a == b)) && + ("hash" |: (a.hashCode == b.hashCode)) + } + else + ("equality" |: (a != b)) +} \ No newline at end of file