Skip to content

Commit

Permalink
test(test): add test for complex objects
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledosama999 committed Feb 25, 2021
1 parent 4cc37db commit 790d45b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/functionalty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,24 @@ describe('Functionality', () => {

expect(sortedArray).to.have.ordered.members([8, 7, 5, 1]);
});

it('it works with complex objects given the right extractor', () => {
const array = [{ id: 1 }, { id: 7 }, { id: 3 }, { id: 8 }];

const binaryHeap = new BinaryHeap(
(x) => x.id,
array.values(),
);

const sortedArray = [];

while (true) {
const x = binaryHeap.pop();
if (!x) break;

sortedArray.push(x);
}

expect(sortedArray).to.deep.eq([{ id: 8 }, { id: 7 }, { id: 3 }, { id: 1 }]);
});
});

0 comments on commit 790d45b

Please sign in to comment.