Skip to content

Commit

Permalink
tests and error
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Mar 13, 2013
1 parent 3c32d68 commit 9773e9c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
5 changes: 1 addition & 4 deletions lib/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ internals.topoSort = function (ancestorsGraph, length) {
}
}

if (sorted.length != length) {
throw new Error('Invalid ext input supplied'); // Occurs if before/after set to item's group (but not limited to this case)
}

Utils.assert(sorted.length === length, 'Invalid ext dependencies detected');
return sorted;
};
60 changes: 45 additions & 15 deletions test/unit/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,56 @@ describe('Ext', function () {
});
});

it('sorts dependencies (2)', function (done) {

var scenario = [
{ id: '0', before: 'a' },
{ id: '1', after: 'f', group: 'a' },
{ id: '2', before: 'a' },
{ id: '3', before: ['b', 'c'], group: 'a' },
{ id: '4', after: 'c', group: 'b' },
{ id: '5', group: 'c' },
{ id: '6', group: 'd' },
{ id: '7', group: 'e' },
{ id: '8', before: 'd', after: 'e' },
{ id: '9', after: 'c', group: 'a' }
];
it('sorts dependencies (explicit)', function (done) {

var set = '0123456789abcdefghijklmnopqrstuvwxyz';
var array = set.split('');

var scenario = [];
for (var i = 0, il = array.length; i < il; ++i) {
var item = {
id: array[i],
group: array[i],
after: i ? array.slice(0, i) : [],
before: array.slice(i + 1)
};
scenario.push(item);
}

var fisherYates = function (array) {

var i = array.length;
while (--i) {
var j = Math.floor(Math.random() * (i + 1));
var tempi = array[i];
var tempj = array[j];
array[i] = tempj;
array[j] = tempi;
}
};

fisherYates(scenario);
testDeps(scenario, function (result) {

expect(result).to.equal('0213547869');
expect(result).to.equal(set);
done();
});
});

it('throws on circular dependency', function (done) {

var scenario = [
{ id: '0', before: 'a', group: 'b'},
{ id: '1', before: 'c', group: 'a' },
{ id: '2', before: 'b', group: 'c' }
];

expect(function () {

testDeps(scenario, function (result) { });
}).to.throw();

done();
});
});
});

0 comments on commit 9773e9c

Please sign in to comment.