Пример #1
0
        public void RoverRunsIntoObstacleAndReports()
        {
            var grid = new GridBuilder()
                       .WithDimensions(2, 2)
                       .WithObstacleAt(1, 0)
                       .Build();
            var startingPosition = new PositionBuilder()
                                   .OnGrid(grid)
                                   .WithCoordinates(new Coordinates(0, 0))
                                   .Facing(DirectionEnum.West)
                                   .Build();
            var rover = new RoverBuilder()
                        .AtPosition(startingPosition)
                        .Build();
            var roverControl = new RoverControlBuilder()
                               .ForRover(rover)
                               .Build();

            roverControl.SendCommands("f");
            var detectedObstacle = roverControl.InvokeCommands();

            Assert.Equal(startingPosition, rover.Position);
            Assert.True(detectedObstacle);
            Assert.Empty(roverControl.Commands);
        }
Пример #2
0
            protected override void Given()
            {
                const int x = 5;
                const int y = 5;

                var positionOne =
                    new PositionBuilder()
                    .WithX(x)
                    .WithY(y)
                    .Build();

                _positionTwo =
                    new PositionBuilder()
                    .WithX(x + 2)
                    .WithY(y + 2)
                    .Build();

                var landingPlatform =
                    new LandingPlatformMockBuilder()
                    .WithIsPositionInsideOfPlatformMocked(IsPositionInsideOfThePlatform)
                    .WithIsAllowedPositionMocked(IsAllowedPosition)
                    .Build();

                _sut =
                    new LandingAreaBuilder()
                    .WithLandingPlatform(landingPlatform)
                    .Build();

                _sut.CheckPosition(positionOne);

                _expectedResult    = LandingAnswer;
                _expectedPositions = StoredPositions;
            }
Пример #3
0
        public void RoverExecutesCommandSequenceThatLeadsIntoObstacle()
        {
            var grid = new GridBuilder()
                       .WithDimensions(2, 2)
                       .WithObstacleAt(1, 1)
                       .Build();
            var startingPosition = new PositionBuilder()
                                   .OnGrid(grid)
                                   .WithCoordinates(new Coordinates(0, 0))
                                   .Facing(DirectionEnum.North)
                                   .Build();
            var rover = new RoverBuilder()
                        .AtPosition(startingPosition)
                        .Build();
            var roverControl = new RoverControlBuilder()
                               .ForRover(rover)
                               .Build();

            roverControl.SendCommands("frf");
            roverControl.InvokeCommands();

            var endingPosition = new PositionBuilder()
                                 .OnGrid(grid)
                                 .WithCoordinates(new Coordinates(0, 1))
                                 .Facing(DirectionEnum.East)
                                 .Build();

            Assert.Equal(endingPosition, rover.Position);
        }
Пример #4
0
        public ValidPosition MakeTurn()
        {
            ValidPosition        bestPosition = this;
            Predicate <Position> betterScore  =
                p => p.Score > bestPosition.Score;

            for (int i = 0; i < 2 * COLUMN_COUNT - 1; ++i)
            {
                for (int j = 0; j < 2 * SHORT_COLUMN_LENGTH - 1; ++j)
                {
                    var point    = new RotationCenter(i, j);
                    var position = PositionBuilder.Generate(this, point, true).MakeTurn().Build();
                    if (betterScore(position))
                    {
                        bestPosition = position;
                    }
                    position = PositionBuilder.Generate(this, point, false).MakeTurn().Build();
                    if (betterScore(position))
                    {
                        bestPosition = position;
                    }
                }
            }
            return(bestPosition);
        }
Пример #5
0
        public void CreateRoverAtPosition()
        {
            var position = new PositionBuilder()
                           .DefaultPosition()
                           .Build();

            var rover = new Rover(position);

            Assert.Equal(position, rover.Position);
        }
        public override void EndElement(string endElement)
        {
            if (this.PositionEventListener == null || !"position".Equals(endElement))
            {
                return;
            }
            long longValue1;

            this.TryGetValue("accountId", out longValue1);
            long longValue2;

            this.TryGetValue("instrumentId", out longValue2);
            Decimal dec1;

            this.TryGetValue("openQuantity", out dec1);
            Decimal dec2;

            this.TryGetValue("openCost", out dec2);
            Decimal dec3;

            this.TryGetValue("cumulativeCost", out dec3);
            PositionBuilder positionBuilder = new PositionBuilder();

            positionBuilder.AccountId(longValue1).InstrumentId(longValue2).OpenQuantity(dec1).OpenCost(dec2).CumulativeCost(dec3);
            Decimal dec4;

            if (this.TryGetValue("shortUnfilledCost", out dec4))
            {
                positionBuilder.ShortUnfilledCost(dec4);
            }
            else
            {
                positionBuilder.ShortUnfilledCost(new Decimal(0));
            }
            Decimal dec5;

            if (this.TryGetValue("longUnfilledCost", out dec5))
            {
                positionBuilder.LongUnfilledCost(dec5);
            }
            else
            {
                positionBuilder.LongUnfilledCost(new Decimal(0));
            }
            this.PositionEventListener(positionBuilder.NewInstance());
        }
Пример #7
0
        public RegularTree(AstNode root)
        {
            this.EoiCharSetNode = CharSetNode.Create(EoiChar);
            this.AugmentedRoot = new CatNode(new List<AstNode> { root, EoiCharSetNode });

            var positionBuilder = new PositionBuilder();
            AugmentedRoot.Accept(positionBuilder, null);
            Positions = positionBuilder.Positions;

            EoiPosition = Positions.FindIndex(pos => pos.Characters.Contains(EoiChar));
            Debug.Assert(EoiPosition >= 0);

            var firstPosVisitor = new FirstPosGetter();
            this.FirstPos = AugmentedRoot.Accept(firstPosVisitor, 0);

            var followPosBuilder = new FollowPosBuilder(Positions);
            AugmentedRoot.Accept(followPosBuilder, 0);
        }
Пример #8
0
        public override void EndElement(string endElement)
        {
            if (PositionEventListener != null && RootNode.Equals(endElement))
            {
                long    accountId;
                long    instrumentId;
                decimal shortUnfilledCost;
                decimal longUnfilledCost;
                decimal openQuantity;
                decimal openCost;
                decimal cumulativeCost;

                TryGetValue(AccountId, out accountId);
                TryGetValue(InstrumentId, out instrumentId);
                TryGetValue(OpenQuantity, out openQuantity);
                TryGetValue(OpenCost, out openCost);
                TryGetValue(CumulativeCost, out cumulativeCost);

                PositionBuilder positionBuilder = new PositionBuilder();
                positionBuilder.AccountId(accountId).InstrumentId(instrumentId).OpenQuantity(openQuantity).OpenCost(openCost).CumulativeCost(cumulativeCost);

                if (TryGetValue(ShortUnfilledCost, out shortUnfilledCost))
                {
                    positionBuilder.ShortUnfilledCost(shortUnfilledCost);
                }
                else
                {
                    positionBuilder.ShortUnfilledCost(0);
                }

                if (TryGetValue(LongUnfilledCost, out longUnfilledCost))
                {
                    positionBuilder.LongUnfilledCost(longUnfilledCost);
                }
                else
                {
                    positionBuilder.LongUnfilledCost(0);
                }

                PositionEventListener(positionBuilder.NewInstance());
            }
        }
        public void TestEncirclementBug1()
        {
            Fraction        testFraction    = new Fraction("test");
            Point           testPosition    = new Point(0, 0);
            PositionBuilder positionBuilder = new PositionBuilder(testPosition);

            TerritoryApi.ChangeTerritoryOwner(testPosition, testFraction);
            TerritoryApi.ChangeTerritoryOwner(positionBuilder.Top(), testFraction);
            TerritoryApi.ChangeTerritoryOwner(positionBuilder.Right(), testFraction);
            TerritoryApi.ChangeTerritoryOwner(positionBuilder.TopRight(), testFraction);

            FindTerritoryOwnerEvent checkTestPositionOwner = new FindTerritoryOwnerEvent(testPosition);

            JEventBus.GetDefault().Post(checkTestPositionOwner);
            Assert.IsTrue(checkTestPositionOwner.Success);
            Assert.IsNotNull(checkTestPositionOwner.Owner);
            Assert.AreEqual(testFraction, checkTestPositionOwner.Owner);

            Assert.AreEqual(4, TerritoryApi.GetTerritoryCellsAmount(testFraction));
        }
Пример #10
0
        private static void _ReadTitle(_Property titleProp, Contact contact)
        {
            // In VCF there are three related properties: ORG, ROLE, and TITLE.
            // There reasonably could be multiple organizations on a vcard but short
            // of property groupings there's no way to distinguish, and even then
            // no guarantee that the property groupings will be present in the case
            // of multiple sets of these properties.
            // So instead, treat this like name and assume only the default, but rather
            // than use .Default, use the PropertyLabels.Business indexer.
            Assert.IsNotNull(titleProp);
            Assert.IsNotNull(contact);

            var position = new PositionBuilder(contact.Positions[PropertyLabels.Business])
            {
                JobTitle = titleProp.ValueString
            };
            contact.Positions[PropertyLabels.Business] = position;
        }
Пример #11
0
        private static void _ReadOrganization(_Property orgProp, Contact contact)
        {
            // In VCF there are three related properties: ORG, ROLE, and TITLE.
            // There reasonably could be multiple organizations on a vcard but short
            // of property groupings there's no way to distinguish, and even then
            // no guarantee that the property groupings will be present in the case
            // of multiple sets of these properties.
            // So instead, treat this like name and assume only the default, but rather
            // than use .Default, use the PropertyLabels.Business indexer.
            Assert.IsNotNull(orgProp);
            Assert.IsNotNull(contact);

            var position = new PositionBuilder(contact.Positions[PropertyLabels.Business]);
            string[] elements = _TokenizeEscapedMultipropString(orgProp.ValueString);
            Assert.BoundedInteger(1, elements.Length, int.MaxValue);

            // ORG is weird in that it doesn't actually say what the tokens represent.
            // The first one can be safely assumed to be Company, but anything else it's probably
            // best to just put back the ';'s and stick the string somewhere visible.
            position.Company = elements[0];
            if (elements.Length > 1)
            {
                position.Office = string.Join(";", elements, 1, elements.Length -1);
            }
            contact.Positions[PropertyLabels.Business] = position;
        }
 static protected IList<Position> LoadTradingPositions(Filter filter, Market market, DateTime valuationTime, SimpleDate fromDate, SimpleDate toDate)
 {
     var builder = new PositionBuilder { PositionFilter = filter };
     builder.AcceptCurrencySecurity = true;
     builder.IncludeOtc = true;
     builder.ExcludeNonLive = true;
     builder.FromDate = fromDate;
     builder.ToDate = toDate;
     var asOfDate = market.Date(valuationTime);
     return builder.Build(new SimpleDate(asOfDate));
 }
        public SiteMappingViewModel(string path, string colorText, string colorLines, string colorRectWithText, string colorRectWithoutText, string linesConnection)
        {
            SiteMapGenerator     smg    = new SiteMapGenerator();
            List <SiteMapObject> allObj = smg.GetAllObjects(path);
            int sizeAndLevel            = 1;

            if (path != null)
            {
                sizeAndLevel = path.Split('/').Count();
            }

            if (linesConnection == null)
            {
                LinesConnection = "1";
            }
            else
            {
                LinesConnection = linesConnection;
            }


            PositionBuilder cm = new PositionBuilder(allObj, sizeAndLevel, LinesConnection);

            AllObjects = cm.Build();

            HeightSize = cm.HeightSize;
            WidthSize  = cm.WidthSize;

            RectWidth = cm.recWidht;
            RectHight = cm.recHight;

            RectWidthText = cm.recWidhtText;
            RectHightText = cm.recHightText;
            ColumnsDiff   = cm.columnsDiff;
            RowDiff       = cm.rowDiff;

            if (colorText == null)
            {
                ColorText = "#1a1aff";
            }
            else
            {
                ColorText = colorText;
            }
            if (colorLines == null)
            {
                ColorLines = "#ffff00";
            }
            else
            {
                ColorLines = colorLines;
            }

            if (colorRectWithText == null)
            {
                ColorRectWithText = "#ff0000";
            }
            else
            {
                ColorRectWithText = colorRectWithText;
            }

            if (colorRectWithoutText == null)
            {
                ColorRectWithoutText = "#ff00ff";
            }
            else
            {
                ColorRectWithoutText = colorRectWithoutText;
            }


            AllLineObjects = cm.SiteMapLineObjects();
        }