BVB Source Codes

Algorithm-Implementations Show BinarySearchTreeTests.cs Source code

Return Download Algorithm-Implementations: download BinarySearchTreeTests.cs Source code - Download Algorithm-Implementations Source code - Type:.cs
  1. 锘縰sing Microsoft.VisualStudio.TestTools.UnitTesting;
  2.  
  3. namespace JamLib.DataStructures.Trees.Tests
  4. {
  5.     [TestClass()]
  6.     public class BinarySearchTreeTests
  7.     {
  8.         [TestMethod()]
  9.         public void AddTest()
  10.         {
  11.             var bst = new BinarySearchTree<int>() { 10, 15, 5, 4, 7, 20, 14, 0, -5, -8, -2, -1 };
  12.             bst.Add(55);
  13.             bst.Add(-55);
  14.             bst.Add(35);
  15.  
  16.             // TODO: Dump as array then compare against expected array
  17.             Assert.IsTrue(bst.Contains(55), "Did not add element correctly");
  18.             Assert.IsTrue(bst.Contains(-55), "Did not add element correctly");
  19.             Assert.IsTrue(bst.Contains(35), "Did not add element correctly");
  20.         }
  21.  
  22.         [TestMethod()]
  23.         public void RemoveTest()
  24.         {
  25.             var bst = new BinarySearchTree<int>() { 10, 15, 5, 4, 7, 20, 14, 0, -5, -8, -2, -1 };
  26.             bst.Remove(20);
  27.             bst.Remove(0);
  28.             bst.Remove(10);
  29.  
  30.             // TODO: Dump as array then compare against expected array
  31.             Assert.IsFalse(bst.Contains(20), "Did not remove element correctly");
  32.             Assert.IsFalse(bst.Contains(0), "Did not remove element correctly");
  33.             Assert.IsFalse(bst.Contains(10), "Did not remove root element correctly");
  34.         }
  35.  
  36.         [TestMethod()]
  37.         public void ClearTest()
  38.         {
  39.             var bst = new BinarySearchTree<int>() { 10, 15, 5, 4, 7, 20, 14, 0, -5, -8, -2, -1 };
  40.             bst.Clear();
  41.             Assert.AreEqual(0, bst.Count, "Clearing the bst did not work");
  42.         }
  43.  
  44.         [TestMethod()]
  45.         public void ContainsTest()
  46.         {
  47.             var bst = new BinarySearchTree<int>() { 10, 15, 5, 4, 7, 20, 14, 0, -5, -8, -2, -1 };
  48.             Assert.IsTrue(bst.Contains(0), "Contain method could not find element");
  49.         }
  50.  
  51.         [TestMethod()]
  52.         public void CopyToTest()
  53.         {
  54.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  55.             int[] expected = new int[] { 5, 20, 25, 50, 66, 75, 80, 90, 92, 95, 111, 150, 166, 175, 200 };
  56.             int[] actual = new int[bst.Count];
  57.  
  58.             // Default is InOrder
  59.             bst.CopyTo(actual, 0);
  60.  
  61.             CollectionAssert.AreEqual(expected, actual, "Inorder bst traversal did not sort correctly");
  62.         }
  63.  
  64.         [TestMethod()]
  65.         public void CopyTo_PreOrder_Test()
  66.         {
  67.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  68.             int[] expected = new int[] { 90, 50, 20, 5, 25, 75, 66, 80, 150, 95, 92, 111, 175, 166, 200 };
  69.             int[] actual = new int[bst.Count];
  70.             bst.CopyTo(actual, 0, TraversalMethod.Preorder);
  71.  
  72.             CollectionAssert.AreEqual(expected, actual, "Preorder bst traversal did not sort correctly");
  73.         }
  74.  
  75.         [TestMethod()]
  76.         public void CopyTo_InOrder_Test()
  77.         {
  78.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  79.             int[] expected = new int[] { 5, 20, 25, 50, 66, 75, 80, 90, 92, 95, 111, 150, 166, 175, 200 };
  80.             int[] actual = new int[bst.Count];
  81.             bst.CopyTo(actual, 0, TraversalMethod.Inorder);
  82.  
  83.             CollectionAssert.AreEqual(expected, actual, "Inorder bst traversal did not sort correctly");
  84.         }
  85.  
  86.         [TestMethod()]
  87.         public void CopyTo_PostOrder_Test()
  88.         {
  89.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  90.             int[] expected = new int[] { 5, 25, 20, 66, 80, 75, 50, 92, 111, 95, 166, 200, 175, 150, 90 };
  91.             int[] actual = new int[bst.Count];
  92.             bst.CopyTo(actual, 0, TraversalMethod.Postorder);
  93.  
  94.             CollectionAssert.AreEqual(expected, actual, "Postorder bst traversal did not sort correctly");
  95.         }
  96.  
  97.         [TestMethod()]
  98.         public void GetEnumeratorTest()
  99.         {
  100.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  101.             int[] expected = new int[] { 5, 20, 25, 50, 66, 75, 80, 90, 92, 95, 111, 150, 166, 175, 200 };
  102.             var actual = new System.Collections.Generic.List<int>();
  103.  
  104.             // Iterate trough the collection, the default enumarator is InOrder
  105.             foreach (var value in bst) { actual.Add(value); }
  106.  
  107.             CollectionAssert.AreEqual(expected, actual, "Inorder bst traversal did not work correctly");
  108.         }
  109.  
  110.  
  111.         [TestMethod()]
  112.         public void GetEnumerator_PreOrder_Test()
  113.         {
  114.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  115.             int[] expected = new int[] { 90, 50, 20, 5, 25, 75, 66, 80, 150, 95, 92, 111, 175, 166, 200 };
  116.             var actual = new System.Collections.Generic.List<int>();
  117.  
  118.             // Iterate trough the collection, the default enumarator is InOrder
  119.             foreach (var value in bst.Preorder) { actual.Add(value); }
  120.  
  121.             CollectionAssert.AreEqual(expected, actual, "Preorder bst traversal did not work correctly");
  122.         }
  123.  
  124.         [TestMethod()]
  125.         public void GetEnumerator_InOrder_Test()
  126.         {
  127.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  128.             int[] expected = new int[] { 5, 20, 25, 50, 66, 75, 80, 90, 92, 95, 111, 150, 166, 175, 200 };
  129.             var actual = new System.Collections.Generic.List<int>();
  130.  
  131.             // Iterate trough the collection, the default enumarator is InOrder
  132.             foreach (var value in bst.Inorder) { actual.Add(value); }
  133.  
  134.             CollectionAssert.AreEqual(expected, actual, "Inorder bst traversal did not work correctly");
  135.         }
  136.  
  137.         [TestMethod()]
  138.         public void GetEnumerator_PostOrder_Test()
  139.         {
  140.             var bst = new BinarySearchTree<int>() { 90, 50, 150, 20, 75, 95, 175, 5, 25, 66, 80, 92, 111, 166, 200 };
  141.             int[] expected = new int[] { 5, 25, 20, 66, 80, 75, 50, 92, 111, 95, 166, 200, 175, 150, 90 };
  142.             var actual = new System.Collections.Generic.List<int>();
  143.  
  144.             // Iterate trough the collection, the default enumarator is InOrder
  145.             foreach (var value in bst.Postorder) { actual.Add(value); }
  146.  
  147.             CollectionAssert.AreEqual(expected, actual, "Postorder bst traversal did not work correctly");
  148.         }
  149.     }
  150. }
  151.  
downloadBinarySearchTreeTests.cs Source code - Download Algorithm-Implementations Source code
Related Source Codes/Software:
raty - 2017-04-22
RDVTabBarController - Highly customizable tabBar and tabBarController fo... 2017-04-22
material-icon-lib - Library containing over 1500 material vector icons... 2017-04-21
httpdiff - Perform the same request against two HTTP servers ... 2017-04-21
jquerytools - The missing UI library for the Web ... 2017-04-21
mcrouter - Mcrouter is a memcached protocol router for scalin... 2017-04-22
dynomite - A generic dynamo implementation for different k-v ... 2017-04-22
kityminder - Baidu brain figure 2017-04-22
llvm - Mirror of official llvm git repository located at ... 2017-04-22
RBBAnimation - Block-based animations made easy, comes with easin... 2017-04-22
ied - 2017-04-29
Nimble - A Matcher Framework for Swift and Objective-C 2017-04-29
MHVideoPhotoGallery - A Photo and Video Gallery 2017-04-29
shoulda-matchers - Collection of testing matchers extracted from Shou... 2017-04-29
Android-SlideExpandableListView - A better ExpandableListView, with animated expanda... 2017-04-29
AppSales-Mobile - App Sales allows iPhone and Mac App Store develope... 2017-04-29
react-templates - Light weight templates for react ... 2017-04-28
afterglow-theme - A minimal dark Theme for Sublime Text 2 and 3 2017-04-28
jwt-go - Golang implementation of JSON Web Tokens (JWT) 2017-04-28
DeerResume - Tool MarkDown online resume, online preview, edit,... 2017-04-28

 Back to top