コード例 #1
0
    def testZeros(self):
        """Test to make sure parent arrays of 0s returns 0s."""

        truss_1 = np.zeros(10, dtype=int)
        truss_2 = np.zeros(10, dtype=int)

        result = Crossover.uniform_crossover(truss_1, truss_2)

        np.testing.assert_array_equal(result[0], truss_1)
        np.testing.assert_array_equal(result[1], truss_2)
コード例 #2
0
    def testChildInParents(self):
        """Test to make sure that all values of the child arrays 
        exist in the one of the two parent arrays."""

        truss_1 = np.random.randint(10, size=25)
        truss_2 = np.random.randint(10, size=25)
        parents_combined = np.concatenate((truss_1, truss_2))

        result = Crossover.uniform_crossover(truss_1, truss_2)

        child1_status = str(np.all(np.in1d(result[0], parents_combined)))
        child2_status = str(np.all(np.in1d(result[1], parents_combined)))

        np.testing.assert_string_equal(child1_status, str(True))
        np.testing.assert_string_equal(child2_status, str(True))
コード例 #3
0
    def testOutputTypeInt(self):
        """Test to make sure the data type matches what is expected."""

        truss_1 = np.zeros(10, dtype=int)
        truss_2 = np.zeros(10, dtype=int)
        check = np.zeros(10, dtype=int)

        result = Crossover.uniform_crossover(truss_1, truss_2)

        np.testing.assert_array_equal(result[0], check)
        np.testing.assert_array_equal(result[1], check)

        np.testing.assert_string_equal(str((result[0]).dtype),
                                       str(check.dtype))
        np.testing.assert_string_equal(str((result[1]).dtype),
                                       str(check.dtype))