public static List <OrbitBodyWithCurrentElementInfo> Setup_MockGameStateData_Elements()
        {
            var getElementsResult = new List <OrbitBodyWithCurrentElementInfo>();

            var currentElements = new TerraformElementsSet();

            currentElements.Set(1, 1.0);
            currentElements.Set(2, 2.0);
            currentElements.Set(3, 3.0);

            getElementsResult.Add(new OrbitBodyWithCurrentElementInfo(5000)
            {
                CurrentElements = currentElements
            });

            currentElements = new TerraformElementsSet();
            currentElements.Set(4, 4.0);
            currentElements.Set(5, 5.0);
            currentElements.Set(6, 6.0);

            getElementsResult.Add(new OrbitBodyWithCurrentElementInfo(5001)
            {
                CurrentElements = currentElements
            });

            return(getElementsResult);
        }
        public static List <OrbitBodyWithTerraformInfo> Setup_MockGameStateData_Targets()
        {
            var getDataResult = new List <OrbitBodyWithTerraformInfo>();

            var targets = new TerraformElementsSet();

            targets.Set(1, 1.1);
            targets.Set(2, 2.2);
            targets.Set(3, 3.3);

            getDataResult.Add(new OrbitBodyWithTerraformInfo(5000, 1000)
            {
                DesiredTargets = targets
            });

            targets = new TerraformElementsSet();
            targets.Set(4, 2.0);
            targets.Set(5, 2.5);
            targets.Set(6, 3.0);

            getDataResult.Add(new OrbitBodyWithTerraformInfo(5001, 1001)
            {
                DesiredTargets = targets
            });

            return(getDataResult);
        }
        public TerraformMutipleAdjustmentResult AdjustMultipleElements(TerraformElementsSet currentElements, TerraformElementsSet targets, double maxChangePossible)
        {
            var targetsToRemove = new List <TerraformElement>();

            var remainingDelta = maxChangePossible;

            foreach (var target in targets.theElements)
            {
                var currentElement = currentElements.Get(target.elementId);
                var adjustResult   = CalculateSingleElementChange(target.amount, currentElement.amount, remainingDelta);
                remainingDelta = adjustResult.maxChangeLeft;

                currentElements.Set(currentElement.elementId, adjustResult.newElementAmount);

                if (adjustResult.targetReached)
                {
                    targetsToRemove.Add(target);
                }
            }

            foreach (var target in targetsToRemove)
            {
                targets.Remove(target.elementId);
            }

            return(new TerraformMutipleAdjustmentResult()
            {
                currentElementValues = currentElements,
                adjustedTargets = targets
            });
        }
        public void Manager_WhenCalculatingMultiple_AndDeltaIsEnough_Should_HaveEmptyFinalTargetList()
        {
            var currentElements = new TerraformElementsSet();

            currentElements.Set(elementId: 1, amount: 1.6);
            currentElements.Set(elementId: 2, amount: 1.8);
            currentElements.Set(elementId: 31, amount: 0.1);

            var targets = new TerraformElementsSet();

            targets.Set(elementId: 1, amount: 2.0);
            targets.Set(elementId: 2, amount: 2.05);
            targets.Set(elementId: 31, amount: 1.0);

            var results        = _terraformManager.AdjustMultipleElements(currentElements, targets, maxChangePossible: 3.0);
            var updatedTargets = results.adjustedTargets;

            Assert.IsFalse(updatedTargets.theElements.Any());
        }
        public void Manager_WhenCalculatingMultiple_AndDeltaIsEnough_Should_ReachAllTargets()
        {
            var currentElements = new TerraformElementsSet();

            currentElements.Set(elementId: 1, amount: 1.6);
            currentElements.Set(elementId: 2, amount: 1.8);
            currentElements.Set(elementId: 31, amount: 0.1);

            var targets = new TerraformElementsSet();

            targets.Set(elementId: 1, amount: 2.0);
            targets.Set(elementId: 2, amount: 2.05);
            targets.Set(elementId: 31, amount: 1.0);

            var results = _terraformManager.AdjustMultipleElements(currentElements, targets, maxChangePossible: 3.0);

            Assert.AreEqual(2.0, results.currentElementValues.GetAmount(1));
            Assert.AreEqual(2.05, results.currentElementValues.GetAmount(2));
            Assert.AreEqual(1.0, results.currentElementValues.GetAmount(31));
        }
        public void Manager_WhenCalculatingMultiple_AndDeltaIsInsufficient_Should_DoAsMuchAsPossible()
        {
            var currentElements = new TerraformElementsSet();

            currentElements.Set(elementId: 1, amount: 1.6);
            currentElements.Set(elementId: 2, amount: 1.8);
            currentElements.Set(elementId: 31, amount: 0.1);

            var targets = new TerraformElementsSet();

            targets.Set(elementId: 1, amount: 2.0);
            targets.Set(elementId: 2, amount: 2.05);
            targets.Set(elementId: 31, amount: 1.0);

            var results = _terraformManager.AdjustMultipleElements(currentElements, targets, maxChangePossible: 0.6);

            Assert.AreEqual(2.0, results.currentElementValues.GetAmount(1));
            Assert.AreEqual(2.0, results.currentElementValues.GetAmount(2));

            Assert.IsFalse(results.adjustedTargets.IsPresent(1));
            Assert.AreEqual(2.05, results.adjustedTargets.GetAmount(2));
            Assert.AreEqual(1.0, results.adjustedTargets.GetAmount(31));
        }