Exemplo n.º 1
0
        public void PlaceDoor_InRectangularTestRooms(StandardTestRoom testRoom)
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupStandardRoom()
            {
                fakeRandomNumbers.PopulateRandomForTestRoom(testRoom)
                ;
            }

            void SetupDoorForStandardRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(0, 0)               // Door placement, top left corner, will try again
                .AddCoordinates(9, 0)               // Door placement, btm left corner, will try again
                .AddCoordinates(9, 5)               // Door placement, btm right corner, will try again
                .AddCoordinates(0, 5)               // Door placement, top right corner, will try again
                .AddCoordinates(0, 3)               // Door placement, vertical wall, will try again
                .AddCoordinates(4, 0)               // Door placement, horizontal wall, will try again
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.West)  // direction to walk to find a wall and place a door
                ;
            }

            var registry = new DispatchRegistry();

            SetupStandardRoom();
            SetupDoorForStandardRoom();

            var fakeLogger = new FakeLogger(_output);

            var builder = new RoomBuilder(fakeRandomNumbers, fakeLogger, registry);

            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();
            var detail         = mazeDescriptor[1];
            var room           = builder.BuildRoom(detail.BlocksPerRoom, detail.TilesPerBlock);

            room = room.AddDoor(1);
            room = room.AddDoor(2);
            room = room.AddDoor(3);
            room = room.AddDoor(4);

            var expected = GetExpectationForTestRoom(testRoom);
            var actual   = room.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        internal static IRandomNumberGenerator GetGenerator(int testNum)
        {
            var generator = new FakeRandomNumberGenerator();

            switch (testNum)
            {
            case 1:
            case 2:
                generator.PopulateEnum(Compass4Points.South, Compass4Points.North);
                generator.PopulateDice(1, 0, 1, 1, 1);
                break;

            default: throw new ArgumentException($"Didn't have Generator for [{testNum}]");
            }

            return(generator);
        }
        public void BuildTilesFromInputString(int testNumber)
        {
            var input             = GetInputString(testNumber);
            var registry          = new DispatchRegistry();
            var fakeRandomNumbers = new FakeRandomNumberGenerator();
            var tiles             = TilesBuilder.BuildTiles(input, registry, fakeRandomNumbers);

            var actual   = tiles.ToString();
            var expected = GetExpectedTiles(testNumber);

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actual);
        }
        public void BuildRoom_ShouldBuildARoom_WithWalls(StandardTestRoom testRoom)
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator().PopulateRandomForTestRoom(testRoom);
            var registry          = new DispatchRegistry();
            var builder           = new RoomBuilder(fakeRandomNumbers, new FakeLogger(_output), registry);

            var room   = builder.BuildRoom(GetNumBlocks(testRoom), 4);
            var actual = room.ToString();

            var expected = StandardTestRooms.GetExpectation(testRoom);

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine("Test Room " + testRoom);
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);

            Assert.Equal(expected, actual);
        }
        internal static IRandomNumberGenerator GetGenerator(Test test)
        {
            var generator = new FakeRandomNumberGenerator();

            switch (test)
            {
            case Test.TopLeft:
                generator.PopulateEnum(Compass4Points.West, Compass4Points.North, Compass4Points.East, Compass4Points.East, Compass4Points.East);
                generator.PopulateDice(0, 1);
                break;

            case Test.TopRight:
                generator.PopulateEnum(Compass4Points.North, Compass4Points.East, Compass4Points.South, Compass4Points.East, Compass4Points.East);
                generator.PopulateDice(1, 1);
                break;

            case Test.BottomRight:
                generator.PopulateEnum(Compass4Points.South, Compass4Points.West, Compass4Points.East, Compass4Points.East, Compass4Points.East);
                generator.PopulateDice(1, 0);
                break;

            case Test.BottomLeft:
                generator.PopulateEnum(Compass4Points.South, Compass4Points.West, Compass4Points.North, Compass4Points.East, Compass4Points.East);
                generator.PopulateDice(0, 0);
                break;

            case Test.Cornered:
                generator.PopulateEnum(Compass4Points.West, Compass4Points.South, Compass4Points.East, Compass4Points.East, Compass4Points.East);
                generator.PopulateDice(3, 4, 0, 0, 1, 1, 4, 2);
                break;

            default: throw new ArgumentException($"Didn't have Generator for [{test}]");
            }

            return(generator);
        }
        internal static IRandomNumberGenerator CreateGenerator(int numBlocks)
        {
            var random = new FakeRandomNumberGenerator();

            random.PopulateEnum(
                Compass4Points.East,
                Compass4Points.East,
                Compass4Points.South,
                Compass4Points.North,
                Compass4Points.East,
                Compass4Points.North,
                Compass4Points.West,
                Compass4Points.South,
                Compass4Points.South,
                Compass4Points.West,
                Compass4Points.West
                );

            var start             = 1;
            var posOfNonConnected = numBlocks - 1;

            random.PopulateDice(start, start, posOfNonConnected, posOfNonConnected, -1, 0, 1, 3, 0, 0, 2);
            return(random);
        }
Exemplo n.º 7
0
        public void PlaceTwoRooms_WherePlacingTheSecondRoomCausesMazeToGrow()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupTwoRooms()
            {
                fakeRandomNumbers
                .PopulateRandomForRoomCount(2)
                .PopulateRandomForTestRoom(StandardTestRoom.Second)
                .PopulateRandomForTestRoom(StandardTestRoom.Second)
                ;
            }

            void SetupDoorForFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(0, 0)               // Door placement, should be empty tile to walk from, but it is a wall, top left corner
                .AddCoordinates(3, 3)               // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                ;
            }

            void SetupDoorForSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(5, 9)               // Door placement, should be empty tile to walk from, but it is a wall, bottom right corner
                .AddCoordinates(4, 8)               // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                ;
            }

            void SetupCoordinatesForPlacingFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(3, 3)     // should succeed
                ;
            }

            void SetupCoordinatesForPlacingSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(17, 15)     // placing room outside of maze
                .AddCoordinates(17, 15)     // placing room outside of maze
                .AddCoordinates(17, 15)     // placing room outside of maze, show grow after third attempt
                .AddCoordinates(17, 15)     // placing room outside of old maze, now inside new maze so succeeds
                ;
            }

            var registry   = new DispatchRegistry();
            var dispatcher = new Dispatcher(registry);

            SetupTwoRooms();
            SetupDoorForFirstRoom();
            SetupDoorForSecondRoom();
            SetupCoordinatesForPlacingFirstRoom();
            SetupCoordinatesForPlacingSecondRoom();

            var fakeLogger     = new FakeLogger(_output);
            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(1, connectTunnels: false);

            var expected     = GetExpectation(2);
            var actual       = (Maze)registry.GetDispatchee("Maze1");
            var actualString = actual.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actualString);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actualString);
        }
Exemplo n.º 8
0
        public void PlaceTwoRooms_WhereFirstAndSecondDoNotOverlap()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupTwoRooms()
            {
                fakeRandomNumbers
                .PopulateRandomForRoomCount(2)
                .PopulateRandomForTestRoom(StandardTestRoom.First)
                .PopulateRandomForTestRoom(StandardTestRoom.First)
                ;
            }

            void SetupDoors()
            {
                fakeRandomNumbers
                .AddCoordinates(2, 2)              // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.West) // direction to walk to find a wall and place a door
                .AddCoordinates(3, 3)              // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.East) // direction to walk to find a wall and place a door
                ;
            }

            void SetupCoordinatesForPlacingFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(1, 1)     // too close to edge of maze, should fail
                .AddCoordinates(2, 2)     // too close to edge of maze, should fail
                .AddCoordinates(3, 3)     // should succeed
                ;
            }

            void SetupCoordinatesForPlacingSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(4, 4)     // overlaps first so should fail
                .AddCoordinates(6, 6)     // too near first so should fail
                .AddCoordinates(17, 10)   // does not overlap and not close so should succeed
                ;
            }

            var registry   = new DispatchRegistry();
            var dispatcher = new Dispatcher(registry);

            SetupTwoRooms();
            SetupDoors();
            SetupCoordinatesForPlacingFirstRoom();
            SetupCoordinatesForPlacingSecondRoom();

            var fakeLogger     = new FakeLogger(_output);
            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(1, connectTunnels: false);

            var expected     = GetExpectation(1);
            var actual       = (Maze)registry.GetDispatchee("Maze1");
            var actualString = actual.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actualString);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actualString);
        }
Exemplo n.º 9
0
 public DeterministicKexFac(IKeyAgreementFactory other, FakeRandomNumberGenerator rng)
 {
     _other = other;
     _rng   = rng;
 }
Exemplo n.º 10
0
        public void ReferenceTest1()
        {
            var message1 = new byte[] { 0x3c, 0x07, 0x3f, 0x70, 0xe7, 0xee, 0x7f, 0x88, 0x34, 0x14, 0x8e, 0x1a, 0xb8, 0xb4, 0xd4, 0x33 };
            var message2 = new byte[] { 0x73, 0x17, 0xa6, 0x4a, 0x5c, 0xb5, 0x1c, 0x5f, 0xda, 0x61, 0x33, 0x4e, 0xde, 0x38, 0x54, 0x97, 0xc6, 0x95, 0x14, 0xc6, 0x4b, 0x60, 0xf8, 0xd5, 0x32, 0x37, 0x38, 0xc8, 0x01, 0x38, 0x28, 0x8b };
            var message3 = new byte[] { 0x32, 0x12, 0x57, 0x18, 0x87, 0xa2, 0x26, 0x2a, 0x91, 0x3e, 0xf1, 0xa5, 0x07, 0x76, 0x0f, 0x6d, 0xa2, 0x09, 0x6a, 0x7b, 0xa4, 0x59, 0x5d, 0xc6, 0x2b, 0xca, 0x0e, 0xce, 0xd2, 0xf7, 0xb3, 0x4f, 0x01, 0x52, 0x1c, 0x07, 0x59, 0x06, 0x7b, 0x2a, 0x4c, 0x57, 0xeb, 0x45, 0x64, 0x37, 0x9c, 0xe5, 0x22, 0xcd, 0x77, 0x19, 0x29, 0xe3, 0x6e, 0x21, 0xbf, 0x11, 0x40, 0x6a, 0x89, 0xc8, 0x8f, 0xb0, 0x2b, 0x8e, 0x2a, 0x33, 0x2c, 0xce, 0x24, 0x9f, 0xed, 0xec, 0x3a, 0x50, 0xae, 0x69, 0xcd, 0x99, 0xac, 0x92, 0xd7, 0xaa, 0xe7, 0xca, 0xbf, 0x7b, 0xc4, 0x36, 0xd7, 0xd8, 0x16, 0xf4, 0x59, 0x30, 0xc4, 0x8c, 0x10, 0x66, 0x6a, 0xb6, 0xf2, 0x18, 0x69, 0x8c, 0xae, 0x38, 0x32, 0x54, 0x12, 0xcb, 0x5c, 0xc7, 0x92, 0x3b, 0x3a, 0x71, 0xa4, 0xfd, 0x81, 0x46, 0xf6, 0x7d, 0xf9, 0x97, 0xeb, 0xf2, 0x5c, 0xfc, 0x4f, 0x3c, 0x9c, 0x6f, 0xd8, 0x42, 0x24, 0x11, 0x16, 0xbd, 0xaa, 0x38, 0x0f, 0x0e, 0xe2, 0x92, 0x83, 0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x8a, 0x07, 0x0d, 0x08, 0x11, 0xb4, 0xed, 0x19, 0xa3, 0xdb, 0xa8, 0x02, 0x4f, 0x3c, 0x1e, 0x39, 0xb0, 0x29, 0xc6, 0xa9, 0x24, 0xdc, 0x2d, 0x94, 0xf6, 0x08, 0x40, 0x29, 0xab, 0x9c, 0x48, 0xe9, 0x6f, 0x2b, 0x7e, 0xc1, 0xd8, 0x93, 0xde, 0x33, 0x51, 0x69, 0xcd, 0xf3, 0x91, 0xd9, 0x29, 0xa7, 0x96, 0x29, 0xdb, 0xc3, 0xcb, 0xa2, 0xa4, 0x40, 0x52, 0x83, 0x77, 0x5b, 0x48, 0xb5, 0xbf, 0xb7, 0xde, 0x78, 0x1e, 0xc3, 0xcb, 0xb6, 0x04, 0x97, 0xf6, 0x0f, 0x4b, 0x94, 0xc8, 0xc6, 0xa6, 0x6d, 0x6c, 0x09, 0x45, 0x72, 0x7e, 0x07, 0x1d, 0xc5, 0x77, 0xc8, 0x48, 0x21, 0xa2, 0xba, 0xad, 0xe0, 0x4d, 0xef, 0x4b, 0x4c, 0x55, 0x18, 0xed, 0x52, 0x32, 0x67, 0xea, 0x8d, 0x40, 0x2c, 0xab, 0x59, 0x96, 0x30, 0x49, 0x90, 0xb5, 0x19, 0xef, 0x86, 0xf9, 0x2e, 0x20, 0xa3, 0x4b, 0x8a, 0xfd, 0xe2, 0x9a, 0xfa, 0x99, 0x45, 0x84, 0x72, 0x7f, 0x50, 0x49, 0x85, 0xda, 0x08, 0x3d, 0x7f, 0x0d, 0xe6, 0x0d, 0x35, 0x31, 0xa2, 0x24, 0xda, 0x42, 0x2f, 0x69, 0x58, 0x8b, 0x4a, 0x61, 0xaf, 0xb2, 0x11, 0x4c, 0x36, 0x1a, 0x67, 0x38, 0xc5, 0xd0, 0xac, 0x0c };
            var randomS = new byte[] { 0xc9, 0x06, 0xbc, 0xd2, 0xe9, 0xdb, 0x8f, 0x5e, 0x47, 0x26, 0x91, 0xa0, 0xe4, 0xc9, 0x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 0x78, 0x0b, 0x03, 0xb9, 0x63, 0x50, 0x2d, 0x44, 0x90, 0xd1, 0xf1, 0x36, 0xc9, 0x04, 0x8f, 0xcc, 0x1b, 0xc2, 0xef, 0x76, 0x3b, 0x11, 0x77, 0x59, 0xf4, 0x5b, 0xea, 0xdf, 0x56, 0xd4, 0x81, 0x8b, 0x36, 0xfd, 0x02, 0x06, 0xf1, 0x41, 0x4f, 0x47, 0xbc, 0x59, 0x57, 0x31, 0x9a, 0x1b, 0xfa, 0x8a, 0xf9, 0xd8, 0x3e, 0x0c, 0x28, 0x2c, 0xb1, 0xc2, 0x1d };

            var applicationKey = new byte[] { 0xef, 0x3f, 0xb4, 0x74, 0xe1, 0x41, 0x07, 0x76, 0xe5, 0xbf, 0x85, 0x94, 0xd2, 0x95, 0xb0, 0x5f, 0x3e, 0x04, 0xe2, 0x21, 0xce, 0x5a, 0x3e, 0xf3, 0xee, 0x40, 0xca, 0x33, 0x24, 0x78, 0xbb, 0x78 };
            var privateKeyC    = new byte[] { 0x47, 0x3e, 0x33, 0x6b, 0xa2, 0xc7, 0xfb, 0xae, 0xc3, 0x9f, 0x38, 0xd6, 0x2e, 0x3e, 0x8d, 0xda, 0xc8, 0x8f, 0x09, 0x0f, 0xb6, 0xbe, 0x85, 0xd7, 0x3c, 0xc5, 0xf6, 0x11, 0x39, 0xa6, 0x3b, 0xb0 };
            var privateKeyS    = new byte[] { 0x69, 0xb2, 0x36, 0x09, 0x02, 0x55, 0x3c, 0xf8, 0x65, 0x79, 0x79, 0xfb, 0xea, 0xc6, 0xcf, 0x80, 0x2d, 0x49, 0xd1, 0x30, 0x73, 0xd9, 0xa7, 0x11, 0x48, 0x4f, 0x42, 0x9f, 0x85, 0x12, 0x11, 0x40 };

            //var rng = new RandomNumberGenerator();
            //message1 = rng.Generate(16);
            //message2 = rng.Generate(32);
            //message3 = rng.Generate(256 - 16);
            //randomC = rng.Generate(256);
            //randomS = rng.Generate(256);
            //applicationKey = rng.Generate(32);
            //privateKeyC = KeyGeneration.GeneratePrivateKey();
            //privateKeyS = KeyGeneration.GeneratePrivateKey();

            //BytePrintHelper.PrintAsByteArray(nameof(message1), message1);
            //BytePrintHelper.PrintAsByteArray(nameof(message2), message2);
            //BytePrintHelper.PrintAsByteArray(nameof(message3), message3);
            //BytePrintHelper.PrintAsByteArray(nameof(randomC), randomC);
            //BytePrintHelper.PrintAsByteArray(nameof(randomS), randomS);
            //BytePrintHelper.PrintAsByteArray(nameof(applicationKey), applicationKey);
            //BytePrintHelper.PrintAsByteArray(nameof(privateKeyC), privateKeyC);
            //BytePrintHelper.PrintAsByteArray(nameof(privateKeyS), privateKeyS);

            var ec1  = new byte[] { 0xd4, 0xf7, 0xd4, 0x89, 0x86, 0xdc, 0x90, 0xc8, 0x62, 0x5b, 0xb7, 0x8d, 0xc5, 0x25, 0x51, 0xd4, 0xb1, 0x4b, 0xdd, 0x0d, 0x6f, 0xda, 0x36, 0x98, 0x3e, 0xb9, 0xd0, 0x1e, 0x90, 0x93, 0x7d, 0x7c, 0x3d, 0x96, 0x17, 0xe1, 0x9e, 0x13, 0xa8, 0xec, 0x29, 0x7f, 0xac, 0x75, 0xaf, 0xff, 0x65, 0xf7, 0x1a, 0xf8, 0xc3, 0x52, 0xa1, 0xb7, 0x6f, 0x8d, 0x37, 0x1b, 0xc5, 0xec, 0x53, 0x18, 0xfe, 0x42, 0x1e, 0x21, 0xf1, 0xf2, 0xbc, 0x36, 0x45, 0xee, 0xe4, 0x12, 0xb9, 0xb2, 0xac, 0x7e, 0x46, 0xd0, 0xe9, 0x7f, 0x43, 0xf3, 0xa9, 0xe8, 0xa5, 0xec, 0xf4, 0xcf, 0xa9, 0x27, 0x16, 0x72, 0x30, 0xd4, 0xb0, 0x42, 0x31, 0x71, 0xa5, 0xfc, 0xe6, 0x52, 0xe5, 0x56, 0x62, 0x26, 0x64, 0x3e, 0xe7, 0xa3, 0x39, 0x0a, 0x1f, 0x24, 0x2a, 0xac, 0xf8, 0xb5, 0x37,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, 0xc8, 0x50, 0xf1, 0x40, 0xcb, 0x04, 0x73, 0xb6, 0x38, 0x5d, 0xbc, 0xcb, 0xbd, 0xff, 0xf9, 0xbb, 0xdc, 0x67, 0x78, 0xed, 0xd9, 0xbb, 0x52, 0x72, 0x3e, 0x1b, 0xe9, 0x20, 0x87, 0x79, 0x09, 0xfc, 0x29, 0xbf, 0x4e, 0x62, 0x9c, 0x13, 0x31, 0x21, 0xc9, 0x71, 0xd2, 0x66, 0x5e, 0x47, 0xca, 0xee, 0xa2, 0x5f, 0x4a, 0x95, 0xb3, 0x67, 0x36, 0x00, 0x73, 0x19, 0x4f, 0x86, 0xab, 0xf1, 0x3e, 0xd4, 0xce, 0x0c, 0x9a, 0xf3, 0x68, 0x03, 0x8a, 0x36, 0x79, 0x6e, 0xb6, 0x0a, 0x7d, 0x59, 0x64, 0xf1, 0xd0, 0x32, 0xa9, 0x40, 0x94, 0x93, 0x71, 0x5e, 0x36, 0x72 };
            var ec3  = new byte[] { 0xa0, 0xd7, 0xb7, 0xfa, 0x7e, 0x1b, 0xbc, 0xad, 0xce, 0x9b, 0x4b, 0xdd, 0xfc, 0x27, 0x3f, 0x06, 0x2e, 0xef, 0x91, 0xf3, 0x4e, 0x5b, 0xd9, 0xfd, 0x86, 0x81, 0x4f, 0x1f, 0xa9, 0x3f, 0x26, 0xd4, 0x0d, 0xdc, 0x48, 0x5c, 0x0b, 0xe8, 0xbf, 0x70, 0xa5, 0xe2, 0xc5, 0xa9, 0x62, 0xde, 0xf9, 0x0b, 0xbc, 0xe6, 0xcd, 0x9a, 0x47, 0x4c, 0x99, 0xa8, 0xe8, 0x11, 0x9c, 0x00, 0x0d, 0x80, 0x68, 0xdf };
            var es4  = new byte[] { 0x29, 0xa8, 0xbb, 0x57, 0x5f, 0xa5, 0x00, 0x07, 0x8a, 0x4a, 0x56, 0x47, 0x2b, 0xc5, 0x50, 0x3f, 0x3b, 0x7f, 0xe8, 0x5d, 0x6e, 0x7f, 0x8d, 0x5e, 0x98, 0x68, 0x90, 0x9a, 0x2c, 0x5b, 0xb9, 0x89 };
            var ec6  = new byte[] { 0x29, 0x3f, 0x3d, 0x0f, 0xf8, 0xad, 0x1f, 0xe2, 0x17, 0x69, 0x8f, 0x26, 0xf4, 0x40, 0xe0, 0x87, 0x25, 0xe1, 0xcc, 0x1b, 0x91, 0x89, 0x70, 0x88, 0x38, 0xbc, 0x49, 0x90, 0x2f, 0x68, 0x9f, 0xb2, 0xcc, 0x3b, 0x43, 0xd7, 0xea, 0x95, 0xf7, 0xd3, 0x53, 0x44, 0x41, 0x7b, 0x80, 0x0c, 0xe5, 0x2d, 0x8d, 0x97, 0x29, 0x40, 0xac, 0xd0, 0x5d, 0xbd, 0xea, 0xec, 0xaf, 0xa3, 0xcb, 0x7a, 0x77, 0x77 };
            var es7  = new byte[] { 0x3c, 0x07, 0x3f, 0x70, 0xe7, 0xee, 0x7f, 0x88, 0x34, 0x14, 0x8e, 0x1a, 0xb8, 0xb4, 0xd4, 0x33 };
            var es8  = new byte[] { 0x17, 0x57, 0x08, 0x06, 0xa3, 0x70, 0x18, 0xf2, 0xda, 0xaf, 0x2e, 0x87, 0x7d, 0xc8, 0xa5, 0x3e, 0xc2, 0xcb, 0x63, 0x40, 0xaa, 0x9a, 0xfb, 0xd7, 0x9a, 0x7b, 0xca, 0xe5, 0xfe, 0x3e, 0xed, 0x04, 0xaf, 0x56, 0x97, 0x2c, 0x9e, 0x3a, 0xea, 0xaa, 0x68, 0x9b, 0x4d, 0xd8, 0x9f, 0xe7, 0x25, 0x15, 0xb5, 0xf6, 0x69, 0x1a, 0xde, 0x61, 0xe2, 0x6e, 0xe9, 0x19, 0xd7, 0x4b, 0x05, 0x01, 0xaf, 0x3d, 0x0d, 0x2b, 0x35, 0x9a, 0xf3, 0x2c, 0xee, 0xeb, 0x0a, 0x68, 0x47, 0xe5, 0xd2, 0xf2, 0xee, 0x90 };
            var ec9  = new byte[] { 0x73, 0x17, 0xa6, 0x4a, 0x5c, 0xb5, 0x1c, 0x5f, 0xda, 0x61, 0x33, 0x4e, 0xde, 0x38, 0x54, 0x97, 0xc6, 0x95, 0x14, 0xc6, 0x4b, 0x60, 0xf8, 0xd5, 0x32, 0x37, 0x38, 0xc8, 0x01, 0x38, 0x28, 0x8b };
            var ec10 = new byte[] { 0xf7, 0x11, 0x86, 0xd0, 0x87, 0x67, 0xf2, 0xf1, 0x98, 0x75, 0xe4, 0x12, 0xd6, 0xff, 0x75, 0x4d, 0xfd, 0x23, 0x8a, 0xf8, 0x71, 0x00, 0x0f, 0xe1, 0x19, 0x74, 0x17, 0x0d, 0xc0, 0xf1, 0xb1, 0x75, 0x2b, 0x74, 0xf7, 0x5e, 0xd2, 0x58, 0x01, 0x2a, 0xa4, 0x39, 0x51, 0xe3, 0x6f, 0x5b, 0x24, 0x01, 0x19, 0x86, 0x9a, 0xf6, 0x8c, 0x37, 0x43, 0xb1, 0xfd, 0x0a, 0xc0, 0x37, 0xd0, 0x02, 0x0a, 0xc8, 0x1c, 0x74, 0x2b, 0x26, 0x17, 0xde, 0x34, 0x0a, 0x21, 0x8b, 0xda, 0x1f, 0xae, 0x19, 0x81, 0x14, 0x97, 0x60, 0x62, 0x38, 0x48, 0xb0, 0x99, 0x3e, 0x82, 0x19, 0xad, 0xdd, 0xb3, 0x4e, 0x63, 0x9f, 0x4f, 0x25, 0xe7, 0x43, 0xe7, 0x30, 0x1b, 0xde, 0x14, 0x8b, 0x55, 0xd7, 0xe9, 0x69, 0x75, 0x03, 0x36, 0xce, 0xd7, 0xab, 0x00, 0x4e, 0x1c, 0xaa, 0xfd, 0xd7, 0x35, 0x1f, 0x45, 0x79, 0x02, 0x7a, 0x86, 0x1c, 0x7b, 0x1e, 0xbc, 0x13, 0x1f, 0xa6, 0x1e, 0x10, 0x27, 0xcd, 0xb4, 0x20, 0x8d, 0xbd, 0x1e, 0xe1, 0x6b, 0xe2, 0xfb, 0xfd, 0xc5, 0x54, 0xf5, 0x70, 0x54, 0xb9, 0xe2, 0x53, 0xe0, 0x5a, 0x7b, 0xed, 0x0a, 0x7e, 0x24, 0xa8, 0x39, 0x42, 0x5b, 0xa3, 0x90, 0x81, 0x96, 0x15, 0x97, 0xd0, 0x0a, 0x5f, 0x4a, 0x33, 0xfb, 0x1b, 0x73, 0x29, 0x09, 0xa4, 0x8d, 0xb9, 0xcc, 0xf5, 0xcd, 0x5f, 0x0b, 0x41, 0xf2, 0xf7, 0xd1, 0xc9, 0xab, 0x9f, 0x4d, 0x63, 0x38, 0xaa, 0x68, 0x52, 0xcc, 0xe9, 0x3d, 0x72, 0x68, 0xcf, 0xa9, 0x96, 0x9b, 0xa8, 0x63, 0xb3, 0xa9, 0xb2, 0x44, 0x70, 0x92, 0x7d, 0x1c, 0x51, 0x30, 0xb0, 0x3a, 0xd2, 0x28, 0xb1, 0x02, 0x01, 0xf0, 0x0d, 0x28, 0x35, 0x5d, 0x44, 0x3a, 0x1d, 0xc9, 0xc4, 0xc5, 0x1a, 0x3d, 0xd4, 0xdf, 0xb6, 0x1b, 0xbb, 0xb8, 0x38, 0x95, 0xde };
            var es11 = new byte[] { 0x32, 0x12, 0x57, 0x18, 0x87, 0xa2, 0x26, 0x2a, 0x91, 0x3e, 0xf1, 0xa5, 0x07, 0x76, 0x0f, 0x6d, 0xa2, 0x09, 0x6a, 0x7b, 0xa4, 0x59, 0x5d, 0xc6, 0x2b, 0xca, 0x0e, 0xce, 0xd2, 0xf7, 0xb3, 0x4f, 0x01, 0x52, 0x1c, 0x07, 0x59, 0x06, 0x7b, 0x2a, 0x4c, 0x57, 0xeb, 0x45, 0x64, 0x37, 0x9c, 0xe5, 0x22, 0xcd, 0x77, 0x19, 0x29, 0xe3, 0x6e, 0x21, 0xbf, 0x11, 0x40, 0x6a, 0x89, 0xc8, 0x8f, 0xb0, 0x2b, 0x8e, 0x2a, 0x33, 0x2c, 0xce, 0x24, 0x9f, 0xed, 0xec, 0x3a, 0x50, 0xae, 0x69, 0xcd, 0x99, 0xac, 0x92, 0xd7, 0xaa, 0xe7, 0xca, 0xbf, 0x7b, 0xc4, 0x36, 0xd7, 0xd8, 0x16, 0xf4, 0x59, 0x30, 0xc4, 0x8c, 0x10, 0x66, 0x6a, 0xb6, 0xf2, 0x18, 0x69, 0x8c, 0xae, 0x38, 0x32, 0x54, 0x12, 0xcb, 0x5c, 0xc7, 0x92, 0x3b, 0x3a, 0x71, 0xa4, 0xfd, 0x81, 0x46, 0xf6, 0x7d, 0xf9, 0x97, 0xeb, 0xf2, 0x5c, 0xfc, 0x4f, 0x3c, 0x9c, 0x6f, 0xd8, 0x42, 0x24, 0x11, 0x16, 0xbd, 0xaa, 0x38, 0x0f, 0x0e, 0xe2, 0x92, 0x83, 0x54, 0x0f, 0xd3, 0x6e, 0xe5, 0x2a, 0x36, 0x77, 0x14, 0x80, 0x5e, 0xf9, 0x1f, 0x5b, 0xd0, 0xb5, 0xb5, 0x57, 0x5b, 0xf1, 0x79, 0xf8, 0x30, 0x74, 0xb6, 0xbf, 0xcb, 0x4c, 0x66, 0x32, 0xeb, 0x3a, 0xed, 0x80, 0x5b, 0xd6, 0xd8, 0x57, 0xf8, 0xec, 0xf8, 0x53, 0x05, 0x9a, 0xcc, 0x7b, 0x73, 0x9a, 0xfc, 0xe3, 0x40, 0xef, 0xbb, 0x96, 0x7a, 0x98, 0x9d, 0x73, 0x1b, 0x88, 0x40, 0xbd, 0x94, 0xfc, 0x21, 0x0b, 0x0c, 0xba, 0xf6, 0xc8, 0x53, 0x3a, 0xdf, 0x1a, 0x87, 0xdc, 0xfe, 0x15, 0xa7, 0xbc, 0x0e, 0x3b, 0x3a, 0x67, 0x3b, 0x40, 0xfd, 0xab, 0xa8, 0x75, 0xa0, 0xbf, 0x6a };


            var configC = new MicroRatchetConfiguration
            {
                IsClient           = true,
                MaximumMessageSize = 256,
                MinimumMessageSize = 32,
                ApplicationKey     = applicationKey
            };
            var configS = new MicroRatchetConfiguration
            {
                IsClient           = false,
                MaximumMessageSize = 256,
                MinimumMessageSize = 32,
                ApplicationKey     = applicationKey
            };

            var rngC       = new FakeRandomNumberGenerator(randomC);
            var signatureC = new Signature(privateKeyC, new SecureRandom(rngC));
            var rngS       = new FakeRandomNumberGenerator(randomS);
            var signatureS = new Signature(privateKeyS, new SecureRandom(rngS));

            var servicesC = new BouncyCastleServices(privateKeyC)
            {
                Signature             = signatureC,
                RandomNumberGenerator = rngC,
            };

            servicesC.KeyAgreementFactory = new DeterministicKexFac(servicesC.KeyAgreementFactory, rngC);

            var servicesS = new BouncyCastleServices(privateKeyS)
            {
                Signature             = signatureS,
                RandomNumberGenerator = rngS,
            };

            servicesS.KeyAgreementFactory = new DeterministicKexFac(servicesS.KeyAgreementFactory, rngS);

            var C = new MicroRatchetContext(servicesC, configC, null);
            var S = new MicroRatchetContext(servicesS, configS, null);

            var c1 = C.InitiateInitialization();
            var s2 = S.Receive(c1).ToSendBack;
            var c3 = C.Receive(s2).ToSendBack;
            var s4 = S.Receive(c3).ToSendBack;
            var c5 = C.Receive(s4).ToSendBack;

            //BytePrintHelper.PrintAsByteArray("ec1", c1);
            //BytePrintHelper.PrintAsByteArray("es2", s2);
            //BytePrintHelper.PrintAsByteArray("ec3", c3);
            //BytePrintHelper.PrintAsByteArray("es4", s4);

            Assert.Equal(ec1, c1);
            Assert.Equal(es2, s2);
            Assert.Equal(ec3, c3);
            Assert.Equal(es4, s4);
            Assert.Null(c5);

            var c6  = C.Send(message1);
            var s7  = S.Receive(c6).Payload;
            var s8  = S.Send(message2);
            var c9  = C.Receive(s8).Payload;
            var c10 = C.Send(message3);
            var s11 = S.Receive(c10).Payload;

            //BytePrintHelper.PrintAsByteArray("ec6", c6);
            //BytePrintHelper.PrintAsByteArray("es7", s7);
            //BytePrintHelper.PrintAsByteArray("es8", s8);
            //BytePrintHelper.PrintAsByteArray("ec9", c9);
            //BytePrintHelper.PrintAsByteArray("ec10", c10);
            //BytePrintHelper.PrintAsByteArray("es11", s11);

            Assert.Equal(ec6, c6);
            Assert.Equal(es7, s7);
            Assert.Equal(es8, s8);
            Assert.Equal(ec9, c9);
            Assert.Equal(ec10, c10);
            Assert.Equal(es11, s11);

            Assert.Equal(message1, s7);
            Assert.Equal(message2, c9);
            Assert.Equal(message3, s11);
        }
Exemplo n.º 11
0
        public void PlaceDoor_InLShapedTestRooms()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupStandardRoom()
            {
                fakeRandomNumbers.PopulateRandomForTestRoom(StandardTestRoom.Third)
                ;
            }

            void SetupDoorForStandardRoom()
            {
                fakeRandomNumbers
                // find walls
                .AddCoordinates(0, 0)               // Door placement, top left corner, will try again
                .AddCoordinates(0, 3)               // Door placement, top row, horizontal wall, will try again
                .AddCoordinates(0, 5)               // Door placement, top right corner of L, will try again
                .AddCoordinates(4, 5)               // Door placement, middle corner of L, will try again
                .AddCoordinates(4, 6)               // Door placement, horizontal wall in middle, will try again
                .AddCoordinates(4, 9)               // Door placement, far right corner of L, will try again
                .AddCoordinates(6, 9)               // Door placement, horizontal wall at far right L, will try again
                .AddCoordinates(9, 9)               // Door placement, bottom right corner of L, will try again
                .AddCoordinates(9, 6)               // Door placement, horizontal wall at bottom L, will try again
                .AddCoordinates(9, 0)               // Door placement, bottom left corner of L, will try again
                .AddCoordinates(9, 5)               // Door placement, horizontal wall at far left of L, will try again
                                                    //find rocks
                .AddCoordinates(0, 6)               // Door placement, rock outside room, will try again
                .AddCoordinates(0, 9)               // Door placement, rock edge of space, will try again
                .AddCoordinates(1, 8)               // Door placement, rock surrounded by other rocks, will try again
                                                    // find corner of L, starting from valid tile
                .AddCoordinates(4, 4)               // Door placement, valid tile
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door, will find corner and try again
                .AddCoordinates(5, 5)               // Door placement, valid tile
                .AddDirection(Compass8Points.North) // // direction to walk to find a wall and place a door, will find corner and try again
                                                    // place doors
                .AddCoordinates(4, 4)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                .AddCoordinates(5, 5)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door
                .AddCoordinates(5, 5)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 4)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.West)  // direction to walk to find a wall and place a door
                ;
            }

            var registry = new DispatchRegistry();

            SetupStandardRoom();
            SetupDoorForStandardRoom();

            var fakeLogger = new FakeLogger(_output);

            var builder = new RoomBuilder(fakeRandomNumbers, fakeLogger, registry);

            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithThreeBlocks();
            var detail         = mazeDescriptor[1];
            var room           = builder.BuildRoom(detail.BlocksPerRoom, detail.TilesPerBlock);

            room = room.AddDoor(1);
            room = room.AddDoor(2);
            room = room.AddDoor(3);
            room = room.AddDoor(4);

            var expected = GetExpectationForTestRoom(StandardTestRoom.Third);
            var actual   = room.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actual);
        }