[svn] r6162: nemerle/trunk/lib/tests: Makefile heap.n set.n
nazgul
svnadmin at nemerle.org
Sat Mar 25 14:27:14 CET 2006
Log:
Make Heap and Set implement ICollection[T]
Author: nazgul
Date: Sat Mar 25 14:27:12 2006
New Revision: 6162
Added:
nemerle/trunk/lib/tests/set.n (contents, props changed)
Modified:
nemerle/trunk/lib/tests/Makefile
nemerle/trunk/lib/tests/heap.n
Modified: nemerle/trunk/lib/tests/Makefile
==============================================================================
--- nemerle/trunk/lib/tests/Makefile (original)
+++ nemerle/trunk/lib/tests/Makefile Sat Mar 25 14:27:12 2006
@@ -4,7 +4,7 @@
EXECUTE = $(NET_ENGINE) $(NET_FLAGS)
THISDIR = $(shell if cygpath --help 2>/dev/null 1>&2; then echo `cygpath -m $(CURDIR)`; else echo $(CURDIR); fi)
-UNIT_SRC = linkedlist.n list.n
+UNIT_SRC = linkedlist.n list.n heap.n set.n
############################################################
# TARGETS
Modified: nemerle/trunk/lib/tests/heap.n
==============================================================================
--- nemerle/trunk/lib/tests/heap.n (original)
+++ nemerle/trunk/lib/tests/heap.n Sat Mar 25 14:27:12 2006
@@ -2,7 +2,62 @@
using Nemerle.Collections;
using Nemerle.Collections.List;
using Nemerle.IO;
+using SCG = System.Collections.Generic;
+#if NUNIT
+using NUnit.Framework;
+
+[TestFixture]
+public class HeapTest : Assertion
+{
+ mutable heap : Heap [int];
+
+ [SetUp]
+ public Init () : void {
+ heap = Heap (0);
+ }
+
+ [Test]
+ public Clear () : void
+ {
+ heap.Add (4);
+ heap.Add (1);
+ heap.Add (10);
+ AssertEquals (3, heap.Count);
+ Assert.IsFalse (heap.IsEmpty);
+ heap.Clear ();
+ AssertEquals (0, heap.Count);
+ Assert (heap.IsEmpty);
+ }
+
+ [Test]
+ public EnumerableInit () : void
+ {
+ heap = Heap ([4, 1, 10]);
+ AssertEquals (3, heap.Count);
+ AssertEquals (10, heap.Top());
+ }
+
+ [Test]
+ public Enumerable () : void
+ {
+ def li = SCG.List ();
+ heap = Heap ([6,2,7,31,1]);
+ foreach (x in heap)
+ li.Add (x);
+ AssertEquals (5, li.Count);
+ Assert (li.Contains (31));
+ Assert (li.Contains (7));
+ Assert (li.Contains (6));
+ }
+
+ [Test] [ExpectedException (typeof(System.NotSupportedException))]
+ public RemoveNotSupported () : void {
+ heap.Add (1);
+ _ = (heap : SCG.ICollection [int]).Remove (1);
+ }
+}
+#else
public class M {
private static abs(n : int) : int
{
@@ -88,6 +143,7 @@
printf("[%d errors]\n",errors);
}
}
+#endif
/*
BEGIN-OUTPUT
Added: nemerle/trunk/lib/tests/set.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/lib/tests/set.n Sat Mar 25 14:27:12 2006
@@ -0,0 +1,77 @@
+using Nemerle.Collections;
+using Nemerle.Collections.List;
+using Nemerle.IO;
+using SCG = System.Collections.Generic;
+
+#if NUNIT
+using NUnit.Framework;
+
+[TestFixture]
+public class SetTest : Assertion
+{
+ mutable set : Set [int];
+
+ [Test]
+ public EnumerableInit () : void
+ {
+ def li = SCG.List ();
+ li.Add (12);
+ li.Add (435);
+ li.Add (33);
+ set = Set (li);
+ Assert (set.Contains (435));
+ AssertEquals (3, set.Count);
+ }
+
+ [Test]
+ public ForEachSizes () : void
+ {
+ forEachTester (array [33]);
+ forEachTester (array [62, 0]);
+ forEachTester (array [677, 3, -1]);
+ forEachTester (array [343, 2, 44, 132, 1, 4]);
+ forEachTester (array [3, 45, 222, 1, 2343, 55, 111]);
+ forEachTester (array [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]);
+ forEachTester (array [-1, 23, 3454, 22, 3344, 2, 4543, 567, 876, 52, 12312, 454, -2123, 445443]);
+ }
+
+ private forEachTester (init : array [int]) : void
+ {
+ def convert = SCG.List ();
+ set = Set (init);
+ foreach (x in set)
+ convert.Add (x);
+ AssertEquals (set.Count, convert.Count);
+ AssertEquals (init.Length, convert.Count);
+ for (mutable i = 1; i < convert.Count; i++)
+ Assert (convert [i - 1] < convert [i]);
+ foreach (y in init)
+ Assert (convert.Contains (y));
+ }
+
+ [Test]
+ public ForEachEmpty () : void
+ {
+ def convert = SCG.List ();
+ set = Set ();
+ foreach (x in set)
+ convert.Add (x);
+ AssertEquals (0, convert.Count);
+ AssertEquals (0, set.Count);
+ }
+
+ [Test]
+ public CopyTo() : void
+ {
+ set = Set ([43, 4, 657]);
+ def arr = array (3);
+ set.CopyTo (arr, 0);
+ AssertEquals (4, arr [0]);
+ AssertEquals (43, arr [1]);
+ AssertEquals (657, arr [2]);
+ }
+
+}
+#else
+()
+#endif
\ No newline at end of file
More information about the svn
mailing list