Exemple #1
0
    def test_constraints(self):
        """
        In this test, we build a body generator with a maximum
        number of inputs / outputs that is already satisfied
        by the root component, and ensure no further generation
        is done.

        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
                body_spec,
                root_parts=["Core"],
                attach_parts=["2Params"],
                max_inputs=2,
                max_outputs=10,
                max_parts=100,
                fix_num_parts=True
        )

        body = gen.generate()
        self.assertEquals("Core", body.root.type,
                          "Root type should be 'Core' (seed %d)." % seed)
        self.assertEquals(0, len(body.root.child),
                          "Too many inputs were generated (seed %d)." % seed)

        gen.max_inputs = 100
        gen.max_outputs = 2

        body = gen.generate()
        self.assertEquals(0, len(body.root.child),
                          "Too many outputs were generated (seed %d)." % seed)

        # This leaves enough room for a 2Params child, but not enough for a SomePart child
        gen.max_outputs = 4
        body = gen.generate()
        self.assertEquals(_count_parts(body.root), 1,
                          "One child part should be present (seed %d)." % seed)
        self.assertEquals("2Params", body.root.child[0].part.type,
                          "Child part should be of type 2Params (seed %d)." % seed)

        gen.max_inputs = gen.max_outputs = 100
        gen.max_parts = 1
        body = gen.generate()
        self.assertEquals(0, _count_parts(body.root),
                          "No child parts should be present (seed %d)." % seed)
Exemple #2
0
    def test_constraints(self):
        """
        In this test, we build a body generator with a maximum
        number of inputs / outputs that is already satisfied
        by the root component, and ensure no further generation
        is done.

        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
            body_spec,
            root_parts=["Core"],
            attach_parts=["2Params"],
            max_inputs=2,
            max_outputs=10,
            max_parts=100,
            fix_num_parts=True
        )

        body = gen.generate()
        self.assertEquals("Core", body.root.type, "Root type should be 'Core' (seed %d)." % seed)
        self.assertEquals(0, len(body.root.child), "Too many inputs were generated (seed %d)." % seed)

        gen.max_inputs = 100
        gen.max_outputs = 2

        body = gen.generate()
        self.assertEquals(0, len(body.root.child), "Too many outputs were generated (seed %d)." % seed)

        # This leaves enough room for a 2Params child, but not enough for a SomePart child
        gen.max_outputs = 4
        body = gen.generate()
        self.assertEquals(_count_parts(body.root), 1,
                          "One child part should be present (seed %d)." % seed)
        self.assertEquals("2Params", body.root.child[0].part.type,
                          "Child part should be of type 2Params (seed %d)." % seed)

        gen.max_inputs = gen.max_outputs = 100
        gen.max_parts = 1
        body = gen.generate()
        self.assertEquals(0, _count_parts(body.root),
                          "No child parts should be present (seed %d)." % seed)
Exemple #3
0
    def test_valid(self):
        """
        Generates a body and ensures it is completely initialized.
        :return:
        """
        # Seed so we can reproduce if this goes wrong
        seed = random.randint(0, 10000)
        random.seed(seed)

        gen = BodyGenerator(
            body_spec,
            root_parts=["Core"],
            attach_parts=["2Params"],
            max_inputs=100,
            max_outputs=100,
            max_parts=10,
            fix_num_parts=True
        )

        body = gen.generate()
        self.assertTrue(body.IsInitialized(), "Incomplete body (seed %d)." % seed)