예제 #1
0
		public static void Test(){
			const int Count = 1*1000;

			var treap = new Treap<int>();
			Assert.AreEqual(treap.Count, 0);

			var rand = new Random(1);
			var items = Enumerable.Range(0, Count *2).Select(n=> rand.Next()).Distinct().Take(Count).ToArray();


			for(int i=0;i<items.Length;i++){
				treap.Add(items[i]);
				Assert.AreEqual(i+1, treap.Count);
				for(int j= 0;j<=i;j++)
					Assert.IsTrue(treap.Contains(items[j]));
			}
			Assert.LessOrEqual(treap.Count, Count);

			var x = treap.First();
			int count =1;
			foreach(var item in treap.Skip(1)){
				Assert.Greater(item, x);
				x = item;
				count++;
			}
			Assert.AreEqual(count, treap.Count);

			foreach(var item in items){
				int v;
				Assert.IsTrue(treap.TryGetValue(item, out v));
				Assert.AreEqual(item, v);
			}

			count = treap.Count;
			for(int i=0;i<items.Length;i++){
				treap.Remove(items[i]);
				count--;

				Assert.AreEqual(count, treap.Count);
				for(int j= 0;j<=i;j++)
					Assert.IsFalse(treap.Contains(items[j]));
			}

		}