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

Commit07c2108

Browse files
mlegtrekhleb
andauthored
Add missing LinkedList tests (trekhleb#151)
Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
1 parent38b2b97 commit07c2108

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎src/data-structures/linked-list/__test__/LinkedList.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@ describe('LinkedList', () => {
218218
expect(linkedList.find({value:2,customValue:'test5'})).toBeNull();
219219
});
220220

221+
it('should find preferring callback over compare function',()=>{
222+
constgreaterThan=(value,compareTo)=>(value>compareTo ?0 :1);
223+
224+
constlinkedList=newLinkedList(greaterThan);
225+
linkedList.fromArray([1,2,3,4,5]);
226+
227+
letnode=linkedList.find({value:3});
228+
expect(node.value).toBe(4);
229+
230+
node=linkedList.find({callback:value=>value<3});
231+
expect(node.value).toBe(1);
232+
});
233+
234+
it('should convert to array',()=>{
235+
constlinkedList=newLinkedList();
236+
237+
linkedList.append(1);
238+
linkedList.append(2);
239+
linkedList.append(3);
240+
241+
expect(linkedList.toArray().join(',')).toBe('1,2,3');
242+
});
243+
221244
it('should reverse linked list',()=>{
222245
constlinkedList=newLinkedList();
223246

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp