|
| 1 | +import combineWithoutRepetitions from '../combineWithoutRepetitions'; |
| 2 | +import factorial from '../../factorial/factorial'; |
| 3 | + |
| 4 | +describe('combineWithoutRepetitions', () => { |
| 5 | + it('should combine string without repetitions', () => { |
| 6 | + expect(combineWithoutRepetitions(['A', 'B'], 3)).toEqual([]); |
| 7 | + |
| 8 | + expect(combineWithoutRepetitions(['A', 'B'], 1)).toEqual([ |
| 9 | + ['A'], |
| 10 | + ['B'], |
| 11 | + ]); |
| 12 | + |
| 13 | + expect(combineWithoutRepetitions(['A'], 1)).toEqual([ |
| 14 | + ['A'], |
| 15 | + ]); |
| 16 | + |
| 17 | + expect(combineWithoutRepetitions(['A', 'B'], 2)).toEqual([ |
| 18 | + ['A', 'B'], |
| 19 | + ]); |
| 20 | + |
| 21 | + expect(combineWithoutRepetitions(['A', 'B', 'C'], 2)).toEqual([ |
| 22 | + ['A', 'B'], |
| 23 | + ['A', 'C'], |
| 24 | + ['B', 'C'], |
| 25 | + ]); |
| 26 | + |
| 27 | + expect(combineWithoutRepetitions(['A', 'B', 'C'], 3)).toEqual([ |
| 28 | + ['A', 'B', 'C'], |
| 29 | + ]); |
| 30 | + |
| 31 | + expect(combineWithoutRepetitions(['A', 'B', 'C', 'D'], 3)).toEqual([ |
| 32 | + ['A', 'B', 'C'], |
| 33 | + ['A', 'B', 'D'], |
| 34 | + ['A', 'C', 'D'], |
| 35 | + ['B', 'C', 'D'], |
| 36 | + ]); |
| 37 | + |
| 38 | + expect(combineWithoutRepetitions(['A', 'B', 'C', 'D', 'E'], 3)).toEqual([ |
| 39 | + ['A', 'B', 'C'], |
| 40 | + ['A', 'B', 'D'], |
| 41 | + ['A', 'B', 'E'], |
| 42 | + ['A', 'C', 'D'], |
| 43 | + ['A', 'C', 'E'], |
| 44 | + ['A', 'D', 'E'], |
| 45 | + ['B', 'C', 'D'], |
| 46 | + ['B', 'C', 'E'], |
| 47 | + ['B', 'D', 'E'], |
| 48 | + ['C', 'D', 'E'], |
| 49 | + ]); |
| 50 | + |
| 51 | + const combinationOptions = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; |
| 52 | + const combinationSlotsNumber = 4; |
| 53 | + const combinations = combineWithoutRepetitions(combinationOptions, combinationSlotsNumber); |
| 54 | + const n = combinationOptions.length; |
| 55 | + const r = combinationSlotsNumber; |
| 56 | + const expectedNumberOfCombinations = factorial(n) / (factorial(r) * factorial(n - r)); |
| 57 | + |
| 58 | + expect(combinations.length).toBe(expectedNumberOfCombinations); |
| 59 | + }); |
| 60 | +}); |
0 commit comments