Ejemplo n.º 1
0
    def test_write(self):
        b1d = buffer1d(self.dset_1d, max_fill=10)
        b2d = buffer2d(self.dset_2d, max_fill=10)

        exp1d = np.zeros(10, dtype=int)
        exp1d[:9] = np.arange(9)
        exp2d = np.zeros((10, 100), dtype=int)
        exp2d[:9, :9] = np.tril(np.repeat(np.arange(9), 9).reshape(9, 9).T)
        for i in np.arange(9):
            b1d.write(i)
            b2d.write(np.arange(i+1))

        npt.assert_equal(b1d._buf, exp1d)
        npt.assert_equal(b2d._buf, exp2d)

        for i in np.arange(2):
            b1d.write(i)
            b2d.write(np.arange(i+1))

        exp1d = np.zeros(10, dtype=int)
        exp1d[0] = 1
        exp2d = np.zeros((10, 100), dtype=int)
        exp2d[0, 1] = 1

        npt.assert_equal(b1d._buf, exp1d)
        npt.assert_equal(b2d._buf, exp2d)
Ejemplo n.º 2
0
    def test_init(self):
        b1d = buffer1d(self.dset_1d, max_fill=10)
        b2d = buffer2d(self.dset_2d, max_fill=10)

        npt.assert_equal(b1d.dset, self.dset_1d)
        npt.assert_equal(b2d.dset, self.dset_2d)
        self.assertEqual(b1d._n, 0)
        self.assertEqual(b2d._n, 0)
        self.assertEqual(b1d._idx, 0)
        self.assertEqual(b2d._idx, 0)
        self.assertEqual(b1d._max_fill, 10)
        self.assertEqual(b2d._max_fill, 10)
        npt.assert_equal(b1d._buf, np.zeros(10, dtype=int))
        npt.assert_equal(b2d._buf, np.zeros((10, 100), dtype=int))
Ejemplo n.º 3
0
    def test_is_full(self):
        b1d = buffer1d(self.dset_1d, max_fill=10)
        b2d = buffer2d(self.dset_2d, max_fill=10)

        self.assertFalse(b1d.is_full())
        self.assertFalse(b2d.is_full())

        b1d._n = 10
        b2d._n = 10

        self.assertTrue(b1d.is_full())
        self.assertTrue(b2d.is_full())

        b1d._n = 20
        b2d._n = 20

        self.assertTrue(b1d.is_full())
        self.assertTrue(b2d.is_full())

        b1d._n = 0
        b2d._n = 0
Ejemplo n.º 4
0
    def test_destructor(self):
        b1d = buffer1d(self.dset_1d, max_fill=10)
        b2d = buffer2d(self.dset_2d, max_fill=10)

        for i in np.arange(9):
            b1d.write(i)
            b2d.write(np.arange(i+1))

        npt.assert_equal(b1d.dset, np.zeros(100, dtype=int))
        npt.assert_equal(b2d.dset, np.zeros((100, 100), dtype=int))

        del b1d
        del b2d

        exp1d = np.zeros(100, dtype=int)
        exp1d[:9] = np.arange(9)
        exp2d = np.zeros((100, 100), dtype=int)
        exp2d[:9, :9] = np.tril(np.repeat(np.arange(9), 9).reshape(9, 9).T)

        npt.assert_equal(self.dset_1d, exp1d)
        npt.assert_equal(self.dset_2d, exp2d)