Пример #1
0
 def test_create_full_array_3d(self):
     """Test the create_full_array function for three-dimensional arrays."""
     a1 = create_full_array([1, 1, 1], 1)
     self.assertTrue(a1 == [[[1]]])
     a2 = create_full_array([2, 1, 1], 1.0)
     self.assertTrue(a2 == [[[1.0]], [[1.0]]])
     a3 = create_full_array([1, 2, 1], 1.0)
     self.assertTrue(a3 == [[[1.0], [1.0]]])
     a4 = create_full_array([2, 2, 2], 1)
     self.assertTrue(a4 == [[[1, 1], [1, 1]], [[1, 1], [1, 1]]])
Пример #2
0
 def test_create_full_array_1d(self):
     """Test the create_full_array function for one-dimensional arrays."""
     a1 = create_full_array([1], 1)
     self.assertTrue(a1 == [1])
     a2 = create_full_array([1], 1.0)
     self.assertTrue(a2 == [1.0])
     a3 = create_full_array([2], True)
     self.assertTrue(a3 == [True, True])
     a4 = create_full_array([10], "Al")
     self.assertTrue(a4 == ["Al", "Al", "Al", "Al", "Al",
                            "Al", "Al", "Al", "Al", "Al"])
Пример #3
0
    def test_create_full_array(self):
        """Test the create_full_array function."""
        a1 = create_full_array([2, 3], 1)
        self.assertTrue(a1 == FULL_ARRAY_1)

        a2 = create_full_array([3, 3, 2], True)
        self.assertTrue(a2 == FULL_ARRAY_2)

        # if the input is not a list or tuple
        self.assertRaises(self.KIMPropertyError, create_full_array,
                          {2, 3, 2})
Пример #4
0
    def test_extend_full_array(self):
        """Test the extend_full_array function."""
        a0 = extend_full_array(FULL_ARRAY_0, shape(FULL_ARRAY_0), 0)
        self.assertTrue(a0 == FULL_ARRAY_0)

        a1 = extend_full_array(FULL_ARRAY_1, shape(FULL_ARRAY_1), 0)
        self.assertTrue(a1 == FULL_ARRAY_1)

        a1 = extend_full_array(FULL_ARRAY_1, [6, 3], 0)
        self.assertTrue(a1 == FULL_ARRAY_1_EXTENDED)

        a2 = extend_full_array(FULL_ARRAY_1, [3, 4], 0)
        self.assertTrue(a2 == FULL_ARRAY_1_EXTENDED_2)

        a3 = extend_full_array(
            FULL_ARRAY_2, shape(FULL_ARRAY_2), False)
        self.assertTrue(a3 == FULL_ARRAY_2)

        a3 = extend_full_array(
            FULL_ARRAY_2, [3, 4, 2], False)
        self.assertTrue(a3 == FULL_ARRAY_2_EXTENDED)

        a4 = extend_full_array(
            FULL_ARRAY_2, [4, 4, 2], False)
        self.assertTrue(a4 == FULL_ARRAY_2_EXTENDED_2)

        # if the input is not a list or tuple
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          FULL_ARRAY_1, {6, 3}, 0)

        # if the input is not uniform
        a = [[1], [2, 1], [3], [4], [5, 2, 3]]
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, {5, 3}, 0)

        # dimensions do not match
        a = create_full_array([2, 3], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 3, 2], 0)

        # full array dimensions are bigger
        a = create_full_array([2, 3, 4], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 3, 2], 0)

        # input number of dimensions is greater than 6
        a = create_full_array([1, 1, 1, 1, 1, 1, 1, 1], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [1, 1, 1, 1, 1, 1, 1, 2], 0)

        # the input array is not uniform along all dimensions
        a = [[1, 2], [0, 0, 0]]
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [3, 3], 0)

        a = [[], [1]]
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 2], 0)

        a = create_full_array([2, 2, 2, 2], 0)
        b = extend_full_array(a, [2, 2, 2, 4], 100)
        self.assertTrue(b[0][0][0][0] == 0)
        self.assertTrue(b[0][0][0][1] == 0)
        self.assertTrue(b[0][0][0][2] == 100)
        self.assertTrue(b[0][0][0][3] == 100)

        # Fail if the old shape is bigger than the new
        a = create_full_array([2, 2, 2, 2], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 2, 1, 4], 0)

        a = create_full_array([1, 1, 1, 1, 1], 0)
        b = extend_full_array(a, [2, 2, 2, 2, 2], 100)
        self.assertTrue(b[0][0][0][0][0] == 0)
        self.assertTrue(b[0][0][0][0][1] == 100)

        a = create_full_array([2, 1, 2, 1, 2], 0)
        b = extend_full_array(a, [2, 2, 2, 2, 2], 100)
        self.assertTrue(b[0][0][0][0][0] == 0)
        self.assertTrue(b[0][0][0][0][1] == 0)
        self.assertTrue(b[0][0][0][1][1] == 100)
        self.assertTrue(b[1][1][1][1][1] == 100)

        # Fail if the old shape is bigger than the new
        a = create_full_array([2, 1, 2, 1, 2], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 2, 2, 2, 1], 0)

        a = create_full_array([1, 1, 1, 1, 1, 1], 0)
        b = extend_full_array(a, [2, 2, 2, 2, 2, 2], 100)
        self.assertTrue(b[0][0][0][0][0][0] == 0)
        self.assertTrue(b[0][0][0][0][0][1] == 100)
        self.assertTrue(b[0][0][0][0][1][1] == 100)

        # Fail if the old shape is bigger than the new
        a = create_full_array([1, 2, 3, 3, 2, 1], 0)
        self.assertRaises(self.KIMPropertyError, extend_full_array,
                          a, [2, 2, 2, 2, 2, 2], 0)

        b = extend_full_array(a, [2, 2, 3, 3, 2, 2], 100)
        self.assertTrue(b[0][0][0][0][0][0] == 0)
        self.assertTrue(b[1][0][0][0][0][0] == 100)
        self.assertTrue(b[1][0][0][0][0][1] == 100)