public void TestComponentReplacement()
        {
            var vectorA = new RawHexVector();

            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.B, 2);
            vectorA.AddComponent(HexAxis.E, 7);
            vectorA.AddComponent(HexAxis.A, 2);
            vectorA.AddComponent(HexAxis.C, 2);

            _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B).Should().Be(5);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-2);

            _utilityLibrary.AddOrUpdateVectorDirection(vectorA, 1, HexAxis.B);
            _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B).Should().Be(1);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-6);

            var vectorB = new RawHexVector();

            vectorB.AddComponent(HexAxis.F, 3);

            _utilityLibrary.GetMagnitudeAlongDirection(vectorB, HexAxis.C).Should().Be(0);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorB, HexAxis.C).Should().Be(-3);

            _utilityLibrary.AddOrUpdateVectorDirection(vectorB, 5, HexAxis.C);
            _utilityLibrary.GetMagnitudeAlongDirection(vectorB, HexAxis.C).Should().Be(5);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorB, HexAxis.C).Should().Be(2);
        }
        public void TestVectorDirectionValuesCalculation()
        {
            var vectorA = new RawHexVector();

            vectorA.AddComponent(HexAxis.B, 5);
            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.E, 2);

            int bMagnitude = _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B);

            bMagnitude.Should().Be(8);
            int beMagnitude = _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B);

            beMagnitude.Should().Be(6);
        }
        public void ConsolidateVector(RawHexVector rawVector)
        {
            List <HexVectorComponent> reductedComponents = rawVector.Components.ToList();

            rawVector.ClearComponents();
            rawVector.AddComponent(ConsolidateCardinalDirection(HexAxis.Up, reductedComponents));

            do
            {
                // Step 1. Consolidate opposing vectors.
                reductedComponents = new List <HexVectorComponent>
                {
                    ConsolidateCardinalDirection(HexAxis.A, reductedComponents),
                    ConsolidateCardinalDirection(HexAxis.B, reductedComponents),
                    ConsolidateCardinalDirection(HexAxis.C, reductedComponents)
                };

                reductedComponents = reductedComponents.Where(av => av.Magnitude > 0).ToList();
                HexVectorComponent fittingVectorA,
                                   fittingVectorB;
                // Step 2. Consolidate vectors 120 degree apart.
                var medianDirection = FindVectors120Apart(reductedComponents, out fittingVectorA, out fittingVectorB);
                if (medianDirection != null && fittingVectorA != null && fittingVectorB != null)
                {
                    int minimumMagnitude = Math.Min(fittingVectorA.Magnitude, fittingVectorB.Magnitude);
                    fittingVectorA.Magnitude -= minimumMagnitude;
                    fittingVectorB.Magnitude -= minimumMagnitude;
                    reductedComponents.Add(new HexVectorComponent(medianDirection.Value, minimumMagnitude)); //This one will be resolved in the next iteration.
                }
            }while (reductedComponents.Count > 2 || HasVectors120Apart(reductedComponents));

            rawVector.AddComponents(reductedComponents);
        }
        public void TestConsolidation()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent   = new HexVectorComponent(HexAxis.C, 5),
                SecondaryComponent = new HexVectorComponent(HexAxis.E, 9)
            };

            _utilityLibrary.ConsolidateVector(vectorA);
            TestChecksUtility.CheckComponent(vectorA.PrimaryComponent, HexAxis.D, 5);
            TestChecksUtility.CheckComponent(vectorA.SecondaryComponent, HexAxis.E, 4);

            var vectorB = new RawHexVector();

            vectorB.AddComponent(HexAxis.A, 1);
            vectorB.AddComponent(HexAxis.B, 4);
            vectorB.AddComponent(HexAxis.C, 3);
            vectorB.AddComponent(HexAxis.E, 7);
            vectorB.AddComponent(HexAxis.Up, 2);
            vectorB.AddComponent(HexAxis.Up, 3);
            vectorB.AddComponent(HexAxis.Down, 5);
            var resultB = _utilityLibrary.ConsolidateAndCopyVector(vectorB);

            TestChecksUtility.CheckComponent(resultB.PrimaryComponent, HexAxis.D, 2);
            resultB.SecondaryComponent.Should().Be(HexVectorComponent.Zero);
            resultB.VerticalComponent.Should().Be(HexVectorComponent.Zero);
        }
        public void TestComponentElimination()
        {
            var vectorA = new RawHexVector();

            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.B, 2);
            vectorA.AddComponent(HexAxis.E, 7);
            vectorA.AddComponent(HexAxis.A, 2);
            vectorA.AddComponent(HexAxis.C, 2);

            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.A).Should().Be(2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.C).Should().Be(2);

            _utilityLibrary.EliminateComponentsAlongCardinalDirection(vectorA, HexAxis.B);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(0);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.A).Should().Be(2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.C).Should().Be(2);
        }
        public void TestVectorCloning()
        {
            var vectorA = new RawHexVector();

            vectorA.AddComponent(HexAxis.B, 5);
            vectorA.AddComponent(HexAxis.F, 2);

            var hexVector = _utilityLibrary.CloneHexVector <HexVector>(vectorA);

            TestChecksUtility.CheckComponent(hexVector.PrimaryComponent, HexAxis.B, 5);
            TestChecksUtility.CheckComponent(hexVector.SecondaryComponent, HexAxis.F, 2);

            // Cloning does not consolidate vectors. It copies them as they are, so we can't test grid
            // coordinates copy on vector A.
            var vectorB = new RawHexVector();

            vectorB.AddComponent(HexAxis.C, 5);
            vectorB.AddComponent(HexAxis.A, 2);
            var gridCoordinate = _utilityLibrary.CloneHexVector <HexGridCoordinate>(vectorB);

            gridCoordinate.CfCoordinate.Should().Be(5);
            gridCoordinate.DaCoordinate.Should().Be(1);
        }
        public void AddOrUpdateVectorDirection(RawHexVector rawVector, int value, HexAxis direction)
        {
            var affectedComponents = rawVector.Components.Where(hvc => hvc.Direction == direction).ToList();

            if (value > 0)
            {
                if (affectedComponents.Count > 0)
                {
                    var firstComponent = affectedComponents[0];
                    affectedComponents.Remove(firstComponent);
                    firstComponent.Magnitude = value;
                }
                else
                {
                    rawVector.AddComponent(direction, value);
                }
            }

            rawVector.RemoveComponents(affectedComponents);
        }
        public void TestConsolidation()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.C, 5),
                SecondaryComponent = new HexVectorComponent(HexAxis.E, 9)
            };
            _utilityLibrary.ConsolidateVector(vectorA);
            TestChecksUtility.CheckComponent(vectorA.PrimaryComponent, HexAxis.D, 5);
            TestChecksUtility.CheckComponent(vectorA.SecondaryComponent, HexAxis.E, 4);

            var vectorB = new RawHexVector();
            vectorB.AddComponent(HexAxis.A, 1);
            vectorB.AddComponent(HexAxis.B, 4);
            vectorB.AddComponent(HexAxis.C, 3);
            vectorB.AddComponent(HexAxis.E, 7);
            vectorB.AddComponent(HexAxis.Up, 2);
            vectorB.AddComponent(HexAxis.Up, 3);
            vectorB.AddComponent(HexAxis.Down, 5);
            var resultB = _utilityLibrary.ConsolidateAndCopyVector(vectorB);
            TestChecksUtility.CheckComponent(resultB.PrimaryComponent, HexAxis.D, 2);
            resultB.SecondaryComponent.Should().Be(HexVectorComponent.Zero);
            resultB.VerticalComponent.Should().Be(HexVectorComponent.Zero);
        }
        public void TestComponentReplacement()
        {
            var vectorA = new RawHexVector();
            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.B, 2);
            vectorA.AddComponent(HexAxis.E, 7);
            vectorA.AddComponent(HexAxis.A, 2);
            vectorA.AddComponent(HexAxis.C, 2);

            _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B).Should().Be(5);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-2);

            _utilityLibrary.AddOrUpdateVectorDirection(vectorA, 1, HexAxis.B);
            _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B).Should().Be(1);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-6);

            var vectorB = new RawHexVector();
            vectorB.AddComponent(HexAxis.F, 3);

            _utilityLibrary.GetMagnitudeAlongDirection(vectorB, HexAxis.C).Should().Be(0);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorB, HexAxis.C).Should().Be(-3);

            _utilityLibrary.AddOrUpdateVectorDirection(vectorB, 5, HexAxis.C);
            _utilityLibrary.GetMagnitudeAlongDirection(vectorB, HexAxis.C).Should().Be(5);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorB, HexAxis.C).Should().Be(2);

        }
        public void TestComponentElimination()
        {
            var vectorA = new RawHexVector();
            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.B, 2);
            vectorA.AddComponent(HexAxis.E, 7);
            vectorA.AddComponent(HexAxis.A, 2);
            vectorA.AddComponent(HexAxis.C, 2);

            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(-2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.A).Should().Be(2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.C).Should().Be(2);

            _utilityLibrary.EliminateComponentsAlongCardinalDirection(vectorA, HexAxis.B);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B).Should().Be(0);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.A).Should().Be(2);
            _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.C).Should().Be(2);
        }
        public void TestVectorCloning()
        {
            var vectorA = new RawHexVector();
            vectorA.AddComponent(HexAxis.B, 5);
            vectorA.AddComponent(HexAxis.F, 2);

            var hexVector = _utilityLibrary.CloneHexVector<HexVector>(vectorA);
            TestChecksUtility.CheckComponent(hexVector.PrimaryComponent, HexAxis.B, 5);
            TestChecksUtility.CheckComponent(hexVector.SecondaryComponent, HexAxis.F, 2);

            // Cloning does not consolidate vectors. It copies them as they are, so we can't test grid
            // coordinates copy on vector A.
            var vectorB = new RawHexVector();
            vectorB.AddComponent(HexAxis.C, 5);
            vectorB.AddComponent(HexAxis.A, 2);
            var gridCoordinate = _utilityLibrary.CloneHexVector<HexGridCoordinate>(vectorB);
            gridCoordinate.CfCoordinate.Should().Be(5);
            gridCoordinate.DaCoordinate.Should().Be(1);
        }
        public void TestVectorDirectionValuesCalculation()
        {
            var vectorA = new RawHexVector();
            vectorA.AddComponent(HexAxis.B, 5);
            vectorA.AddComponent(HexAxis.B, 3);
            vectorA.AddComponent(HexAxis.E, 2);

            int bMagnitude = _utilityLibrary.GetMagnitudeAlongDirection(vectorA, HexAxis.B);
            bMagnitude.Should().Be(8);
            int beMagnitude = _utilityLibrary.GetMagnitudeAlongCardinalDirection(vectorA, HexAxis.B);
            beMagnitude.Should().Be(6);
        }