misoproject / dataset

JavaScript library that makes managing the data behind client-side visualisations easy
http://misoproject.com
GNU General Public License v2.0
1.18k stars 99 forks source link

remove multiple lines fails #209

Open alexmasselot opened 11 years ago

alexmasselot commented 11 years ago

Hi trying to remove multiple lines fail with version 0.4.1 Her is the fix, line 1243 of miso.ds.0.4.1.m.js

.each(rowsToRemove, function(rowId) { is rewritten .each(rowsToRemove.reverse(), function(rowId) { That's a classic one, nope?

Want a jasmine test?? see below, the two last tests are failing by removing the wrong line...

Thanks a lot for for the Miso works ;)

define(['underscore', 'Miso'], function(, Miso) { describe('Miso.Dataset', function() { //just make a array of element with incremental id fireld and one char at a time var buildDummy = function(chars) { return .map(chars.split(''), function(c, i) { return { idx : i, val : c } }) } // load a dummy dataset and exeut the callback test when fetched var checkWithDummyDS = function(testName, chars, testCallback) { it(testName, function() { var ds = new Miso.Dataset({ data : buildDummy(chars) }); var ok; ds.fetch({ success : function() { ok = true }, error : function(err) { throw err } }) waitsFor(function() { return ok }) runs(function() { testCallback(ds) }) }) } it('builDummy', function() { expect(buildDummy('acc')).toEqual([{ idx : 0, val : 'a' }, { idx : 1, val : 'c' }, { idx : 2, val : 'c' }]);

    })
    checkWithDummyDS('size', 'abcdefg', function(ds) {
        expect(ds.length).toBe(7)
    })

  checkWithDummyDS('remove one "b"', 'aabccdd', function(ds) {
        expect(ds.column('idx').data).toEqual([0, 1, 2, 3, 4, 5, 6])
        expect(ds.column('val').data).toEqual(['a', 'a', 'b', 'c', 'c', 'd', 'd'])
        console.log('remove')
        ds.remove(function(row) {
            return row.val == 'b'
        });
        expect(ds.length).toBe(6)
        expect(ds.column('val').data).toEqual(['a', 'a', 'c', 'c', 'd', 'd'])
        expect(ds.column('idx').data).toEqual([0, 1, 3, 4, 5, 6])
    })
    checkWithDummyDS('remove multiple alternated "b"', 'aabcbcdd', function(ds) {
        expect(ds.column('idx').data).toEqual([0, 1, 2, 3, 4, 5, 6, 7])
        expect(ds.column('val').data).toEqual(['a', 'a', 'b', 'c', 'b', 'c', 'd', 'd'])
        ds.remove(function(row) {
            return row.val == 'b'
        });
        expect(ds.length).toBe(6)
        expect(ds.column('val').data).toEqual(['a', 'a', 'c', 'c', 'd', 'd'])
        expect(ds.column('idx').data).toEqual([0, 1, 3, 5, 6, 7])
    })

    checkWithDummyDS('remove multiple successive "b"', 'aabbccdd', function(ds) {
        expect(ds.column('idx').data).toEqual([0, 1, 2, 3, 4, 5, 6, 7])
        expect(ds.column('val').data).toEqual(['a', 'a', 'b', 'b', 'c', 'c', 'd', 'd'])
        ds.remove(function(row) {
            return row.val == 'b'
        });
        expect(ds.length).toBe(6)
        expect(ds.column('val').data).toEqual(['a', 'a', 'c', 'c', 'd', 'd'])
        expect(ds.column('idx').data).toEqual([0, 1, 4, 5, 6, 7])
    })
})

})

alexmasselot commented 11 years ago

solved in fork https://github.com/alexmasselot/dataset

alexgraul commented 11 years ago

Ah, nice! Mind submitting a pull req?

alexmasselot commented 11 years ago

done. That hardest part was to discover how github works for contributions (OK, I'm ashamed of discovering that only now....)