예제 #1
0
    def test_forward_distance_bounds_and_type(self):
        self.begin_for_testing()

        with self.assertRaisesRegexp(
                AssertionError,
                "Oops, forward\(0\) won't work. Distance must be a whole number between 1 and 1000."
        ):
            forward(0)

        with self.assertRaisesRegexp(
                AssertionError,
                "Oops, forward\(-1\) won't work. Distance must be a whole number between 1 and 1000."
        ):
            forward(-1)

        with self.assertRaisesRegexp(
                AssertionError,
                "Oops, forward\(1001\) won't work. Distance must be a whole number between 1 and 1000."
        ):
            forward(1001)

        with self.assertRaisesRegexp(
                AssertionError,
                "Oops, forward\(1.1\) won't work. Distance must be a whole number between 1 and 1000."
        ):
            forward(1.1)

        with self.assertRaisesRegexp(
                AssertionError,
                "Oops, forward\(abc\) won't work. Distance must be a whole number between 1 and 1000."
        ):
            forward('abc')
예제 #2
0
 def test_peek_limit(self):
     self.begin_for_testing()
     down(90)
     forward(300)
     self.assertEqual(None, peek())
     up(180)
     forward(700)
예제 #3
0
    def test_delay(self):
        self.begin_for_testing()
        delay(1)
        forward(2)
        delay(2)
        forward(1)

        self.assertEqual([1, 1, 2], self.slept)
예제 #4
0
    def test_track_spawned_entities(self):
        self.begin_for_testing()
        pen_down(living.OCELOT)
        forward(2)

        self.assertEqual({
            "uuid1": living.OCELOT,
            "uuid2": living.OCELOT
        }, living_things())
예제 #5
0
    def test_forward(self):
        self.begin_for_testing()
        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (100, 200, 302): ("piston", {
                    "facing": "south"
                })
            }, self.game.tiles)
예제 #6
0
    def test_turn_45_degrees(self):
        self.begin_for_testing()
        left(45)
        forward(4)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (101, 200, 301): "gold_block",
                (102, 200, 302): ("piston", {
                    "facing": "south"
                })
            }, self.game.tiles)
예제 #7
0
    def test_forward_outside_of_game_boundaries_just_doesnt_attempt_to_lay_blocks__less_than_min_y(
            self):
        self.game.player.tile_pos = Vector(100, 2, 300)
        self.game.player.rotation = 2
        self.begin_for_testing(start_distance_from_player=5)

        down(90)
        forward(10)

        self.assertEqual(
            {
                (100, 2, 305): "gold_block",
                (100, 1, 305): "gold_block",
                (100, 0, 305): "gold_block"
            }, self.game.tiles)
예제 #8
0
    def test_forward_and_back_return_block_info_of_where_turtle_ended_up(self):

        # the fake is hard-coded to always return a piston.

        self.begin_for_testing()
        self.assertEqual(back(1), block.PISTON)
        self.assertEqual(forward(2), block.PISTON)
예제 #9
0
    def test_spawn_entity(self):
        self.begin_for_testing()
        pen_down(living.OCELOT)
        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "air",
                (100, 200, 301): "air",
                (100, 200, 302): ("piston", {
                    "facing": "south"
                })
            }, self.game.tiles)

        self.assertEqual([(100, 200, 300, 'ocelot', {
            'owner': 'papadapadapa'
        }), (100, 200, 301, 'ocelot', {
            'owner': 'papadapadapa'
        })], self.game.entity.entities_created)
예제 #10
0
    def test_show_that_pen_up_is_currently_destructive(self):

        # future: enhance the library so that this isn't destructive

        self.begin_for_testing()
        forward(3)

        self.begin_for_testing()
        pen_up()
        forward(1)

        self.assertEqual(
            {
                (100, 200, 300): "air",
                (100, 200, 301): ("piston", {
                    "facing": "south"
                }),  # the second turtle, overwriting the first path
                (100, 200, 302): "gold_block",
                (100, 200, 303): ("piston", {
                    "facing": "south"
                })  # the original turtle
            },
            self.game.tiles)
예제 #11
0
    def test_living_entity_tasks(self):
        self.begin_for_testing()
        pen_down(living.OCELOT)
        forward(2)
        pen_down(living.WOLF)
        forward(1)

        self.assertEqual(
            {
                "uuid1": living.OCELOT,
                "uuid2": living.OCELOT,
                "uuid3": living.WOLF
            }, living_things())

        start_task(living.OCELOT.SIT)

        self.assertEqual([("uuid1", "sit"), ("uuid2", "sit")],
                         sorted(self.game.entity.tasks_in_progress)
                         )  # by default, only ocelots are selected

        reset_task(living.OCELOT.SIT)

        self.assertEqual([], self.game.entity.tasks_in_progress)
예제 #12
0
    def test_down_90(self):
        self.begin_for_testing()
        forward(1)
        down(90)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): ("piston", {
                    "facing": "down"
                })
            }, self.game.tiles)

        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (100, 199, 301): "gold_block",
                (100, 198, 301): ("piston", {
                    "facing": "down"
                })
            }, self.game.tiles)
예제 #13
0
    def test_left_90(self):
        self.begin_for_testing()
        forward(1)
        left(90)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): ("piston", {
                    "facing": "east"
                })
            }, self.game.tiles)

        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (101, 200, 301): "gold_block",
                (102, 200, 301): ("piston", {
                    "facing": "east"
                })
            }, self.game.tiles)
예제 #14
0
    def test_right_over_360(self):
        self.begin_for_testing()
        forward(1)
        right(3690)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): ("piston", {
                    "facing": "west"
                })
            }, self.game.tiles)

        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (99, 200, 301): "gold_block",
                (98, 200, 301): ("piston", {
                    "facing": "west"
                })
            }, self.game.tiles)
예제 #15
0
    def test_up_over_360(self):
        self.begin_for_testing()
        forward(1)
        up(3690)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): ("piston", {
                    "facing": "up"
                })
            }, self.game.tiles)

        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (100, 201, 301): "gold_block",
                (100, 202, 301): ("piston", {
                    "facing": "up"
                })
            }, self.game.tiles)
예제 #16
0
 def test_some_more_turning(self):
     self.begin_for_testing()
     forward(2)
     right(90)
     forward(2)
     down(90)
     forward(2)
     self.assertEqual(
         {
             (100, 200, 300): "gold_block",
             (100, 200, 301): "gold_block",
             (100, 200, 302): "gold_block",
             (99, 200, 302): "gold_block",
             (98, 200, 302): "gold_block",
             (98, 199, 302): "gold_block",
             (98, 198, 302): ("piston", {
                 "facing": "down"
             })
         }, self.game.tiles)
예제 #17
0
    def test_pen_down_pen_up(self):
        self.begin_for_testing()
        forward(2)
        pen_up()
        forward(2)
        pen_down(block.GOLD_BLOCK)
        forward(2)

        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (100, 200, 302): "air",
                (100, 200, 303): "air",
                (100, 200, 304): "gold_block",
                (100, 200, 305): "gold_block",
                (100, 200, 306): ("piston", {
                    "facing": "south"
                })
            }, self.game.tiles)
예제 #18
0
    def test_show_that_turtle_wont_turn_right_when_going_down_or_up(self):
        self.begin_for_testing()
        forward(2)
        down(90)
        forward(2)
        right(90)
        forward(2)
        self.assertEqual(
            {
                (100, 200, 300): "gold_block",
                (100, 200, 301): "gold_block",
                (100, 200, 302): "gold_block",
                (100, 199, 302): "gold_block",

                # turtle should have gone right but it didn't.
                (100, 198, 302): "gold_block",
                (100, 197, 302): "gold_block",
                (100, 196, 302): ("piston", {
                    "facing": "down"
                })
            },
            self.game.tiles)
예제 #19
0
    def test_basic(self):
        def connect():
            # connect to minecraft server running on localhost, 25565 (default port)
            return mcpi.minecraft.Minecraft.create()

        # mcpi_minecraft.setBlockV2(1, 120, 1, block.STONE.name, variant=block.STONE.VARIANT_ANDESITE.value)
        # mcpi_minecraft.setBlockV2(1, 127, 1, block.STONE.name, block.STONE.VARIANT_ANDESITE)
        # mcpi_minecraft.setBlockV2(1, 130, 1, block.PISTON.name, block.PISTON.FACING_DOWN)

        # mcpi_minecraft.setBlockV2(1, 101, 1, block.DIRT.name)
        # mcpi_minecraft.setBlockV2(1, 102, 1, block.CACTUS.name, block.CACTUS.AGE_15)
        init(connect, "papadapadapa")
        chat("hi")
        # begin()
        # pen_down(block.GOLD_BLOCK)

        # forward()
        # forward()
        # forward()
        # forward()

        # up(90)
        # forward()
        # forward()
        # forward()
        # forward()

        # down(90)
        # right(90)
        # forward()
        # forward()
        # forward()
        # forward()

        # begin()
        # delay(0)
        # up(90)
        # for i in xrange(300):
        #     forward(1)
        # down(180)
        # for i in xrange(300):
        #     forward(1)

        # for i in xrange(10):
        #     for i in xrange(1000):
        #         forward(10)
        #     back(1)
        #     for i in xrange(1000):
        #         forward(10)


        # pen_down(living.COW)

        # for i in xrange(50):
        #         forward()

        # sleep(5)
        # select_living_things(nearby())
        # start_task(living.COW.PANIC)
        # start_task(living.OCELOT.MATE)
        # reset_task(living.OCELOT.FOLLOW_OWNER)
        # start_task(living.OCELOT.OCELOT_ATTACK)
        # start_task(living.OCELOT.LEAP_AT_TARGET)

        # reset_task(living.WOLF.SIT)


        # forward()

        # forward()
        # forward()

        # right(90)
        # forward()
        # forward()

        # up(90)
        # forward()
        # forward()

        # right(90)

        # forward()
        # forward()

        # left(90)

        # forward()
        # forward()

        # left(90)

        # forward()
        # forward()

        # right(90)


        # forward(2)

        # down(90)

        # math bug START

        begin()
        delay(0)
        down(90)
        for _ in xrange(200):
            print forward(1)
예제 #20
0
 def test_not_begun(self):
     with self.assertRaisesRegexp(
             AssertionError,
             re.compile("Oops, there's no current turtle.*", re.MULTILINE)):
         forward(1)
예제 #21
0
    def test_basic(self):
        def connect():
            # connect to minecraft server running on localhost, 25565 (default port)
            return mcpi.minecraft.Minecraft.create()

        # mcpi_minecraft.setBlockV2(1, 120, 1, block.STONE.name, variant=block.STONE.VARIANT_ANDESITE.value)
        # mcpi_minecraft.setBlockV2(1, 127, 1, block.STONE.name, block.STONE.VARIANT_ANDESITE)
        # mcpi_minecraft.setBlockV2(1, 130, 1, block.PISTON.name, block.PISTON.FACING_DOWN)

        # mcpi_minecraft.setBlockV2(1, 101, 1, block.DIRT.name)
        # mcpi_minecraft.setBlockV2(1, 102, 1, block.CACTUS.name, block.CACTUS.AGE_15)
        init(connect, "papadapadapa")
        chat("hi")
        # begin()
        # pen_down(block.GOLD_BLOCK)

        # forward()
        # forward()
        # forward()
        # forward()

        # up(90)
        # forward()
        # forward()
        # forward()
        # forward()

        # down(90)
        # right(90)
        # forward()
        # forward()
        # forward()
        # forward()

        # begin()
        # delay(0)
        # up(90)
        # for i in xrange(300):
        #     forward(1)
        # down(180)
        # for i in xrange(300):
        #     forward(1)

        # for i in xrange(10):
        #     for i in xrange(1000):
        #         forward(10)
        #     back(1)
        #     for i in xrange(1000):
        #         forward(10)

        # pen_down(living.COW)

        # for i in xrange(50):
        #         forward()

        # sleep(5)
        # select_living_things(nearby())
        # start_task(living.COW.PANIC)
        # start_task(living.OCELOT.MATE)
        # reset_task(living.OCELOT.FOLLOW_OWNER)
        # start_task(living.OCELOT.OCELOT_ATTACK)
        # start_task(living.OCELOT.LEAP_AT_TARGET)

        # reset_task(living.WOLF.SIT)

        # forward()

        # forward()
        # forward()

        # right(90)
        # forward()
        # forward()

        # up(90)
        # forward()
        # forward()

        # right(90)

        # forward()
        # forward()

        # left(90)

        # forward()
        # forward()

        # left(90)

        # forward()
        # forward()

        # right(90)

        # forward(2)

        # down(90)

        # math bug START

        begin()
        delay(0)
        down(90)
        for _ in xrange(200):
            print forward(1)