Exemple #1
0
    def test_resize(self):
        """Tests the resize function."""
        da = DoubleArray(0)

        da.resize(20)
        self.assertEqual(da.length, 20)
        self.assertEqual(len(da.get_npy_array()), 20)
        self.assertEqual(da.alloc >= da.length, True)
Exemple #2
0
    def test_reset(self):
        """Tests the reset function."""
        da = DoubleArray(5)
        da.shrink(2)

        self.assertEqual(da.length, 2)
        self.assertEqual(da.alloc, 5)
        self.assertEqual(len(da.get_npy_array()), 2)
Exemple #3
0
    def test_get_npy_array(self):
        """Tests the get_npy_array array."""
        da = DoubleArray(3)
        da[0] = 1.0
        da[1] = 2.0
        da[2] = 3.0

        nparray = da.get_npy_array()
        self.assertEqual(len(nparray), 3)

        for i in range(3):
            self.assertEqual(nparray[i], da[i])
Exemple #4
0
    def test_copy_values(self):
        """Tests the copy values function."""
        da1 = DoubleArray(5)
        da2 = DoubleArray(5)
        indices = LongArray(5)

        for i in range(5):
            da1[i] = i
            da2[i] = 0
            indices[i] = i

        da1.copy_values(indices, da2)
        self.assertEqual(np.allclose(da1.get_npy_array(), da2.get_npy_array()),
                         True)
Exemple #5
0
    def test_get_set_indexing(self):
        """Test get/set and [] operator."""
        da = DoubleArray(10)
        da.set(0, 10.0)
        da.set(9, 1.0)

        self.assertEqual(da.get(0), 10.0)
        self.assertEqual(da.get(9), 1.0)

        da[9] = 2.0
        self.assertEqual(da[9], 2.0)
Exemple #6
0
    def test_squeeze(self):
        """Tests the squeeze function."""
        da = DoubleArray(5)
        da.append(4.0)

        self.assertEqual(da.alloc > da.length, True)

        da.squeeze()

        self.assertEqual(da.length, 6)
        self.assertEqual(da.alloc == da.length, True)
        self.assertEqual(len(da.get_npy_array()), 6)
Exemple #7
0
    def test_paste_values(self):
        """Tests the paste values function."""
        da1 = DoubleArray(3)
        da1_array = da1.get_npy_array()
        da1_array[:] = 2.0

        da2 = DoubleArray(6)
        da2_array = da2.get_npy_array()
        da2_array[:] = 0.0

        indices = LongArray(3)
        ind_array = indices.get_npy_array()
        ind_array[:] = [0, 2, 4]

        da1.paste_values(indices, da2)
        for i in indices:
            self.assertTrue(da2[i] == 2.0)
Exemple #8
0
    def test_constructor(self):
        """Test the constructor."""
        da = DoubleArray(10)

        self.assertEqual(da.length, 10)
        self.assertEqual(da.alloc, 10)
        self.assertEqual(len(da.get_npy_array()), 10)
        self.assertEqual(da.get_npy_array().itemsize, 8)

        da = DoubleArray()

        self.assertEqual(da.length, 0)
        self.assertEqual(da.alloc, 16)
        self.assertEqual(len(da.get_npy_array()), 0)
Exemple #9
0
    def test_extend(self):
        """Tests teh extend function."""
        da1 = DoubleArray(5)

        for i in range(5):
            da1[i] = i

        da2 = DoubleArray(5)

        for i in range(5):
            da2[i] = 5 + i

        da1.extend(da2.get_npy_array())

        self.assertEqual(da1.length, 10)
        self.assertEqual(
            np.allclose(da1.get_npy_array(), np.arange(10, dtype=np.float64)),
            True)
Exemple #10
0
    def test_append(self):
        """Test the append function."""
        da = DoubleArray(0)
        da.append(1.0)
        da.append(2.0)
        da.append(3.0)

        self.assertEqual(da.length, 3)
        self.assertEqual(da[0], 1.0)
        self.assertEqual(da[1], 2.0)
        self.assertEqual(da[2], 3.0)
Exemple #11
0
    def test_aling_array(self):
        """Test the align_array function."""
        da1 = DoubleArray(10)
        da1_array = da1.get_npy_array()
        da1_array[:] = np.arange(10, dtype=np.float64)

        new_indices = np.array([1, 5, 3, 2, 4, 7, 8, 6, 9, 0], dtype=np.int)
        da1.align_array(new_indices)

        self.assertEqual(
            np.allclose(
                np.array([1.0, 5.0, 3.0, 2.0, 4.0, 7.0, 8.0, 6.0, 9.0, 0.0],
                         dtype=np.float64), da1.get_npy_array()), True)
Exemple #12
0
 def test_dtype(self):
     """Test data type."""
     da = DoubleArray(10)
     self.assertEqual(da.get_npy_array().dtype, np.float64)
Exemple #13
0
    def test_remove(self):
        """Tests the remove function"""
        da1 = DoubleArray(10)
        da1_array = da1.get_npy_array()
        da1_array[:] = np.arange(10, dtype=np.float64)

        rem = [0, 4, 3]
        da1.remove(np.array(rem, dtype=np.int))
        self.assertEqual(da1.length, 7)
        self.assertEqual(
            np.allclose(
                np.array([7.0, 1.0, 2.0, 8.0, 9.0, 5.0, 6.0],
                         dtype=np.float64), da1.get_npy_array()), True)

        da1.remove(np.array(rem, dtype=np.int))
        self.assertEqual(da1.length, 4)
        self.assertEqual(
            np.allclose(np.array([6.0, 1.0, 2.0, 5.0], dtype=np.float64),
                        da1.get_npy_array()), True)

        rem = [0, 1, 3]
        da1.remove(np.array(rem, dtype=np.int))
        self.assertEqual(da1.length, 1)
        self.assertEqual(
            np.allclose(np.array([2.0], dtype=np.float64),
                        da1.get_npy_array()), True)

        da1.remove(np.array([0], dtype=np.int))
        self.assertEqual(da1.length, 0)
        self.assertEqual(len(da1.get_npy_array()), 0)