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

        la.resize(20)
        self.assertEqual(la.length, 20)
        self.assertEqual(len(la.get_npy_array()), 20)
        self.assertEqual(la.alloc >= la.length, True)
    def test_remove_particles(self):
        x = [1, 2, 3, 4.]
        y = [0., 1., 2., 3.]
        z = [0., 0., 0., 0.]
        m = [1., 1., 1., 1.]
        h = [.1, .1, .1, .1]
        A = numpy.arange(12)

        p = particle_array.ParticleArray(x={'data': x},
                                         y={'data': y},
                                         z={'data': z},
                                         m={'data': m},
                                         h={'data': h},
                                         A={
                                             'data': A,
                                             'stride': 3
                                         },
                                         backend=self.backend)

        remove_arr = LongArray(0)
        remove_arr.append(0)
        remove_arr.append(1)

        p.remove_particles(remove_arr)
        self.pull(p)

        self.assertEqual(p.get_number_of_particles(), 2)
        self.assertEqual(check_array(p.x, [3., 4.]), True)
        self.assertEqual(check_array(p.y, [2., 3.]), True)
        self.assertEqual(check_array(p.z, [0., 0.]), True)
        self.assertEqual(check_array(p.m, [1., 1.]), True)
        self.assertEqual(check_array(p.h, [.1, .1]), True)
        self.assertEqual(check_array(p.A, numpy.arange(6, 12)), True)

        # now try invalid operations to make sure errors are raised.
        remove_arr.resize(10)
        self.assertRaises(ValueError, p.remove_particles, remove_arr)

        # now try to remove a particle with index more that particle
        # length.
        remove_arr = [2]

        p.remove_particles(remove_arr)
        self.pull(p)
        # make sure no change occurred.
        self.assertEqual(p.get_number_of_particles(), 2)
        self.assertEqual(check_array(p.x, [3., 4.]), True)
        self.assertEqual(check_array(p.y, [2., 3.]), True)
        self.assertEqual(check_array(p.z, [0., 0.]), True)
        self.assertEqual(check_array(p.m, [1., 1.]), True)
        self.assertEqual(check_array(p.h, [.1, .1]), True)
        self.assertEqual(check_array(p.A, numpy.arange(6, 12)), True)