Esempio n. 1
0
        public void Test1()
        {
            var list = new List <int> {
                23, 42, 4, 16, 8, 15, 3, 9, 55, 0, 34, 12, 2, 46, 25
            };

            BucketSorter.BucketSort(list);
        }
Esempio n. 2
0
        public static void ArraySorted([Random(0, 1000, 1000, Distinct = true)] int n)
        {
            // Arrange
            var sorter = new BucketSorter();

            var(correctArray, testArray) = RandomHelper.GetArrays(n);

            // Act
            sorter.Sort(testArray);
            Array.Sort(correctArray);

            // Assert
            Assert.AreEqual(correctArray, testArray);
        }
Esempio n. 3
0
        public void Sort_DoesNotChange_OriginalInput()
        {
            //arrange
            const int firstElement = 5, lastElement = 3;
            var       original = new List <int> {
                firstElement, 2, 4, 6, 1, lastElement
            };
            var sorter = new BucketSorter();
            //act
            var sorted = sorter.Sort(original);

            //assert
            original[0].Should().Be(firstElement);
            original[5].Should().Be(lastElement);
        }
Esempio n. 4
0
        public void SortWithOrderExample()
        {
            var sorter = new BucketSorter();

            var list = new List <int> {
                13, 5, 77, 9, 12
            };

            sorter.Sort(list, SortOrder.Descending);

            Assert.AreEqual(77, list[0]);
            Assert.AreEqual(13, list[1]);
            Assert.AreEqual(12, list[2]);
            Assert.AreEqual(9, list[3]);
            Assert.AreEqual(5, list[4]);
        }
Esempio n. 5
0
		protected override void StartSearch()
		{
			BucketSorter sorter = new BucketSorter();

			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Trinket))		sorter.Add(new Bucket(EquippableSlotFlags.Trinket));

			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.ShirtChest))		sorter.Add(new Bucket(EquippableSlotFlags.ShirtChest));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.PantsUpperLegs)) sorter.Add(new Bucket(EquippableSlotFlags.PantsUpperLegs));

			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Necklace))		sorter.Add(new Bucket(EquippableSlotFlags.Necklace));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.RightBracelet))	sorter.Add(new Bucket(EquippableSlotFlags.RightBracelet));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.LeftBracelet))	sorter.Add(new Bucket(EquippableSlotFlags.LeftBracelet));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.RightRing))		sorter.Add(new Bucket(EquippableSlotFlags.RightRing));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.LeftRing))		sorter.Add(new Bucket(EquippableSlotFlags.LeftRing));

			// Put all of our inventory into its appropriate bucket
			foreach (SuitBuildableMyWorldObject piece in Equipment)
				sorter.PutItemInBuckets(piece);

			// Remove any empty buckets
			for (int i = sorter.Count - 1; i >= 0; i--)
			{
				if (sorter[i].Count == 0)
					sorter.RemoveAt(i);
			}

			// Reset our variables
			highestCountSuitBuilt = 0;
			highestEpicuitsBuilt = new Dictionary<int, List<int>>();
			for (int i = 1; i <= 17; i++)
				highestEpicuitsBuilt.Add(i, new List<int>(5));
			completedSuits = new List<CompletedSuit>();

			// Do the actual search here
			if (sorter.Count > 0)
				SearchThroughBuckets(sorter, 0);

			// If we're not running, the search was stopped before it could complete
			if (!Running)
				return;

			Stop();

			OnSearchCompleted();
		}
Esempio n. 6
0
        public void Sort_Returns_AscOrderedCollection()
        {
            //arrange
            var original = new List <int> {
                5, 2, 4, 6, 1, 3
            };
            var sorter = new BucketSorter();
            //act
            var sorted = sorter.Sort(original).ToList();
            //assert
            var prev = sorted[0];

            for (var i = 1; i < sorted.Count; i++)
            {
                prev.Should().BeLessOrEqualTo(sorted[i]);
                prev = sorted[i];
            }
        }
Esempio n. 7
0
    private Sorter GetSorter(SorterType type)
    {
        Sorter sorter = null;

        switch (type)
        {
        case SorterType.Bubble:
            sorter = new BubbleSorter();
            break;

        case SorterType.Bucket:
            sorter = new BucketSorter();
            break;

        case SorterType.Quick:
            sorter = new QuickSorter();
            break;
        }
        return(sorter);
    }
Esempio n. 8
0
		protected override void StartSearch()
		{
			buckets = new BucketSorter();

			// All these slots can have armor
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Head))		buckets.Add(new Bucket(EquippableSlotFlags.Head));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Hands))		buckets.Add(new Bucket(EquippableSlotFlags.Hands));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Feet))		buckets.Add(new Bucket(EquippableSlotFlags.Feet));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Chest))		buckets.Add(new Bucket(EquippableSlotFlags.Chest));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.Abdomen))	buckets.Add(new Bucket(EquippableSlotFlags.Abdomen));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.UpperArms))	buckets.Add(new Bucket(EquippableSlotFlags.UpperArms));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.LowerArms))	buckets.Add(new Bucket(EquippableSlotFlags.LowerArms));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.UpperLegs))	buckets.Add(new Bucket(EquippableSlotFlags.UpperLegs));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.LowerLegs))	buckets.Add(new Bucket(EquippableSlotFlags.LowerLegs));

			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.ShirtChest))		buckets.Add(new Bucket(EquippableSlotFlags.ShirtChest));
			if (SuitBuilder.SlotIsOpen(EquippableSlotFlags.PantsUpperLegs)) buckets.Add(new Bucket(EquippableSlotFlags.PantsUpperLegs));
		
			// Put all of our inventory into its appropriate bucket
			foreach (var piece in Equipment)
			{
				if (piece.EquippableSlots == (EquippableSlotFlags.PantsLowerLegs | EquippableSlotFlags.Feet)) // Some shoes cover both feet/lower legs but can only go in the feet slot
					buckets.PutItemInBuckets(piece, EquippableSlotFlags.Feet);
				else if (piece.EquippableSlots.IsBodyArmor() && piece.EquippableSlots.GetTotalBitsSet() != piece.Coverage.GetTotalBitsSet())
					MessageBox.Show("Unable to add " + piece + " into an appropriate bucket. EquippableSlots != Coverage" + Environment.NewLine + "EquippableSlots: " + piece.EquippableSlots + Environment.NewLine + "Coverage: " + piece.Coverage);
				else if (piece.EquippableSlots.IsBodyArmor() && piece.EquippableSlots.GetTotalBitsSet() > 1)
				{
					if (piece.Material == null) // Can't reduce non-loot gen pieces
						buckets.PutItemInBuckets(piece);
					else
					{
						// Lets try to reduce this
						foreach (var option in piece.Coverage.ReductionOptions())
						{
							if (option == CoverageFlags.Head)			buckets.PutItemInBuckets(piece, EquippableSlotFlags.Head);
							else if (option == CoverageFlags.Chest)		buckets.PutItemInBuckets(piece, EquippableSlotFlags.Chest);
							else if (option == CoverageFlags.UpperArms) buckets.PutItemInBuckets(piece, EquippableSlotFlags.UpperArms);
							else if (option == CoverageFlags.LowerArms) buckets.PutItemInBuckets(piece, EquippableSlotFlags.LowerArms);
							else if (option == CoverageFlags.Hands)		buckets.PutItemInBuckets(piece, EquippableSlotFlags.Hands);
							else if (option == CoverageFlags.Abdomen)	buckets.PutItemInBuckets(piece, EquippableSlotFlags.Abdomen);
							else if (option == CoverageFlags.UpperLegs) buckets.PutItemInBuckets(piece, EquippableSlotFlags.UpperLegs);
							else if (option == CoverageFlags.LowerLegs) buckets.PutItemInBuckets(piece, EquippableSlotFlags.LowerLegs);
							else if (option == CoverageFlags.Feet)		buckets.PutItemInBuckets(piece, EquippableSlotFlags.Feet);
							else
								MessageBox.Show("Unable to add " + piece + " into an appropriate bucket." + Environment.NewLine + "Reduction coverage option of " + option + " not expected.");
						}
					}
				}
				else
					buckets.PutItemInBuckets(piece);
			}

			// Remove any empty buckets
			for (int i = buckets.Count - 1; i >= 0; i--)
			{
				if (buckets[i].Count == 0)
					buckets.RemoveAt(i);
			}

			// We should sort the buckets based on number of items, least amount first, with all armor buckets first
			buckets.Sort((a, b) =>
			{
				if (a.Slot.IsBodyArmor() && !b.Slot.IsBodyArmor()) return -1;
				if (!a.Slot.IsBodyArmor() && b.Slot.IsBodyArmor()) return 1;
				return a.Count.CompareTo(b.Count);
			});

			// Calculate the total number of armor buckets we have with pieces in them.
			totalArmorBucketsWithItems = 0;
			foreach (Bucket bucket in buckets)
			{
				if (bucket.Slot.IsBodyArmor())
					totalArmorBucketsWithItems++;
			}

			// Reset our variables
			highestArmorCountSuitBuilt = 0;
			highestArmorSuitsBuilt = new Dictionary<int, List<int>>();
			for (int i = 1; i <= 17; i++)
				highestArmorSuitsBuilt.Add(i, new List<int>(5));
			completedSuits = new List<CompletedSuit>();

			// Do the actual search here
			if (buckets.Count > 0)
				SearchThroughBuckets(SuitBuilder.Clone(), 0);

			// If we're not running, the search was stopped before it could complete
			if (!Running)
				return;

			Stop();

			OnSearchCompleted();
		}
Esempio n. 9
0
		public void ExceptionNullList3()
        {
            var sorter = new BucketSorter();
            sorter.Sort(null, SortOrder.Ascending);
        }
Esempio n. 10
0
		public void ExceptionNullList1()
        {
            var sorter = new BucketSorter();
            sorter.Sort(null);
        }
Esempio n. 11
0
		public void Simple()
        {
            var sorter = new BucketSorter();
            TestSorter(sorter);
        }
Esempio n. 12
0
        public void TestBucketSortNullComparer1()
        {
            BucketSorter sorter = new BucketSorter(500);

            sorter.Sort(new List <int>(), (IComparer <int>)null);
        }
Esempio n. 13
0
        public void TestBucketSortNullList3()
        {
            BucketSorter sorter = new BucketSorter(500);

            sorter.Sort(null, SortOrder.Ascending);
        }
Esempio n. 14
0
        public void TestBucketSortNullList2()
        {
            BucketSorter sorter = new BucketSorter(500);

            sorter.Sort(null, Comparer <int> .Default);
        }
Esempio n. 15
0
        public void TestBucketSortNullList1()
        {
            BucketSorter sorter = new BucketSorter(500);

            sorter.Sort(null);
        }
Esempio n. 16
0
        public void TestBucketSorter()
        {
            BucketSorter sorter = new BucketSorter(500);

            TestSorter(sorter);
        }