Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cc3231

Browse files
Add tests to heap "update" method
1 parent0ecc151 commit8cc3231

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎test/data-structures/heap.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,38 @@ describe('Heap', function () {
5858
res=heap.extract();
5959
expect(res).toBe(66);
6060
});
61+
it('should update top node properly',function(){
62+
varheap=newHeap(function(a,b){
63+
returna.val-b.val;
64+
});
65+
varobjectToUpdate={val:66};
66+
heap.add(objectToUpdate);
67+
heap.add({val:11});
68+
heap.add({val:55});
69+
objectToUpdate.val=0;
70+
heap.update(objectToUpdate);
71+
varres=heap.extract();
72+
expect(res.val).toBe(55);
73+
res=heap.extract();
74+
expect(res.val).toBe(11);
75+
res=heap.extract();
76+
expect(res.val).toBe(0);
77+
});
78+
it('should update bottom node properly',function(){
79+
varheap=newHeap(function(a,b){
80+
returna.val-b.val;
81+
});
82+
varobjectToUpdate={val:0};
83+
heap.add(objectToUpdate);
84+
heap.add({val:11});
85+
heap.add({val:55});
86+
objectToUpdate.val=66;
87+
heap.update(objectToUpdate);
88+
varres=heap.extract();
89+
expect(res.val).toBe(66);
90+
res=heap.extract();
91+
expect(res.val).toBe(55);
92+
res=heap.extract();
93+
expect(res.val).toBe(11);
94+
});
6195
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp