/// <summary>
        /// MemberData to be passed to tests that take an IEnumerable{T}. This method returns every permutation of
        /// EnumerableType to test on (e.g. HashSet, Queue), and size of set to test with (e.g. 0, 1, etc.).
        /// </summary>
        public static IEnumerable <object[]> EnumerableTestData()
        {
            foreach (object[] collectionSizeArray in ValidCollectionSizes())
            {
                foreach (EnumerableType enumerableType in Enum2.GetValues(typeof(EnumerableType)))
                {
                    int count = (int)collectionSizeArray[0];
                    yield return(new object[] { enumerableType, count, 0, 0, 0 });                       // Empty Enumerable

                    yield return(new object[] { enumerableType, count, count + 1, 0, 0 });               // Enumerable that is 1 larger

                    if (count >= 1)
                    {
                        yield return(new object[] { enumerableType, count, count, 0, 0 });               // Enumerable of the same size

                        yield return(new object[] { enumerableType, count, count - 1, 0, 0 });           // Enumerable that is 1 smaller

                        yield return(new object[] { enumerableType, count, count, 1, 0 });               // Enumerable of the same size with 1 matching element

                        yield return(new object[] { enumerableType, count, count + 1, 1, 0 });           // Enumerable that is 1 longer with 1 matching element

                        yield return(new object[] { enumerableType, count, count, count, 0 });           // Enumerable with all elements matching

                        yield return(new object[] { enumerableType, count, count + 1, count, 0 });       // Enumerable with all elements matching plus one extra
                    }

                    if (count >= 2)
                    {
                        yield return(new object[] { enumerableType, count, count - 1, 1, 0 });           // Enumerable that is 1 smaller with 1 matching element

                        yield return(new object[] { enumerableType, count, count + 2, 2, 0 });           // Enumerable that is 2 longer with 2 matching element

                        yield return(new object[] { enumerableType, count, count - 1, count - 1, 0 });   // Enumerable with all elements matching minus one

                        yield return(new object[] { enumerableType, count, count, 2, 0 });               // Enumerable of the same size with 2 matching element

                        if ((enumerableType == EnumerableType.List || enumerableType == EnumerableType.Queue))
                        {
                            yield return new object[] { enumerableType, count, count, 0, 1 }
                        }
                        ;                                                                               // Enumerable with 1 element duplicated
                    }

                    if (count >= 3)
                    {
                        if ((enumerableType == EnumerableType.List || enumerableType == EnumerableType.Queue))
                        {
                            yield return new object[] { enumerableType, count, count, 0, 1 }
                        }
                        ;                                                                               // Enumerable with all elements duplicated
                        yield return(new object[] { enumerableType, count, count - 1, 2, 0 });          // Enumerable that is 1 smaller with 2 matching elements
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void MultipleWorkItemsMultiplePriorities()
        {
            // Get all the available priorities
            WorkItemPriority[] priorities = Enum2.GetValues(typeof(WorkItemPriority)).Cast <WorkItemPriority> ().ToArray();

            // Create an array of priority items
            PriorityItem[] priorityItems = new PriorityItem[priorities.Length];

            // Create a priority item for each priority
            int i = priorities.Length;

            foreach (WorkItemPriority workItemPriority in priorities)
            {
                --i;
                priorityItems[i] = new PriorityItem(workItemPriority);
            }

            // Create a PermutationGenerator for the priority items
            PermutationGenerator permutations = new PermutationGenerator(priorityItems);

            int count = 0;

            // Iterate over the permutations
            foreach (object[] permutation in permutations)
            {
                ++count;
                //Console.Write ("Permutation #" + count + " : ");
                for (int j = 0; j < permutation.Length; ++j)
                {
                    PriorityItem pi = permutation[j] as PriorityItem;
                    //Console.Write (pi.WorkItemPriority + ", ");
                }
                //Console.WriteLine ();
                // Create a priority queue
                PriorityQueue pq = new PriorityQueue();

                // Enqueue each priority item according to the permutation
                for (i = 0; i < permutation.Length; ++i)
                {
                    PriorityItem priorityItem = permutation[i] as PriorityItem;
                    pq.Enqueue(priorityItem);
                }

                // Make sure all the priority items are in the queue
                Assert.AreEqual(priorityItems.Length, pq.Count);

                // Compare the order of the priority items
                for (i = 0; i < priorityItems.Length; ++i)
                {
                    PriorityItem priorityItem = pq.Dequeue() as PriorityItem;
                    Assert.AreSame(priorityItems[i], priorityItem);
                }
            }
        }
Ejemplo n.º 3
0
        private void EnumGetValues(Type enumType, ulong[] expected)
        {
            Array result = Enum2.GetValues(enumType);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected.Length, result.Length);

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(expected[i], Convert.ToUInt64(result.GetValue(i)));
            }
        }
Ejemplo n.º 4
0
        private static void GetNames_GetValues(Type enumType, string[] expectedNames, object[] expectedValues)
        {
            //Assert.AreEqual(expectedNames, Enum.GetNames(enumType));
            //Assert.AreEqual(expectedValues, Enum.GetValues(enumType).Cast<object>().ToArray());
            string[] names = Enum2.GetNames(enumType);
            Assert.IsNotNull(names, enumType.ToString());
            Assert.AreEqual(expectedNames.Length, names.Length, enumType.ToString());
            for (int i = 0; i < names.Length; i++)
            {
                Assert.AreEqual(expectedNames[i], names[i], enumType.ToString());
            }

            object[] values = Enum2.GetValues(enumType).Cast <object>().ToArray();
            Assert.IsNotNull(values);
            Assert.AreEqual(expectedValues.Length, values.Length);
            for (int i = 0; i < values.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], values[i], enumType.ToString());
            }
        }
Ejemplo n.º 5
0
        public void OneWorkItem()
        {
            WorkItemPriority[] priorities = Enum2.GetValues(typeof(WorkItemPriority)).Cast <WorkItemPriority> ().ToArray();
            foreach (WorkItemPriority wip in priorities)
            {
                PriorityQueue pq = new PriorityQueue();

                PriorityItem pi = new PriorityItem(wip);

                pq.Enqueue(pi);

                Assert.AreEqual(1, pq.Count, "Failed for priority {0}", wip);

                PriorityItem pi2 = pq.Dequeue() as PriorityItem;

                Assert.IsNotNull(pi2, "Failed for priority {0}", wip);

                Assert.AreSame(pi, pi2, "Failed for priority {0}", wip);

                Assert.AreEqual(0, pq.Count, "Failed for priority {0}", wip);
            }
        }
Ejemplo n.º 6
0
        public void MultipleWorkItemsOnePriority()
        {
            WorkItemPriority[] priorities = Enum2.GetValues(typeof(WorkItemPriority)).Cast <WorkItemPriority> ().ToArray();
            foreach (WorkItemPriority wip in priorities)
            {
                PriorityQueue pq = new PriorityQueue();

                PriorityItem[] priorityItems = new PriorityItem[10];

                for (int i = 0; i < priorityItems.Length; ++i)
                {
                    priorityItems[i] = new PriorityItem(wip);

                    pq.Enqueue(priorityItems[i]);

                    Assert.AreEqual(i + 1, pq.Count, "Failed for priority {0} item count {1}", wip, i + 1);
                }

                for (int i = 0; i < priorityItems.Length; ++i)
                {
                    PriorityItem pi = pq.Dequeue() as PriorityItem;

                    Assert.AreEqual(priorityItems.Length - (i + 1), pq.Count, "Failed for priority {0} item count {1}", wip, i + 1);

                    Assert.IsNotNull(pi, "Failed for priority {0} item count {1}", wip, i + 1);

                    Assert.AreSame(pi, priorityItems[i], "Failed for priority {0} item count {1}", wip, i + 1);
                }

                Assert.AreEqual(0, pq.Count, "Failed for priority {0}", wip);

                Assert.IsNull(pq.Dequeue());

                Assert.AreEqual(0, pq.Count);
            }
        }