class TestSparseArray(unittest.TestCase):

    #def __init__(self):
    #    self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )

    def test_get(self):
        self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )
        assert self.sa[4] == 2

    def test_splice(self):
        self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )
        assert self.sa[2:5] == (0,0,2)

    def test_set(self):
        self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )
        self.sa[6] = 9
        assert self.sa[6] == 9

    def test_append(self):
        self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )
        self.sa.append(7)
        assert self.sa[:] == (1,0,0,0,2,0,0,0,5,7) 

    def test_del(self):
        self.sa = SparseArray( (1,0,0,0,2,0,0,0,5) )
        del(self.sa[0])
        assert self.sa[:] == (0,0,0,2,0,9,0,5)        
class TestSparseArray(unittest.TestCase):
    def test_get(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        assert self.sa[4] == 2

    def test_splice(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        assert self.sa[2:5] == [0, 0, 2]

    def test_splice_step(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        assert self.sa[0:6:2] == [1, 0, 2]

    def test_set(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        self.sa[6] = 9
        assert self.sa[6] == 9

    def test_append(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        self.sa.append(7)
        assert self.sa[:] == [1, 0, 0, 0, 2, 0, 0, 0, 5, 7]

    def test_del(self):
        self.sa = SparseArray((1, 0, 0, 0, 2, 0, 0, 0, 5))
        del (self.sa[0])
        assert self.sa[:] == [0, 0, 0, 2, 0, 0, 0, 5]
def test_append():
    sa = SparseArray([0, 1, 0, 3, 4, 0])
    assert len(sa) == 6

    sa.append(8)
    assert len(sa) == 7
    assert sa == SparseArray([0, 1, 0, 3, 4, 0, 8])
    assert sa != SparseArray([0, 1, 0, 3, 4, 0])
def test_append():
    sp = SparseArray(test_list)
    sp.append(20)
    assert sp[len(sp) - 1] == 20

    sp.append(0)
    assert sp[len(sp) - 1] == 0

    assert 0 not in sp.storage.values()
Beispiel #5
0
def test_sparsearray_append():
    """ Tests that you can append to the sparse array """
    sa = SparseArray(my_array)
    sa.append(4)
    assert len(sa) == 11
Beispiel #6
0
def test_append():
    sa = SparseArray([7,29,0,0,0,0,13,0,0,72])
    old_length = sa.length
    sa.append(4)
    assert sa[10] == 4
    assert sa.length == old_length + 1
def test_append():
    sa = SparseArray([1, 2])
    sa.append(3)
    assert len(sa) == 3
    assert sa[2] == 3
def test_append_array():
    a = SA([1,0,0,0,0,3,0,0,0,4,0,5])
    a.append([0,9])
    assert a[12] == 0
    assert a[13] == 9
    assert a.length == 14
def test_append0():
    a = SA([1,0,0,0,0,3,0,0,0,4,0,5])
    a.append(0)
    assert a[12] == 0
    assert a.length == 13
def test_append():
    a = SA([1,0,0,0,0,3,0,0,0,4,0,5])
    a.append(8)
    assert a[12] == 8