Skip to content

Commit 29c60b9

Browse files
author
Isaac Ramirez
committed
- add test for an array of equal values
1 parent d789c8b commit 29c60b9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/algorithms/selection-sort/selection-sort.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Unit Tests: Selection Sort Algorithm', () => {
1313
this.orderedArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1414
this.reversedArray = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
1515
this.unorderedArray = [0, 9, 5, 2, 1, 8, 7, 6, 4, 3]
16+
this.allEqualArray = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
1617
})
1718

1819
describe('static less method', () => {
@@ -58,6 +59,7 @@ describe('Unit Tests: Selection Sort Algorithm', () => {
5859
describe('static isSorted method', () => {
5960
it('should return true if an array is sorted', () => {
6061
expect(Selection.isSorted(this.orderedArray)).toBe(true)
62+
expect(Selection.isSorted(this.allEqualArray)).toBe(true)
6163
})
6264

6365
it('should return false if the array is not sorted', () => {
@@ -89,7 +91,7 @@ describe('Unit Tests: Selection Sort Algorithm', () => {
8991
})
9092
})
9193

92-
describe('static sort method', () => {
94+
describe('static show method', () => {
9395
it('should be a function', () => {
9496
// I could test the call to StdOut, but I don't want to.
9597
expect(Selection.show).toBeInstanceOf(Function)
@@ -121,6 +123,14 @@ describe('Unit Tests: Selection Sort Algorithm', () => {
121123
expect(this.reversedArray).toEqual(expectedArray)
122124
})
123125

126+
it('should sort an array with all the values to be equal', () => {
127+
const expectedArray = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
128+
129+
Selection.sort(this.allEqualArray)
130+
131+
expect(this.allEqualArray).toEqual(expectedArray)
132+
})
133+
124134
it('should sort a small random array', () => {
125135
// considering that Selection Sort is slow...
126136
const n = 1000 // a thousand

0 commit comments

Comments
 (0)