From cac67ec7d4eab68ca8ca026f0c535d455240dc38 Mon Sep 17 00:00:00 2001
From: Mirco Dotta <mirco.dotta@gmail.com>
Date: Sun, 12 Jul 2009 13:36:48 +0000
Subject: [PATCH] MapReducer need to use multisets for abstracting away order
 in lists. Now forAll properties does not fails anymore.

---
 tests/plugin/BST.scala                 |  4 ++--
 tests/plugin/kawaguchi/MapReduce.scala | 20 ++++++++++++++------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/tests/plugin/BST.scala b/tests/plugin/BST.scala
index f7a684e12..09ed9cb80 100644
--- a/tests/plugin/BST.scala
+++ b/tests/plugin/BST.scala
@@ -47,8 +47,8 @@ object BST extends Application {
   } 
 
   /** global assertions */
-  forAll[(BST,Int)]( p => contains(p._2,p._1) == content(p._1).contains(p._2))
-  forAll[(BST,Int)]( p => content(add(p._2, p._1)) == content(p._1) + p._2)
+  forAll{ p: (BST,Int) => contains(p._2,p._1) == content(p._1).contains(p._2)}
+  forAll{ p: (BST,Int) => content(add(p._2, p._1)) == content(p._1) + p._2}
   
 }
 
diff --git a/tests/plugin/kawaguchi/MapReduce.scala b/tests/plugin/kawaguchi/MapReduce.scala
index 97e2ddefb..beba264d6 100644
--- a/tests/plugin/kawaguchi/MapReduce.scala
+++ b/tests/plugin/kawaguchi/MapReduce.scala
@@ -5,19 +5,27 @@ package plugin.kawaguchi
 
 import funcheck.lib.Specs._
 
+import scala.collection.immutable.Multiset
+
 object MapReduce {
   
   /* specification */
-  def insert(map: Map[Int, List[Int]], entry: (Int, Int)): Map[Int, List[Int]] = {
+  def insert(map: Map[Int, Multiset[Int]], entry: (Int, Int)): Map[Int, Multiset[Int]] = {
     val (key,value) = entry
     map.get(key) match {
-      case None => map + ((key, List(value)))
-      case Some(vs) => map + ((key, value :: vs)) 
+      case None => map + ((key, Multiset(value)))
+      case Some(vs) => map + ((key, vs +++ List(value))) 
     }
   }
   
-  def content(kvs: List[(Int, List[Int])]) = 
-    Map.empty[Int, List[Int]] ++ (kvs)
+  def content(kvs: List[(Int, List[Int])]): Map[Int, Multiset[Int]] = 
+    (Map.empty[Int, Multiset[Int]] /: kvs) {
+      case (map,(key,values)) => 
+        (map /: values) {
+          case (map,v) => insert(map,(key,v))
+        }
+    } 
+    
     
   
   /*****************************************/
@@ -55,7 +63,7 @@ object MapReduce {
   def collapse(f: (Int,Int) => Int, gs: List[(Int, List[Int])]): List[(Int, Int)] = {
     val collapser = {
       x: (Int, List[Int]) => x match {
-        case (k, Nil) => assert(false); null
+        case (k, Nil) => error("cannot collapse")
         case (k, v :: vs)  => (k, vs.foldLeft(v)((z: Int,a: Int) => f(z,a)))  
        
       }
-- 
GitLab