コード例 #1
0
ファイル: test_carray.py プロジェクト: pankajp/pysph
    def test_append(self):
        """
        Test the append function.
        """
        l = LongArray(0)
        l.append(1)
        l.append(2)
        l.append(3)

        self.assertEqual(l.length, 3)
        self.assertEqual(l[0], 1)
        self.assertEqual(l[1], 2)
        self.assertEqual(l[2], 3)
コード例 #2
0
ファイル: test_carray.py プロジェクト: pankajp/pysph
    def test_squeeze(self):
        """
        Tests the squeeze function.
        """
        l = LongArray(5)
        l.append(4)

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

        l.squeeze()

        self.assertEqual(l.length, 6)
        self.assertEqual(l.alloc == l.length, True)
        self.assertEqual(len(l.get_npy_array()), 6)
コード例 #3
0
ファイル: particle_array_tests.py プロジェクト: pankajp/pysph
    def test_remove_particles(self):
        """
        Tests the remove_particles function.
        """
        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]

        p = particle_array.ParticleArray(x={'data':x}, y={'data':y},
                                         z={'data':z}, m={'data':m},
                                         h={'data':h})
        p.add_temporary_array('tmp1')

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

        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(len(p.tmp1), 2)

        # now try invalid operatios 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.resize(1)
        remove_arr[0] = 2

        p.remove_particles(remove_arr)
        # 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(len(p.tmp1), 2)