PriorityQueue.test.js 739 B

123456789101112131415161718192021222324252627
  1. require('should');
  2. var PriorityQueue = require('../lib/index.js').PriorityQueue;
  3. describe('PriorityQueue', function() {
  4. describe('insert', function() {
  5. it('should return correct result', function() {
  6. var p = new PriorityQueue();
  7. p.insert(1, 4);
  8. p.insert(2, 1);
  9. p.insert(3, 2);
  10. p.insert(4, 3);
  11. p.getElements().should.eql([1, 4, 3, 2]);
  12. p.getPriorities().should.eql([4, 3, 2, 1]);
  13. });
  14. });
  15. describe('init', function() {
  16. it('should initialize queue correctly', function() {
  17. var p = new PriorityQueue([1, 2, 3, 4], [4, 1, 2, 3]);
  18. p.getElements().should.eql([1, 4, 3, 2]);
  19. p.getPriorities().should.eql([4, 3, 2, 1]);
  20. });
  21. });
  22. });