当前位置: 首页>>代码示例>>C#>>正文


C# Tree.LessThan方法代码示例

本文整理汇总了C#中Tree.LessThan方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.LessThan方法的具体用法?C# Tree.LessThan怎么用?C# Tree.LessThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree.LessThan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NonFullRootNodeTest

		public void NonFullRootNodeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default),
				allowDuplicateKeys: true);

			tree.Insert (1, "1");

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (1, (from node in tree.LessThan(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(1) select node).FirstOrDefault().Item1);
			Assert.AreEqual (0, (from node in tree.LessThan(1) select node).Count());

			tree.Insert (5, "5");
			tree.Insert (9, "9");

			// 1,5,9

			Assert.IsTrue ((from node in tree.LessThanOrEqualTo(9) select node.Item1).SequenceEqual(new int[] { 9, 5, 1 }));
			Assert.IsTrue ((from node in tree.LessThan(9) select node.Item1).SequenceEqual(new int[] { 5, 1 }));
			Assert.IsTrue ((from node in tree.LargerThanOrEqualTo(5) select node.Item1).SequenceEqual(new int[] { 5, 9 }));
			Assert.IsTrue ((from node in tree.LargerThan(5) select node.Item1).SequenceEqual(new int[] { 9 }));


			Assert.DoesNotThrow(delegate {
				tree.Insert (5, "5.1");
			});

			// Iterating test
			var found = (from node in tree.LargerThanOrEqualTo(5) select node.Item2).ToList ();
			Assert.AreEqual (3, found.Count);
			Assert.IsTrue (found.Contains("5.1"));
			Assert.IsTrue (found.Contains("5"));
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:35,代码来源:BTreeNonUniqueTest.cs

示例2: NonFullRootNodeTest

		public void NonFullRootNodeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			tree.Insert (1, "1");

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (1, (from node in tree.LessThan(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(1) select node).FirstOrDefault().Item1);
			Assert.AreEqual (0, (from node in tree.LessThan(1) select node).Count());

			tree.Insert (5, "2");
			tree.Insert (9, "9");

			// 1,5,9

			Assert.IsTrue ((from node in tree.LessThanOrEqualTo(9) select node.Item1).SequenceEqual(new int[] { 9, 5, 1 }));
			Assert.IsTrue ((from node in tree.LessThan(9) select node.Item1).SequenceEqual(new int[] { 5, 1 }));
			Assert.IsTrue ((from node in tree.LargerThanOrEqualTo(5) select node.Item1).SequenceEqual(new int[] { 5, 9 }));
			Assert.IsTrue ((from node in tree.LargerThan(5) select node.Item1).SequenceEqual(new int[] { 9 }));


			Assert.Throws<TreeKeyExistsException>(delegate {
				tree.Insert (9, "9");
			});
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:28,代码来源:BTreeTest.cs

示例3: SplitRootNodeTest

		public void SplitRootNodeTest ()
		{
			// Insert too much at root node that it overvlow
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			tree.Insert (0, "00");
			tree.Insert (1, "11");
			tree.Insert (2, "22");
			tree.Insert (3, "33");
			tree.Insert (4, "44");

			// Validate the tree
			Assert.IsNull (tree.Get(8));
			Assert.IsNull (tree.Get(-1));
			Assert.IsNull (tree.Get(99));

			Assert.NotNull (tree.Get (0));
			Assert.NotNull (tree.Get (1));
			Assert.NotNull (tree.Get (2));
			Assert.NotNull (tree.Get (3));
			Assert.NotNull (tree.Get (4));

			Assert.IsTrue ((from tpl in tree.LargerThanOrEqualTo(4) select tpl.Item1).SequenceEqual(new int[]{ 4 }));
			Assert.IsTrue ((from tpl in tree.LargerThan(1) select tpl.Item1).SequenceEqual(new int[]{ 2, 3, 4 }));
			Assert.IsTrue ((from tpl in tree.LessThan(3) select tpl.Item1).SequenceEqual(new int[]{ 2,1,0 }));
			Assert.IsTrue ((from tpl in tree.LessThanOrEqualTo(3) select tpl.Item1).SequenceEqual(new int[]{ 3, 2,1,0 }));
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:27,代码来源:BTreeTest.cs

示例4: EmptyTreeTest

		public void EmptyTreeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LessThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LessThanOrEqualTo(7) select node).Count());

		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:10,代码来源:BTreeTest.cs

示例5: BreakNodeTest

		public void BreakNodeTest ()
		{
			// Generate a random sequence
			var seq = new List<double>();
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++) {
				seq.Add (rnd.Next(0, 10));
			}

			// Start inserting
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default),
				allowDuplicateKeys: true
			);
			foreach (var t in seq) {
				tree.Insert (t, t.ToString());
			}

			// Test 1
			{
				var keys = (from t in tree.LargerThanOrEqualTo(0) select t.Item1).ToArray();
				Assert.AreEqual (seq.Count, keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, seq), OccurencesInList(key, keys));
				}
			}

			// Test 2
			{
				var keys = (from t in tree.LargerThanOrEqualTo(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t >= 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t >= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 3
			{
				var keys = (from t in tree.LargerThan(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t > 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t > 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 4
			{
				var keys = (from t in tree.LargerThanOrEqualTo(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t >= 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t >= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 5
			{
				var keys = (from t in tree.LargerThan(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t > 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t > 7.5 select t), OccurencesInList(key, keys));
				}
			}

			// Test 6
			{
				var keys = (from t in tree.LessThan(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t < 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t < 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 7
			{
				var keys = (from t in tree.LessThan(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t < 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t < 7.5 select t), OccurencesInList(key, keys));
				}
			}

			// Test 8
			{
				var keys = (from t in tree.LessThanOrEqualTo(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t <= 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t <= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 9
			{
				var keys = (from t in tree.LessThanOrEqualTo(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t <= 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t <= 7.5 select t), OccurencesInList(key, keys));
				}
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:99,代码来源:BTreeNonUniqueTest.cs

示例6: RandomTest

		public void RandomTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			// Generate a random sequence
			var seq = new List<int>();
			var rnd = new Random (198);

			// Insert random sequence 
			for (var i = 0; i < 1000; i++)
			{
				var n = rnd.Next (0, 2000);
				while (seq.Contains(n) == true) {
					n = rnd.Next (0, 2000);
				}

				tree.Insert (n, n.ToString());
				seq.Add (n);
			}

			// Validate result
			var sortedSeq = seq.FindAll (t => true);
			sortedSeq.Sort (Comparer<int>.Default);
			Assert.IsTrue (sortedSeq.SequenceEqual(from tuple in tree.LargerThanOrEqualTo(0) select tuple.Item1));

			// Randomly query
			for (var n = 0; n <= 100; n++)
			{
				var number = n = rnd.Next (0, 2000);
				var lastD = 0;
				foreach (var d in from tuple in tree.LargerThanOrEqualTo(number) select tuple.Item1)
				{
					Assert.IsTrue (d >= number);
					Assert.IsTrue (d > lastD);
					lastD = d;
				}


				lastD = 0;
				foreach (var d in from tuple in tree.LargerThan(number) select tuple.Item1)
				{
					Assert.IsTrue (d > number);
					Assert.IsTrue (d > lastD);
					lastD = d;
				}

				lastD = 999999;
				foreach (var d in from tuple in tree.LessThan(number) select tuple.Item1)
				{
					Assert.IsTrue (d < number);
					Assert.IsTrue (d < lastD);
					lastD = d;
				}

				lastD = 999999;
				foreach (var d in from tuple in tree.LessThanOrEqualTo(number) select tuple.Item1)
				{
					Assert.IsTrue (d <= number);
					Assert.IsTrue (d < lastD);
					lastD = d;
				}
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:63,代码来源:BTreeTest.cs


注:本文中的Tree.LessThan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。