added tests for rodCutting and made some changes

This commit is contained in:
raghhavtaneja
2021-10-12 11:06:21 +05:30
parent 0312ee731e
commit 0ae960c4ee
2 changed files with 24 additions and 8 deletions

View File

@ -3,7 +3,7 @@
* Find the maximum profit possible by cutting the rod and selling the pieces.
*/
function rodCut(prices, n){
export function rodCut(prices, n){
let memo = new Array(n + 1);
memo[0] = 0;
@ -18,10 +18,4 @@
return memo[n];
}
function main(){
let arr = [1, 5, 4, 2, 1, 11, 19, 12];
let n = arr.length;
console.log('Maximum Possible Profit is : '+ rodCut(arr,n));
}
main();

View File

@ -0,0 +1,22 @@
import { rodCut } from '../RodCutting'
test('Test Case 1', () => {
expect(rodCut([1,5,8,9,10,17,17,20],8)).toBe(22);
})
test('Test Case 2', () => {
expect(rodCut([1,5,4,2,1,11,19,12],8)).toBe(20);
})
test('Test Case 3', () => {
expect(rodCut([1,2,1],3)).toBe(3);
})
test('Test Case 4', () => {
expect(rodCut([5,4,3,2,1],5)).toBe(25);
})
test('Test Case 5', () => {
expect(rodCut([3,5,8,8,10,16,14,19],8)).toBe(24);
})