Skip to content

Commit 35035f7

Browse files
authored
merge: Add test case and fix TimSort algo (TheAlgorithms#977)
1 parent 2169e17 commit 35035f7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Sorts/TimSort.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Timsort = (array) => {
2525
Merge(array, left, mid, right)
2626
}
2727
}
28+
return array
2829
}
2930

3031
/**

Sorts/test/TimSort.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Timsort } from '../TimSort'
2+
3+
test('The Timsort of the array [5, 4, 3, 2, 1] is [1, 2, 3, 4, 5]', () => {
4+
const arr = [5, 4, 3, 2, 1]
5+
const res = Timsort(arr)
6+
expect(res).toEqual([1, 2, 3, 4, 5])
7+
})
8+
9+
test('The Timsort of the array [] is []', () => {
10+
const arr = []
11+
const res = Timsort(arr)
12+
expect(res).toEqual([])
13+
})
14+
15+
test('The Timsort of the array [-5, -4, -3, -2, -1] is [-5, -4, -3, -2, -1]', () => {
16+
const arr = [-5, -4, -3, -2, -1]
17+
const res = Timsort(arr)
18+
expect(res).toEqual([-5, -4, -3, -2, -1])
19+
})
20+
21+
test('The Timsort of the array [9, 0, -5, -11, 3] is [-11, -5, 0, 3, 9]', () => {
22+
const arr = [9, 0, -5, -11, 3]
23+
const res = Timsort(arr)
24+
expect(res).toEqual([-11, -5, 0, 3, 9])
25+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy