コード例 #1
0
        public void TestRandomTripleArraySorting()
        {
            const int len = 0x1 << 10;
            SystemRandomSource random = new SystemRandomSource();

            int[] keys = new int[len];
            int[] items1 = new int[len];
            int[] items2 = new int[len];
            int[] keysCopy = new int[len];

            for(int i = 0; i < keys.Length; i++)
            {
                keys[i] = random.Next();
                keysCopy[i] = keys[i];
                items1[i] = -keys[i];
                items2[i] = keys[i] >> 2;
            }

            Sorting.Sort(keys, items1, items2);

            for(int i = 1; i < keys.Length; i++)
            {
                Assert.That(keys[i] >= keys[i - 1], "Sort Order - " + i.ToString());
                Assert.That(items1[i], Is.EqualTo(-keys[i]), "Items1 Permutation - " + i.ToString());
                Assert.That(items2[i], Is.EqualTo(keys[i] >> 2), "Items2 Permutation - " + i.ToString());
            }

            for(int i = 0; i < keysCopy.Length; i++)
            {
                Assert.That(Array.IndexOf(keys, keysCopy[i]) >= 0, "All keys still there - " + i.ToString());
            }
        }
コード例 #2
0
        public void TestRandomTupleListSorting()
        {
            const int len = 0x1 << 10;
            SystemRandomSource random = new SystemRandomSource();

            List<int> keys = new List<int>(len);
            List<int> items = new List<int>(len);
            int[] keysCopy = new int[len];

            for(int i = 0; i < len; i++)
            {
                int value = random.Next();
                keys.Add(value);
                keysCopy[i] = value;
                items.Add(-value);
            }

            Sorting.Sort(keys, items);

            for(int i = 1; i < len; i++)
            {
                Assert.IsTrue(keys[i] >= keys[i - 1], "Sort Order - " + i.ToString());
                Assert.AreEqual(-keys[i], items[i], "Items Permutation - " + i.ToString());
            }
            for(int i = 0; i < keysCopy.Length; i++)
            {
                Assert.IsTrue(keys.IndexOf(keysCopy[i]) >= 0, "All keys still there - " + i.ToString());
            }
        }
コード例 #3
0
        public void TestRandomTupleArraySorting()
        {
            const int len = 0x1 << 10;
            SystemRandomSource random = new SystemRandomSource();

            int[] keys = new int[len];
            int[] items = new int[len];
            int[] keysCopy = new int[len];

            for(int i = 0; i < keys.Length; i++)
            {
                keys[i] = random.Next();
                keysCopy[i] = keys[i];
                items[i] = -keys[i];
            }

            Sorting.Sort(keys, items);

            for(int i = 1; i < keys.Length; i++)
            {
                Assert.IsTrue(keys[i] >= keys[i - 1], "Sort Order - " + i.ToString());
                Assert.AreEqual(-keys[i], items[i], "Items Permutation - " + i.ToString());
            }
            for(int i = 0; i < keysCopy.Length; i++)
            {
                Assert.IsTrue(Array.IndexOf(keys, keysCopy[i]) >= 0, "All keys still there - " + i.ToString());
            }
        }
コード例 #4
0
        public void TestAppliedSetSorting()
        {
            const int len = 0x1 << 10;
            SystemRandomSource random = new SystemRandomSource();

            Set<int> set = new Set<int>();

            for(int i = 0; i < len; i++)
            {
                set.Add(random.Next());
            }

            // default sorting (Ascending)
            set.Sort();

            // just check that the order is as expected, not that the items are correct
            for(int i = 1; i < set.Count; i++)
            {
                Assert.That(set[i] >= set[i - 1], "Sort Order - " + i.ToString());
            }
        }