Exemple #1
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())
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
    def test_pen_down_invalid_turtle_trail_property(self):
        self.begin_for_testing()

        with self.assertRaisesRegexp(AssertionError, re.compile("Oops, pen_down\(block\.FLOWER_POT, block.QUARTZ_STAIRS\.FACING_NORTH\) won't work, " + \
            "because block\.QUARTZ_STAIRS.FACING_NORTH not part of block type block\.FLOWER_POT", re.MULTILINE)):
            pen_down(block.FLOWER_POT, block.QUARTZ_STAIRS.FACING_NORTH)

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile("^    block\.FLOWER_POT\.CONTENTS_BLUE_ORCHID",
                           re.MULTILINE)):
            pen_down(block.FLOWER_POT, block.QUARTZ_STAIRS.FACING_NORTH)

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile(
                    "Oops, pen_down\(block.FLOWER_POT, foo, 1\) won't work, because foo, 1 not part of block type block\.FLOWER_POT",
                    re.MULTILINE)):
            pen_down(block.FLOWER_POT, "foo", 1)
Exemple #6
0
    def test_pen_down_invalid_turtle_trail_type(self):
        self.begin_for_testing()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile("Oops, pen_down\(\) won't work\.", re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile(
                    "Trail must be a type of block, or a type of living thing, along with any properties\.",
                    re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile("^Example 1: pen_down\(block.GOLD_BLOCK\)",
                           re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile(
                    "^Example 2: pen_down\(block\.FLOWER_POT, block\.FLOWER_POT\.CONTENTS_BLUE_ORCHID\)",
                    re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile("^    block\.GOLD_BLOCK", re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError, re.compile("^    living\.OCELOT",
                                           re.MULTILINE)):
            pen_down()

        with self.assertRaisesRegexp(
                AssertionError,
                re.compile("Oops, pen_down\(foo, bar, 2\) won't work\.",
                           re.MULTILINE)):
            pen_down("foo", "bar", 2)