예제 #1
0
        public void TestInstantiation()
        {
            var testInstance = new SimpleArray();

            Assert.Equal(4, testInstance.GroceryList.Length);
            Assert.Equal("Bread", testInstance.GroceryList[0]);
        }
예제 #2
0
        public static void Sort()
        {
            SimpleArray array = new SimpleArray();

            int[] quick = { 2, 4, 1, 6, 7, 5, 3 };
            array.QuickSort(quick);
            for (int i = 0; i < quick.Length; i++)
            {
                Assert.That(quick[i] == i + 1);
            }

            int[] quick1 = { 2, 4, 8, 6, 7, 5, 3, 1 };
            array.QuickSort(quick1);
            for (int i = 0; i < quick1.Length; i++)
            {
                Assert.That(quick1[i] == i + 1);
            }

            int[] merge = { 2, 4, 1, 6, 7, 5, 3 };
            array.MergeSort(merge);
            for (int i = 0; i < merge.Length; i++)
            {
                Assert.That(merge[i] == i + 1);
            }

            int[] merge1 = { 2, 4, 8, 6, 7, 5, 3, 1 };
            array.MergeSort(merge1);
            for (int i = 0; i < merge1.Length; i++)
            {
                Assert.That(merge1[i] == i + 1);
            }
        }
예제 #3
0
 public static void RotateCycle()
 {
     int[] orig = { 5, -1000 };
     int[] rotate = { -1000, 5 };
     int[] result = SimpleArray.RotateCycle(orig, 1);            
     Assert.That(rotate.SequenceEqual(result));
 }
예제 #4
0
        public static void BinarySearch()
        {
            int[] array = { 1, 2, 3, 4, 5 };
            Assert.That(SimpleArray.BinarySearch(array, 5) == 4);
            Assert.That(SimpleArray.BinarySearch(array, 6) == -1);
            Assert.That(SimpleArray.BinarySearch(array, 2) == 1);

            int[] array1 = { 0, 1 };
            Assert.That(SimpleArray.BinarySearch(array1, 0) == 0);
            Assert.That(SimpleArray.BinarySearch(array1, 1) == 1);

            array = new int[] { 5, 7, 7, 8, 8, 10 };
            Assert.That(SimpleArray.FindCount(array, 8) == 2);

            Assert.That(SimpleArray.Sqrt(16) == 4);
            Assert.That(SimpleArray.Sqrt(10) == 3);
            Assert.That(SimpleArray.Sqrt(1) == 1);
            Assert.That(SimpleArray.Sqrt(0) == 0);
            Assert.That(SimpleArray.Sqrt(-1) == 0);
            Assert.That(SimpleArray.Sqrt(2147483647) == 46340);
            Assert.That(SimpleArray.Sqrt(930675566) == 30506);
        }
예제 #5
0
        public void TestToString()
        {
            var testInstance = new SimpleArray();

            Assert.StartsWith("There are", testInstance.ToString());
        }