Skip to content

Commit 6bb075d

Browse files
committed
Group tests in a describe
1 parent 932599d commit 6bb075d

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

Sorts/test/CycleSort.test.js

+50-48
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
11
import { cycleSort } from '../CycleSort'
22

3-
it('should correctly sort an input list that is sorted backwards', () => {
4-
const array = [5, 4, 3, 2, 1]
5-
expect(cycleSort(array)).toEqual([1, 2, 3, 4, 5])
6-
})
7-
8-
it('should correctly sort an input list that is unsorted', () => {
9-
const array = [15, 24, 3, 2224, 1]
10-
expect(cycleSort(array)).toEqual([1, 3, 15, 24, 2224])
11-
})
12-
13-
describe('Variations of input array lengths', () => {
14-
it('should return an empty list with the input list is an empty list', () => {
15-
expect(cycleSort([])).toEqual([])
3+
describe('cycleSort function', () => {
4+
it('should correctly sort an input list that is sorted backwards', () => {
5+
const array = [5, 4, 3, 2, 1]
6+
expect(cycleSort(array)).toEqual([1, 2, 3, 4, 5])
167
})
178

18-
it('should correctly sort an input list of length 1', () => {
19-
expect(cycleSort([100])).toEqual([100])
9+
it('should correctly sort an input list that is unsorted', () => {
10+
const array = [15, 24, 3, 2224, 1]
11+
expect(cycleSort(array)).toEqual([1, 3, 15, 24, 2224])
2012
})
2113

22-
it('should correctly sort an input list of an odd length', () => {
23-
expect(cycleSort([101, -10, 321])).toEqual([-10, 101, 321])
24-
})
14+
describe('Variations of input array lengths', () => {
15+
it('should return an empty list with the input list is an empty list', () => {
16+
expect(cycleSort([])).toEqual([])
17+
})
2518

26-
it('should correctly sort an input list of an even length', () => {
27-
expect(cycleSort([40, 42, 56, 45, 12, 3])).toEqual([3, 12, 40, 42, 45, 56])
28-
})
29-
})
19+
it('should correctly sort an input list of length 1', () => {
20+
expect(cycleSort([100])).toEqual([100])
21+
})
3022

31-
describe('Variations of input array elements', () => {
32-
it('should correctly sort an input list that contains only positive numbers', () => {
33-
expect(cycleSort([50, 33, 11, 2])).toEqual([2, 11, 33, 50])
34-
})
23+
it('should correctly sort an input list of an odd length', () => {
24+
expect(cycleSort([101, -10, 321])).toEqual([-10, 101, 321])
25+
})
3526

36-
it('should correctly sort an input list that contains only negative numbers', () => {
37-
expect(cycleSort([-1, -21, -2, -35])).toEqual([-35, -21, -2, -1])
27+
it('should correctly sort an input list of an even length', () => {
28+
expect(cycleSort([40, 42, 56, 45, 12, 3])).toEqual([3, 12, 40, 42, 45, 56])
29+
})
3830
})
3931

40-
it('should correctly sort an input list that contains only a mix of positive and negative numbers', () => {
41-
expect(cycleSort([-40, 42, 56, -45, 12, -3])).toEqual([-45, -40, -3, 12, 42, 56])
42-
})
32+
describe('Variations of input array elements', () => {
33+
it('should correctly sort an input list that contains only positive numbers', () => {
34+
expect(cycleSort([50, 33, 11, 2])).toEqual([2, 11, 33, 50])
35+
})
4336

44-
it('should correctly sort an input list that contains only whole numbers', () => {
45-
expect(cycleSort([11, 3, 12, 4, -15])).toEqual([-15, 3, 4, 11, 12])
46-
})
37+
it('should correctly sort an input list that contains only negative numbers', () => {
38+
expect(cycleSort([-1, -21, -2, -35])).toEqual([-35, -21, -2, -1])
39+
})
4740

48-
it('should correctly sort an input list that contains only decimal numbers', () => {
49-
expect(cycleSort([1.0, 1.42, 2.56, 33.45, 13.12, 2.3])).toEqual([1.0, 1.42, 2.3, 2.56, 13.12, 33.45])
50-
})
41+
it('should correctly sort an input list that contains only a mix of positive and negative numbers', () => {
42+
expect(cycleSort([-40, 42, 56, -45, 12, -3])).toEqual([-45, -40, -3, 12, 42, 56])
43+
})
5144

52-
it('should correctly sort an input list that contains only a mix of whole and decimal', () => {
53-
expect(cycleSort([32.40, 12.42, 56, 45, 12, 3])).toEqual([3, 12, 12.42, 32.40, 45, 56])
54-
})
45+
it('should correctly sort an input list that contains only whole numbers', () => {
46+
expect(cycleSort([11, 3, 12, 4, -15])).toEqual([-15, 3, 4, 11, 12])
47+
})
5548

56-
it('should correctly sort an input list that contains only fractional numbers', () => {
57-
expect(cycleSort([0.98, 0.4259, 0.56, -0.456, -0.12, 0.322])).toEqual([-0.456, -0.12, 0.322, 0.4259, 0.56, 0.98])
58-
})
49+
it('should correctly sort an input list that contains only decimal numbers', () => {
50+
expect(cycleSort([1.0, 1.42, 2.56, 33.45, 13.12, 2.3])).toEqual([1.0, 1.42, 2.3, 2.56, 13.12, 33.45])
51+
})
5952

60-
it('should correctly sort an input list that contains only a mix of whole, decimal, and fractional', () => {
61-
expect(cycleSort([-40, -0.222, 5.6, -4.5, 12, 0.333])).toEqual([-40, -4.5, -0.222, 0.333, 5.6, 12])
62-
})
53+
it('should correctly sort an input list that contains only a mix of whole and decimal', () => {
54+
expect(cycleSort([32.40, 12.42, 56, 45, 12, 3])).toEqual([3, 12, 12.42, 32.40, 45, 56])
55+
})
56+
57+
it('should correctly sort an input list that contains only fractional numbers', () => {
58+
expect(cycleSort([0.98, 0.4259, 0.56, -0.456, -0.12, 0.322])).toEqual([-0.456, -0.12, 0.322, 0.4259, 0.56, 0.98])
59+
})
60+
61+
it('should correctly sort an input list that contains only a mix of whole, decimal, and fractional', () => {
62+
expect(cycleSort([-40, -0.222, 5.6, -4.5, 12, 0.333])).toEqual([-40, -4.5, -0.222, 0.333, 5.6, 12])
63+
})
6364

64-
it('should correctly sort an input list that contains duplicates', () => {
65-
expect(cycleSort([4, 3, 4, 2, 1, 2])).toEqual([1, 2, 2, 3, 4, 4])
65+
it('should correctly sort an input list that contains duplicates', () => {
66+
expect(cycleSort([4, 3, 4, 2, 1, 2])).toEqual([1, 2, 2, 3, 4, 4])
67+
})
6668
})
6769
})

0 commit comments

Comments
 (0)