]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListFunctions.scl
Improvement of index and group implementations and indexGroup(By)
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / ListFunctions.scl
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListFunctions.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ListFunctions.scl
new file mode 100644 (file)
index 0000000..e842381
--- /dev/null
@@ -0,0 +1,40 @@
+import "Prelude"
+main = do
+    print $ [1,2] \\ []
+    print $ [1,2,3] \\ [1]
+    print $ [1,2,3] \\ [2]
+    print $ [1,2,3] \\ [2,3]
+--
+[1, 2]
+[2, 3]
+[1, 3]
+[1]
+()    
+--
+import "Prelude"
+
+assertEquals :: Show a => a -> a -> <Proc> ()
+assertEquals a b = if a == b then () else fail "\(a) <> \(b)"
+
+testGrouping outVal f l = do
+    kl = map (\v -> (f v, v)) l
+    groups = group kl
+    print groups
+    
+    assertEquals groups (groupBy f l)
+    
+    i1 = fromMaybe [] . index groups
+    i2 = indexGroup kl
+    i3 = indexGroupBy f l
+    
+    keys = map fst groups + [outVal]
+    
+    for keys $ \k -> do 
+        assertEquals (i1 k) (i2 k)
+        assertEquals (i1 k) (i3 k)
+
+main = do
+    testGrouping 4 (`mod` 3) [2,4,6,8,10]
+--
+[(2, [2, 8]), (1, [4, 10]), (0, [6])]
+()
\ No newline at end of file