|
1 | 1 | import { rodCut } from '../RodCutting' |
2 | 2 |
|
3 | | -test('Test Case 1', () => { |
4 | | - expect(rodCut([1, 5, 8, 9, 10, 17, 17, 20], 8)).toBe(22) |
5 | | -}) |
| 3 | +describe('rodCut contract & oracle cross-checks (Precondition established near line 6 of Dynamic-Programming/RodCutting.js)', () => { |
| 4 | + // Required Fixtures: Smallest valid input [1], n=1 and ordinary input [1, 5, 8, 9, 10, 17, 17, 20], n=8 |
| 5 | + test('Smallest valid input (prices = [1], n = 1)', () => { |
| 6 | + const prices = [1] |
| 7 | + expect(rodCut(prices, 1)).toBe(1) |
| 8 | + }) |
6 | 9 |
|
7 | | -test('Test Case 2', () => { |
8 | | - expect(rodCut([1, 5, 4, 2, 1, 11, 19, 12], 8)).toBe(20) |
9 | | -}) |
| 10 | + test('Ordinary input (prices = [1, 5, 8, 9, 10, 17, 17, 20], n = 8)', () => { |
| 11 | + const prices = [1, 5, 8, 9, 10, 17, 17, 20] |
| 12 | + expect(rodCut(prices, 8)).toBe(22) |
| 13 | + }) |
10 | 14 |
|
11 | | -test('Test Case 3', () => { |
12 | | - expect(rodCut([1, 2, 1], 3)).toBe(3) |
13 | | -}) |
| 15 | + test('Preserves input array immutability', () => { |
| 16 | + const prices = [1, 5, 8, 9, 10, 17, 17, 20] |
| 17 | + const pricesCopy = [...prices] |
| 18 | + rodCut(prices, 8) |
| 19 | + expect(prices).toEqual(pricesCopy) |
| 20 | + }) |
14 | 21 |
|
15 | | -test('Test Case 4', () => { |
16 | | - expect(rodCut([5, 4, 3, 2, 1], 5)).toBe(25) |
17 | | -}) |
| 22 | + // 20-Domain Explicit Reference Cross-Check Table |
| 23 | + const domainTable = [ |
| 24 | + { prices: [1], n: 1, expected: 1 }, |
| 25 | + { prices: [2], n: 1, expected: 2 }, |
| 26 | + { prices: [1, 5], n: 2, expected: 5 }, |
| 27 | + { prices: [3, 5], n: 2, expected: 6 }, |
| 28 | + { prices: [1, 5, 8], n: 3, expected: 8 }, |
| 29 | + { prices: [3, 2, 1], n: 3, expected: 9 }, |
| 30 | + { prices: [1, 2, 1], n: 3, expected: 3 }, |
| 31 | + { prices: [1, 5, 8, 9], n: 4, expected: 10 }, |
| 32 | + { prices: [2, 5, 7, 8], n: 4, expected: 10 }, |
| 33 | + { prices: [5, 4, 3, 2, 1], n: 5, expected: 25 }, |
| 34 | + { prices: [1, 5, 8, 9, 10], n: 5, expected: 13 }, |
| 35 | + { prices: [1, 5, 8, 9, 10, 17], n: 6, expected: 17 }, |
| 36 | + { prices: [2, 3, 7, 8, 10, 12], n: 6, expected: 14 }, |
| 37 | + { prices: [1, 5, 8, 9, 10, 17, 17], n: 7, expected: 18 }, |
| 38 | + { prices: [3, 5, 8, 9, 10, 17, 18], n: 7, expected: 21 }, |
| 39 | + { prices: [1, 5, 4, 2, 1, 11, 19, 12], n: 8, expected: 20 }, |
| 40 | + { prices: [1, 5, 8, 9, 10, 17, 17, 20], n: 8, expected: 22 }, |
| 41 | + { prices: [3, 5, 8, 8, 10, 16, 14, 19], n: 8, expected: 24 }, |
| 42 | + { prices: [1, 5, 8, 9, 10, 17, 17, 20, 24], n: 9, expected: 25 }, |
| 43 | + { prices: [2, 5, 8, 9, 10, 17, 17, 20, 24, 30], n: 10, expected: 30 } |
| 44 | + ] |
18 | 45 |
|
19 | | -test('Test Case 5', () => { |
20 | | - expect(rodCut([3, 5, 8, 8, 10, 16, 14, 19], 8)).toBe(24) |
| 46 | + test.each(domainTable)( |
| 47 | + 'rodCut($prices, $n) matches expected $expected', |
| 48 | + ({ prices, n, expected }) => { |
| 49 | + expect(rodCut(prices, n)).toBe(expected) |
| 50 | + } |
| 51 | + ) |
21 | 52 | }) |
0 commit comments