mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
Fix wiggle sort (#991)
Co-authored-by: Antonia Strack <antonia.strack@thm.mni.de>
This commit is contained in:
24
Sorts/test/SimplifiedWiggleSort.test.js
Normal file
24
Sorts/test/SimplifiedWiggleSort.test.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { simplifiedWiggleSort } from '../SimplifiedWiggleSort.js'
|
||||
|
||||
describe('simplified wiggle sort', () => {
|
||||
test('simplified wiggle sort for chars', () => {
|
||||
const src = ['a', 'b', 'c']
|
||||
expect(simplifiedWiggleSort(src)).toEqual(['a', 'c', 'b'])
|
||||
})
|
||||
|
||||
test('wiggle sort with duplicates, even array', () => {
|
||||
const src = [2, 2, 1, 3]
|
||||
expect(simplifiedWiggleSort(src)).toEqual([1, 3, 2, 2])
|
||||
})
|
||||
|
||||
test('wiggle sort with duplicates, odd array', () => {
|
||||
const src = [1, 1, 1, 2, 4]
|
||||
expect(simplifiedWiggleSort(src)).toEqual([1, 4, 1, 2, 1])
|
||||
})
|
||||
|
||||
test('simplified wiggle sort which leads to equal values next to ' +
|
||||
'each other', () => {
|
||||
const src = [3, 3, 5, 1]
|
||||
expect(simplifiedWiggleSort(src)).toEqual([1, 5, 3, 3])
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user