Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import TemplateSort from './TemplateSort'; import Action from '../../components/sorts/BarChartActions'; import Color from '../../utils/Color'; import getRandomInt from '../../utils/getRandomInt'; import isSorted from '../../utils/isSorted'; const expectedStep = { do: [ { action: Action.SET_COLORS, elements: [ { index: 1, color: Color.BASE_COLOR_BAR_CHART, }, ], text: 'Setting blue color on element 1.', }, ], undo: [ { action: Action.SET_COLORS, elements: [ { index: 1, color: Color.WHITE, }, ], text: 'Undo setting blue color on element 1.', }, ], }; describe('TemplateSort.js', () => { // uncomment this test // it('should sort the given random input', () => { // const numTests = 1000; // const inputSize = 50; // for (let i = 0; i < numTests; i += 1) { // const randomNumbers = new Array(inputSize) // .fill(null) // .map((_) => getRandomInt(0, 100)); // const sortedOutput = TemplateSort(randomNumbers, true); // expect(isSorted(sortedOutput)).toBe(true); // } // }); test.each([ // No input [[], []], // Sorted input [[1, 2, 3, 4, 5], [expectedStep/* put expected output here */]], // Reverse input [[5, 4, 3, 2, 1], [expectedStep/* put expected output here */]], // Only one number [[4], [expectedStep/* put expected output here */]], // Repeating numbers [[1, 2, 1], [expectedStep/* put expected output here */]], // Random input [[3, 8, 2, 7, 1], [expectedStep/* put expected output here */]], ])('should return the expected steps, input %#: %p', (input, expectedOutput) => { const actualOutput = TemplateSort(input); // use the code below to print the steps the algorithm returns: // const util = require('util'); // console.dir(util.inspect(actualOutput, { depth: null })); expect(actualOutput.length).toEqual(expectedOutput.length); expectedOutput.forEach((element, index) => { expect(actualOutput[index]).toEqual(element); }); }); }); |