コード例 #1
0
        public void GetItemForDistance(int distance, string result)
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            // Act
            distanceWeightedItems.AddItem("Item1",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(1, 10),
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 0)
            });
            distanceWeightedItems.AddItem("Item2",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 5)
            });
            distanceWeightedItems.PrepareForUse();
            //Debug.Log(distanceWeightedItems.ToString());

            // Assert
            Assert.AreEqual(result, distanceWeightedItems.GetItemForDistance(distance));
        }
コード例 #2
0
        public void GetAssociatedItemForDistance(int distance, int result)
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            distanceWeightedItems.AddItem("Item1",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(1, 10),
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 0)
            });
            distanceWeightedItems.AddItem("Item2",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 5)
            });
            distanceWeightedItems.PrepareForUse();

            // Act
            var associatedDistance = distanceWeightedItems.GetAssociatedDistance(distance).Distance;

            // Assert
            Assert.AreEqual(result, associatedDistance);
        }
コード例 #3
0
        public void ItemWithoutWeightsNotAdded()
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            distanceWeightedItems.AddItem("Item", new List <DistanceWeightValue>());

            // Assert
            Assert.AreEqual(0, distanceWeightedItems.ItemCount);
        }
コード例 #4
0
        public void DistancesSavedAndUnique()
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            // Act
            distanceWeightedItems.AddItem("Item1",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(1, 10),
                new DistanceWeightValue(2, 10)
            });
            distanceWeightedItems.AddItem("Item2",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 10)
            });

            // Assert
            Assert.AreEqual(distanceWeightedItems.GetDistances().Distinct().Count(), distanceWeightedItems.GetDistances().Count);
        }
コード例 #5
0
        public void AllDistancesSavedAndGapsFilled(int distance, int result)
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            // Act
            distanceWeightedItems.AddItem("Item1",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(1, 10),
                new DistanceWeightValue(2, 10)
            });
            distanceWeightedItems.AddItem("Item2",
                                          new List <DistanceWeightValue>()
            {
                new DistanceWeightValue(2, 10),
                new DistanceWeightValue(4, 5)
            });
            distanceWeightedItems.PrepareForUse();

            // Assert
            Assert.AreEqual(result, distanceWeightedItems.GetDistanceTotalWeight(distance));
        }
コード例 #6
0
        public void ItemCountLikeItemsAdded(int count)
        {
            // Arrange
            var distanceWeightedItems = new DistanceWeightedItems <string>();

            for (var i = 0; i < count; i++)
            {
                distanceWeightedItems.AddItem("Item" + i,
                                              new List <DistanceWeightValue>()
                {
                    new DistanceWeightValue(2, 10)
                });
            }

            // Assert
            Assert.AreEqual(count, distanceWeightedItems.ItemCount);
        }