%PDF- %PDF-
Direktori : /proc/self/root/home/infra/BACKUP-FUSIONINVENTORY/lib/lazy.js-0.5.1/spec/ |
Current File : //proc/self/root/home/infra/BACKUP-FUSIONINVENTORY/lib/lazy.js-0.5.1/spec/shuffle_spec.min.js |
describe("shuffle",function(){ensureLaziness(function(){Lazy(people).shuffle()});it("shuffles the collection",function(){var shuffledCollections=Lazy.range(10).map(function(){return Lazy(people).shuffle().toArray()}).memoize();var firstResult=shuffledCollections.first();shuffledCollections.each(function(collection){var resorted=Lazy(collection).sortBy(Person.getAge).reverse().toArray();expect(resorted).toEqual(people)});var differences=Lazy(people).map(function(){return 0}).toArray();shuffledCollections.drop(1).each(function(collection){for(var i=0;i<collection.length;++i){if(collection[i]!==firstResult[i]){differences[i]++}}});for(var i=0;i<people.length;++i){expect(differences[i]).toBeGreaterThan(0,"All elements at "+i+" are the same!")}});it("is unbiased",function(){var firsts=Lazy.range(100).map(function(){return Lazy(people).shuffle().first()}).memoize();expect(firsts.uniq().sortBy(Person.getName)).toComprise([adam,daniel,david,happy,lauren,mary])});it("passes an index along with each element",function(){expect(Lazy(people).shuffle()).toPassToEach(1,[0,1,2,3,4,5])})});