Added test cases for TrappingRainWater

This commit is contained in:
Omkarnath Parida
2021-10-03 21:13:08 +05:30
parent db3caea70f
commit 63ceac0925
2 changed files with 12 additions and 3 deletions

View File

@ -35,7 +35,7 @@ right maxes = [3,3,3,3,3,3,3,2,2,2,1,0]
water contained = [0,0,1,0,1,2,1,0,0,1,0,0] -> sum = 6
*/
function trap (heights) {
export const trap = (heights) => {
const maxes = new Array(heights.length).fill(0)
let leftMax = 0
@ -59,5 +59,3 @@ function trap (heights) {
}
return maxes.reduce((a, b) => a + b, 0)
}
console.log(trap([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1])) // -> 6

View File

@ -0,0 +1,11 @@
import { trap } from '../TrappingRainWater'
describe('TrappingRainWater', () => {
it('expects 6 units of rain water are being trapped', () => {
expect(trap([0,1,0,2,1,0,1,3,2,1,2,1])).toBe(6)
})
it('expects 9 units of rain water are being trapped', () => {
expect(trap([4,2,0,3,2,5])).toBe(9)
})
})