public void TestBinarySearch_WithNonExistingItem()
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });

            var result = collection.LinearSearch(-11);
            Assert.AreNotEqual(true, result);
        }
Ejemplo n.º 2
0
        private void LoadShippingMethods(Order o)
        {
            var rates = new SortableCollection <ShippingRateDisplay>();

            if (!o.HasShippingItems)
            {
                var r = new ShippingRateDisplay
                {
                    DisplayName         = GlobalLocalization.GetString("NoShippingRequired"),
                    ProviderId          = string.Empty,
                    ProviderServiceCode = string.Empty,
                    Rate             = 0,
                    ShippingMethodId = "NOSHIPPING"
                };
                rates.Add(r);
            }
            else
            {
                // Shipping Methods
                rates = HccApp.OrderServices.FindAvailableShippingRates(o);

                if (rates.Count < 1)
                {
                    var result = new ShippingRateDisplay();
                    result.DisplayName      = GlobalLocalization.GetString("ToBeDetermined");
                    result.ShippingMethodId = "TOBEDETERMINED";
                    result.Rate             = 0;
                    rates.Add(result);
                }
            }

            litShippingMethods.Text = HtmlRendering.ShippingRatesToRadioButtons(rates, 300, o.ShippingMethodUniqueKey);
        }
Ejemplo n.º 3
0
    static void Main()
    {
        var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });

        Console.WriteLine("All items before sorting:");
        Console.WriteLine(collection);

        Console.WriteLine("SelectionSorter result:");
        collection.Sort(new SelectionSorter <int>());
        Console.WriteLine(collection);

        Console.WriteLine("Quicksorter result:");
        collection.Sort(new Quicksorter <int>());
        Console.WriteLine(collection);

        Console.WriteLine("MergeSorter result:");
        collection.Sort(new MergeSorter <int>());
        Console.WriteLine(collection);

        Console.WriteLine("Linear search 101:");
        Console.WriteLine(collection.LinearSearch(101));

        Console.WriteLine("Binary search 101:");
        Console.WriteLine(collection.BinarySearch(101));

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        Console.WriteLine(collection);

        Console.WriteLine("Shuffle again:");
        collection.Shuffle();
        Console.WriteLine(collection);
    }
        public void TestSelectionSortingWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new SelectionSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting");
        }
        public void TestLinearSearchWithExistingElementInMiddlePositionOddCountOfElements()
        {
            var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0, 17 });
            var result = collection.LinearSearch(22);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 6
0
        public void TestSortWithMultipleRandomElements()
        {
            for (int i = 0; i < NumberOfTests; i++)
            {
                int numberOfElements = Random.Next(MinNumberOfElementsToSort, MaxNumberOfElementsToSort + 1);
                int maxValue         = Random.Next(MaxValueCeiling);

                int[] elements = new int[numberOfElements];

                for (int j = 0; j < numberOfElements; j++)
                {
                    elements[j] = Random.Next(maxValue);
                }

                var collection = new SortableCollection <int>(elements);
                collection.Sort(new BucketSorter {
                    Max = maxValue
                });

                Array.Sort(elements);
                /*collection.Sort(new BucketSorter { Max = maxValue });*/

                CollectionAssert.AreEqual(elements, collection.ToArray());
            }
        }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);

            collectionToSort.Sort(new BucketSorter { Max = MaxValue });
            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
            Console.WriteLine(collection);

            collection.Shuffle();
            Console.WriteLine(collection);

            //collection.Sort(new Quicksorter<int>());
            //Console.WriteLine(collection);
        }
Ejemplo n.º 8
0
        public static void Main()
        {
            List<int> numbers = new List<int>() {1,3,4,6,7,8,9,10,23,42};

            SortableCollection<int> sortableCollection = new SortableCollection<int>(numbers);
            Console.WriteLine(sortableCollection.BinarySearch(-12));
        }
Ejemplo n.º 9
0
        public void TestWithASingleItemNotFound()
        {
            SortableCollection<int> collection = new SortableCollection<int>(new int[] { 6 });

            bool isFound = collection.LinearSearch(4);
            Assert.IsFalse(isFound);
        }
Ejemplo n.º 10
0
        public void TestWithMultipleItemsNotFound()
        {
            SortableCollection<int> collection = new SortableCollection<int>(new int[] { 4, 11, -3, 7, 9, 23 });

            bool isFound = collection.LinearSearch(235);
            Assert.IsFalse(isFound);
        }
Ejemplo n.º 11
0
 public void InitMethod()
 {
     collection = new SortableCollection <int>(new List <int>()
     {
         4, 6, 1, 9, 21, 34, 54, 5, 23
     });
 }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            // !!!!!!!!!!!!!! collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);

            Console.WriteLine(collection.InterpolationSearch(0));
        }
Ejemplo n.º 13
0
        public void Test_UpgradedSelectionSorter_ShouldThrowExceptionWhenCollectionIsNull()
        {
            var sorter          = new UpgradedSelectionSorter <int>();
            var emptyCollection = new SortableCollection <int>(null);

            emptyCollection.Sort(sorter);
        }
        public void BinarySearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection <int>();
            var found      = collection.BinarySearch(21);

            Assert.IsFalse(found, "Element is found in empty collection!");
        }
Ejemplo n.º 15
0
 public void SelectionSorterTestWithOneElement()
 {
     SortableCollection<int> collection = new SortableCollection<int>(new int[] { 5 });
     collection.Sort(new SelectionSorter<int>());
     Assert.AreEqual(1, collection.Items.Count);
     Assert.AreEqual(5, collection.Items[0]);
 }
Ejemplo n.º 16
0
        public void TestWithMultipleMissingKeysSmallerThanMinimum()
        {
            const int NumberOfChecks = 10000;
            const int NumberOfElements = 1000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
            }

            Array.Sort(elements);

            var collection = new SortableCollection<int>(elements);

            for (int i = 0; i < NumberOfChecks; i++)
            {
                var item = Random.Next(int.MinValue, collection.Items[0]);

                int result = collection.InterpolationSearch(item);

                Assert.AreEqual(-1, result);
            }
        }
Ejemplo n.º 17
0
        public void TestWithMultipleKeys()
        {
            const int NumberOfElements = 10000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(-100, 100);
            }

            Array.Sort(elements);

            var collection = new SortableCollection <int>(elements);

            foreach (var element in elements)
            {
                /* this test returns the right result, just a different index than
                 * what the binary search would return, I don't think that there is an Array.InterpolationSearch
                 * otherwise, I think that there's nothing wrong with my algorithm*/
                int expected = Array.BinarySearch(elements, element);
                int result   = collection.InterpolationSearch(element);

                Assert.AreEqual(expected, result);
            }
        }
        public void TestLinearSearchWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            var result = collection.LinearSearch(101);

            Assert.IsFalse(result, "Element found in empty collection");
        }
Ejemplo n.º 19
0
        private void LoadShippingMethods(Order o)
        {
            SortableCollection <ShippingRateDisplay> Rates = new SortableCollection <ShippingRateDisplay>();

            if (o.HasShippingItems == false)
            {
                ShippingRateDisplay r = new ShippingRateDisplay();
                r.DisplayName         = SiteTerms.GetTerm(SiteTermIds.NoShippingRequired);
                r.ProviderId          = "";
                r.ProviderServiceCode = "";
                r.Rate             = 0;
                r.ShippingMethodId = "NOSHIPPING";
                Rates.Add(r);
            }
            else
            {
                // Shipping Methods

                Rates = MTApp.OrderServices.FindAvailableShippingRates(o);

                if ((Rates.Count < 1))
                {
                    ShippingRateDisplay result = new ShippingRateDisplay();
                    result.DisplayName      = "Shipping can not be calculated at this time. We will contact you after receiving your order with the exact shipping charges.";
                    result.ShippingMethodId = "TOBEDETERMINED";
                    result.Rate             = 0;
                    Rates.Add(result);
                }
            }

            this.litShippingMethods.Text = MerchantTribe.Commerce.Utilities.HtmlRendering.ShippingRatesToRadioButtons(Rates, 300, o.ShippingMethodUniqueKey);
        }
Ejemplo n.º 20
0
        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("Quicksorter result:");
            collection.Sort(new QuickSorter<int>());
            collection.PrintAllItemsOnConsole();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101) + Environment.NewLine);

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101) + Environment.NewLine);

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
Ejemplo n.º 21
0
 public void Test1SectionSortMethod()
 {
     var collection = new SortableCollection<int>(new[] { 22, 13 });
     collection.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { 13, 22 });
     Assert.Equals(collection,testCollection);
 }
Ejemplo n.º 22
0
        public void TestWithMultipleMissingKeysLargerThanMaximum()
        {
            const int NumberOfChecks   = 10000;
            const int NumberOfElements = 1000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
            }

            Array.Sort(elements);

            var collection = new SortableCollection <int>(elements);

            for (int i = 0; i < NumberOfChecks; i++)
            {
                var item = Random.Next(collection.Items[collection.Count - 1], int.MaxValue);

                int result = collection.InterpolationSearch(item);

                Assert.AreEqual(-1, result);
            }
        }
Ejemplo n.º 23
0
 public void Test2SectionSortMethod()
 {
     var collection1 = new SortableCollection<int>(new[] { 22, 13, 23, 45, -55, 90, 100, 101, -12, 55, 44 });
     collection1.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
        public void TestBinarySearchWithExistingElementInLastPositionOddCountOfElements()
        {
            var collection = new SortableCollection <int>(new[] { 49, 101, 33, 22, 11, 0, 17 });
            var result     = collection.BinarySearch(17);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 25
0
 public void Test3SectionSortMethod()
 {
     var collection1 = new SortableCollection<string>(new[] { "aaaa", "cccc", "dddd", "cccc", "caaa", "aacc", "bbdd", "ccff", "eerr", "rrtt", "assdd" });
     collection1.Sort(new SelectionSorter<string>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
        public void TestLinearSearch_WithMatchingItemOfDifferentType()
        {
            var collection = new SortableCollection<double>(new[] { 22d, 11.0d, 101d, 33d, 0d, 101d });

            var result = collection.LinearSearch(11u);
            Assert.AreEqual(true, result);
        }
        public void TestBinarySearchWithExistingElementInMiddlePositionEvenCountOfElements()
        {
            var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0 });
            var result = collection.BinarySearch(33);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 28
0
        public void TestShouldnotFindValue()
        {
            var col = new SortableCollection <int>(new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 });

            col.Sort(new MergeSorter <int>());
            Assert.IsFalse(col.LinearSearch(99));
        }
Ejemplo n.º 29
0
        public SortableCollection <Activity> Search(ActivitySearchParams searchParams,
                                                    bool addFlowIsNullQuery, bool includeActivityEntries)
        {
            SortableCollection <Activity> list = null;
            List <object> whereValues;

            string sql = ConstructJDBCSearchSql(searchParams, addFlowIsNullQuery, out whereValues);

            DoJDBCQueryWithRowCallbackDelegate(sql, whereValues,
                                               delegate(IDataReader reader)
            {
                if (list == null)
                {
                    list = new SortableCollection <Activity>();
                }
                Activity activity = MapActivity(reader);
                list.Add(activity);
            });

            if (includeActivityEntries)
            {
                PostMapActivityEntries(list);
            }
            return(list);
        }
Ejemplo n.º 30
0
        public static void Main()
        {
            List<int> numbers = new List<int>() { 1,3,5,6,7,3,32,3,5,67,7,4,34,3};

            SortableCollection<int> collection = new SortableCollection<int>(numbers);
            Console.WriteLine(collection.LinearSearch(7));
        }
        public void TestLinearSearchWithExistingElementInLastPositionEvenCountOfElements()
        {
            var collection = new SortableCollection <int>(new[] { 49, 101, 33, 22, 11, 0 });
            var result     = collection.LinearSearch(0);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 32
0
        public void InsertionSorterTestWithEmptyCollection()
        {
            SortableCollection <int> collection = new SortableCollection <int>();

            collection.Sort(new InsertionSorter <int>());
            Assert.AreEqual(0, collection.Items.Count);
        }
Ejemplo n.º 33
0
        public void ShouldSortCorrectlyCharacters()
        {
            var collection = new SortableCollection <char>(new[] { 'a', 'c', 'b' });

            collection.Sort(new Quicksorter <char>());
            CollectionAssert.AreEqual(new[] { 'a', 'b', 'c' }, collection.Items.ToArray());
        }
        public void MergeSortShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new MergeSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting!");
        }
Ejemplo n.º 35
0
        public void SearchValueFoundInUnsortedCollection()
        {
            var  collection = new SortableCollection <int>(new[] { 14, 1, 3, -4, 10, 5 });
            bool actual     = collection.LinearSearch(3);

            Assert.IsTrue(actual);
        }
        public void TestLinearSearchWithCollectionOfEqualElements()
        {
            var collection = new SortableCollection<int>(new[] { 101, 101, 101, 101, 101 });
            var result = collection.LinearSearch(101);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 37
0
        public void SearchValueNotFoundInSortedCollection()
        {
            var  collection = new SortableCollection <int>(new[] { -4, 1, 3, 5, 10, 14 });
            bool actual     = collection.LinearSearch(33);

            Assert.IsFalse(actual);
        }
        public void TestLinearSearchWithExistingElementInFirstPositionEvenCountOfElements()
        {
            var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0 });
            var result = collection.LinearSearch(49);

            Assert.IsTrue(result, "Element not found");
        }
        public void BinarySearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            var found = collection.BinarySearch(21);

            Assert.IsFalse(found, "Element is found in empty collection!");
        }
        public void TestLinearSearchWithExistingRepeatingElementInCollection()
        {
            var collection = new SortableCollection<int>(new[] { 101, 101, 33, 22, 11, 0 });
            var result = collection.LinearSearch(101);

            Assert.IsTrue(result, "Element not found");
        }
        public void TestBinarySearchWithExistingRepeatingElementInCollection()
        {
            var collection = new SortableCollection <int>(new[] { 101, 101, 33, 22, 11, 0 });
            var result     = collection.BinarySearch(101);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 42
0
        public void TestSortWithMultipleElementsMultipleTimes()
        {
            const int NumberOfAttempts = 10000;
            const int MaxNumberOfElements = 1000;

            for (int i = 0; i < NumberOfAttempts; i++)
            {
                var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);

                List<int> originalElements = new List<int>(MaxNumberOfElements);

                for (int j = 0; j < numberOfElements; j++)
                {
                    originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
                }

                var collection = new SortableCollection<int>(originalElements);

                originalElements.Sort();
                collection.Sort(TestSorter);

                CollectionAssert.AreEqual(
                    originalElements,
                    collection.ToArray(),
                    "Sort method should sort the elements in ascending order.");
            }
        }
        public void TestBinarySearchWithCollectionOfEqualElements()
        {
            var collection = new SortableCollection <int>(new[] { 101, 101, 101, 101, 101 });
            var result     = collection.BinarySearch(101);

            Assert.IsTrue(result, "Element not found");
        }
Ejemplo n.º 44
0
        public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
        {
            var collection = new SortableCollection <int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
            var result     = collection.InterpolationSearch(3);

            Assert.AreEqual(4, result);
        }
        public void TestBinarySearchWithEmptyCollection()
        {
            var collection = new SortableCollection <int>();
            var result     = collection.BinarySearch(101);

            Assert.IsFalse(result, "Element found in empty collection");
        }
Ejemplo n.º 46
0
        public void TestSortWithMultipleElementsMultipleTimes()
        {
            const int NumberOfAttempts    = 10000;
            const int MaxNumberOfElements = 1000;

            for (int i = 0; i < NumberOfAttempts; i++)
            {
                var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);

                List <int> originalElements = new List <int>(MaxNumberOfElements);

                for (int j = 0; j < numberOfElements; j++)
                {
                    originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
                }

                var collection = new SortableCollection <int>(originalElements);

                originalElements.Sort();
                collection.Sort(TestSorter);

                CollectionAssert.AreEqual(
                    originalElements,
                    collection.ToArray(),
                    "Sort method should sort the elements in ascending order.");
            }
        }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collectionToShuffle = new SortableCollection<int>(1, 2, 3, 4, 5);
            Console.WriteLine("Before shufflin` " + collectionToShuffle);
            collectionToShuffle.Shuffle();
            Console.WriteLine("After shufflin` " + collectionToShuffle);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);
        }
        public void SearchValueFoundInSortedCollection()
        {
            var  collection = new SortableCollection <int>(new[] { -4, 1, 3, 5, 10, 14 });
            bool actual     = collection.BinarySearch(3);

            Assert.IsTrue(actual);
        }
Ejemplo n.º 49
0
    static void Main()
    {
        var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
        Console.WriteLine("All items before sorting:");
        Console.WriteLine(collection);

        Console.WriteLine("SelectionSorter result:");
        collection.Sort(new SelectionSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Quicksorter result:");
        collection.Sort(new Quicksorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("MergeSorter result:");
        collection.Sort(new MergeSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Linear search 101:");
        Console.WriteLine(collection.LinearSearch(101));

        Console.WriteLine("Binary search 101:");
        Console.WriteLine(collection.BinarySearch(101));

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        Console.WriteLine(collection);

        Console.WriteLine("Shuffle again:");
        collection.Shuffle();
        Console.WriteLine(collection);
    }
Ejemplo n.º 50
0
        public void BinarySearchNotFoundTest()
        {
            var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });
            var actual     = collection.BinarySearch(5);

            Assert.AreEqual(false, actual);
        }
Ejemplo n.º 51
0
        public void BinarySearchFoundPositionAtEndTest()
        {
            var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });
            var actual     = collection.BinarySearch(22);

            Assert.AreEqual(true, actual);
        }
Ejemplo n.º 52
0
        public void LinearSearchFoundTest()
        {
            var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });
            var actual     = collection.LinearSearch(33);

            Assert.AreEqual(true, actual);
        }
Ejemplo n.º 53
0
        public void BinarySearchNullTest()
        {
            var    collection = new SortableCollection <string>(new[] { "da", "ne" });
            string word       = null;

            collection.BinarySearch(word);
        }
        private void initViewChart(bool forceRefresh)
        {
            string       cacheKey     = "3C26BAC7-1D53-40ef-920B-5BDB705F363B";
            CacheWrapper cacheWrapper = Cache[cacheKey] as CacheWrapper;

            if (forceRefresh || (cacheWrapper == null))
            {
                SortableCollection <KeyValuePair <ICatalogable, int> > categoryViews = PageViewDataSource.GetViewsByCategory(_Size, 0, "ViewCount DESC");
                if (categoryViews.Count > 0)
                {
                    //BUILD BAR CHART
                    ViewsChart.Series["Views"].Points.Clear();
                    for (int i = 0; i < categoryViews.Count; i++)
                    {
                        DataPoint point = new DataPoint(ViewsChart.Series["Views"]);
                        point.SetValueXY(categoryViews[i].Key.Name, new object[] { categoryViews[i].Value });
                        ViewsChart.Series["Views"].Points.Add(point);
                    }
                    ViewsChart.DataBind();

                    //CACHE THE DATA
                    cacheWrapper = new CacheWrapper(categoryViews);
                    Cache.Remove(cacheKey);
                    Cache.Add(cacheKey, cacheWrapper, null, LocaleHelper.LocalNow.AddMinutes(5).AddSeconds(-1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
                }
                else
                {
                    //NO CATEGORIES HAVE BEEN VIEWED YET OR PAGE TRACKING IS NOT AVAIALBEL
                    this.Controls.Clear();
                    Panel noViewsPanel = new Panel();
                    noViewsPanel.CssClass = "emptyData";
                    Label noViewsMessage = new Label();
                    noViewsMessage.Text = "No categories have been viewed or page tracking is disabled.";
                    noViewsPanel.Controls.Add(noViewsMessage);
                    this.Controls.Add(noViewsPanel);
                }
            }
            else
            {
                //USE CACHED VALUES
                SortableCollection <KeyValuePair <ICatalogable, int> > categoryViews = (SortableCollection <KeyValuePair <ICatalogable, int> >)cacheWrapper.CacheValue;
                //BUILD BAR CHART
                ViewsChart.Series["Views"].Points.Clear();
                for (int i = 0; i < categoryViews.Count; i++)
                {
                    DataPoint point = new DataPoint(ViewsChart.Series["Views"]);
                    point.SetValueXY(categoryViews[i].Key.Name, new object[] { categoryViews[i].Value });
                    ViewsChart.Series["Views"].Points.Add(point);
                }
                ViewsChart.DataBind();

                ViewsGrid.DataSource = categoryViews;
                ViewsGrid.DataBind();
            }
            DateTime cacheDate = (cacheWrapper != null) ? cacheWrapper.CacheDate : LocaleHelper.LocalNow;

            CacheDate1.Text = string.Format(CacheDate1.Text, cacheDate);
            CacheDate2.Text = string.Format(CacheDate2.Text, cacheDate);
        }
        public void TestSortingOnSixPositiveNumbers()
        {
            var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 5, 101 });

            collection.Sort(new SelectionSorter <int>());

            Assert.AreEqual(true, this.AreElementsEqual(collection));
        }
        public void TestSortingOnSixNegativeNumbers()
        {
            var collection = new SortableCollection <int>(new[] { -22, -11, -101, -33, -5, -101 });

            collection.Sort(new SelectionSorter <int>());

            Assert.AreEqual(true, this.AreElementsEqual(collection));
        }
        public void TestLinearSearch_ItemNotFound()
        {
            int[] numbers = new int[] { 1, 76, -205, 17, 90, 22 };
            SortableCollection<int> collection = new SortableCollection<int>(numbers);
            bool numberFound = collection.LinearSearch(8);

            Assert.AreEqual(false, numberFound);
        }
        public void TestBinarySearch_ItemEqualToMaximum()
        {
            int[] sortedNumbers = new int[] { 1, 5, 7, 9, 22 };
            SortableCollection<int> collection = new SortableCollection<int>(sortedNumbers);
            bool numberFound = collection.BinarySearch(22);

            Assert.AreEqual(true, numberFound);
        }
        public void TestBinarySearch_ItemGreaterThanMaximum()
        {
            int[] sortedNumbers = new int[] { 1, 5, 7, 9, 22 };
            SortableCollection<int> collection = new SortableCollection<int>(sortedNumbers);
            bool numberFound = collection.BinarySearch(30);

            Assert.AreEqual(false, numberFound);
        }
        public void TestLinearSearch_ItemFound()
        {
            int[] numbers = new int[] { 11, 54, -7, 19, -22 };
            SortableCollection<int> collection = new SortableCollection<int>(numbers);
            bool numberFound = collection.LinearSearch(-7);

            Assert.AreEqual(true, numberFound);
        }