예제 #1
0
 public virtual void TestContainsAll()
 {
     var a = new Item(42);
     var b = new Item(a.id + 1);
     var c = new Item(b.id + 1);
     var a_ = new Item(a.id);
     var needle = new Collection4();
     var haystack = new Collection4();
     haystack.Add(a);
     needle.Add(a);
     needle.Add(b);
     Assert.IsFalse(haystack.ContainsAll(needle));
     needle.Remove(b);
     Assert.IsTrue(haystack.ContainsAll(needle));
     needle.Add(b);
     haystack.Add(b);
     Assert.IsTrue(haystack.ContainsAll(needle));
     needle.Add(a_);
     Assert.IsTrue(haystack.ContainsAll(needle));
     needle.Add(c);
     Assert.IsFalse(haystack.ContainsAll(needle));
     needle.Clear();
     Assert.IsTrue(haystack.ContainsAll(needle));
     haystack.Clear();
     Assert.IsTrue(haystack.ContainsAll(needle));
 }
예제 #2
0
		public virtual void TestContains()
		{
			object a = new object();
			Collection4 c = new Collection4();
			c.Add(new object());
			Assert.IsFalse(c.Contains(a));
			c.Add(a);
			Assert.IsTrue(c.Contains(a));
			c.Remove(a);
			Assert.IsFalse(c.Contains(a));
		}
예제 #3
0
 public static void SameContent(IEnumerator expected, IEnumerator actual)
 {
     var allExpected = new Collection4(expected);
     while (actual.MoveNext())
     {
         var current = actual.Current;
         var removed = allExpected.Remove(current);
         if (!removed)
         {
             Unexpected(current);
         }
     }
     Assert.IsTrue(allExpected.IsEmpty(), "Still missing: " + allExpected);
 }
예제 #4
0
		public static void SameContent(IEnumerator expected, IEnumerator actual)
		{
			Collection4 allExpected = new Collection4();
			while (expected.MoveNext())
			{
				allExpected.Add(expected.Current);
			}
			while (actual.MoveNext())
			{
				object current = actual.Current;
				bool removed = allExpected.Remove(current);
				if (!removed)
				{
					Unexpected(current);
				}
			}
			Assert.IsTrue(allExpected.IsEmpty(), allExpected.ToString());
		}
		public Collection4 ForInterface(IReflectClass claxx)
		{
			Collection4 col = new Collection4();
			ClassMetadataIterator i = Iterator();
			while (i.MoveNext())
			{
				ClassMetadata clazz = i.CurrentClass();
				IReflectClass candidate = clazz.ClassReflector();
				if (!candidate.IsInterface())
				{
					if (claxx.IsAssignableFrom(candidate))
					{
						col.Add(clazz);
						IEnumerator j = new Collection4(col).GetEnumerator();
						while (j.MoveNext())
						{
							ClassMetadata existing = (ClassMetadata)j.Current;
							if (existing != clazz)
							{
								ClassMetadata higher = clazz.GetHigherHierarchy(existing);
								if (higher != null)
								{
									if (higher == clazz)
									{
										col.Remove(existing);
									}
									else
									{
										col.Remove(clazz);
									}
								}
							}
						}
					}
				}
			}
			return col;
		}
예제 #6
0
		public virtual void TestContainsAll()
		{
			Collection4TestCase.Item a = new Collection4TestCase.Item(42);
			Collection4TestCase.Item b = new Collection4TestCase.Item(a.id + 1);
			Collection4TestCase.Item c = new Collection4TestCase.Item(b.id + 1);
			Collection4TestCase.Item a_ = new Collection4TestCase.Item(a.id);
			Collection4 needle = new Collection4();
			Collection4 haystack = new Collection4();
			haystack.Add(a);
			needle.Add(a);
			needle.Add(b);
			Assert.IsFalse(haystack.ContainsAll(needle));
			needle.Remove(b);
			Assert.IsTrue(haystack.ContainsAll(needle));
			needle.Add(b);
			haystack.Add(b);
			Assert.IsTrue(haystack.ContainsAll(needle));
			needle.Add(a_);
			Assert.IsTrue(haystack.ContainsAll(needle));
			needle.Add(c);
			Assert.IsFalse(haystack.ContainsAll(needle));
			needle.Clear();
			Assert.IsTrue(haystack.ContainsAll(needle));
			haystack.Clear();
			Assert.IsTrue(haystack.ContainsAll(needle));
		}
예제 #7
0
		private void AssertNotContainsNull(Collection4 c)
		{
			Assert.IsFalse(c.Contains(null));
			Assert.IsNull(c.Get(null));
			int size = c.Size();
			c.Ensure(null);
			Assert.AreEqual(size + 1, c.Size());
			c.Remove(null);
			Assert.AreEqual(size, c.Size());
		}
예제 #8
0
		public virtual void TestNulls()
		{
			Collection4 c = new Collection4();
			c.Add("one");
			AssertNotContainsNull(c);
			c.Add(null);
			AssertContainsNull(c);
			AssertCollection(new string[] { "one", null }, c);
			c.Prepend(null);
			AssertCollection(new string[] { null, "one", null }, c);
			c.Prepend("zero");
			c.Add("two");
			AssertCollection(new string[] { "zero", null, "one", null, "two" }, c);
			AssertContainsNull(c);
			c.Remove(null);
			AssertCollection(new string[] { "zero", "one", null, "two" }, c);
			c.Remove(null);
			AssertNotContainsNull(c);
			AssertCollection(new string[] { "zero", "one", "two" }, c);
			c.Remove(null);
			AssertCollection(new string[] { "zero", "one", "two" }, c);
		}
			private bool Expect(IObjectContainer container, string[] names)
			{
				Collection4 expected = new Collection4(names);
				IObjectSet actual = container.Query(typeof(CrashSimulatingTestSuite.CrashData));
				while (actual.HasNext())
				{
					CrashSimulatingTestSuite.CrashData current = (CrashSimulatingTestSuite.CrashData)
						actual.Next();
					if (!expected.Remove(current._name))
					{
						return false;
					}
				}
				return expected.IsEmpty();
			}
		private void AssertEntries(PersistentEntry[] expected, IEnumerator actual)
		{
			Collection4 checklist = new Collection4(actual);
			Assert.AreEqual(expected.Length, checklist.Size());
			for (int i = 0; i < expected.Length; ++i)
			{
				PersistentEntry e = expected[i];
				PersistentEntry a = EntryByUid(checklist.GetEnumerator(), e.uid);
				if (a != null)
				{
					AssertEqualEntries(e, a);
					checklist.Remove(a);
				}
			}
			Assert.IsTrue(checklist.IsEmpty(), checklist.ToString());
		}
예제 #11
0
 private void AssertIterator(Hashtable4 table, object[] keys)
 {
     var iter = table.Iterator();
     var expected = new Collection4(keys);
     while (iter.MoveNext())
     {
         var entry = (IEntry4) iter.Current;
         var removedOK = expected.Remove(entry.Key());
         Assert.IsTrue(removedOK);
     }
     Assert.IsTrue(expected.IsEmpty(), expected.ToString());
 }