From 2cc9100f83738d9011d1301218adbadbfc2038e3 Mon Sep 17 00:00:00 2001 From: ABHISHEK-821005 <69668943+ABHISHEK-821005@users.noreply.github.com> Date: Sat, 31 Oct 2020 11:53:40 +0530 Subject: [PATCH] added a new example to check correctness of the code --- dynamic_programming/cut_rod.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dynamic_programming/cut_rod.cpp b/dynamic_programming/cut_rod.cpp index 80e4391d2..c365be4fc 100644 --- a/dynamic_programming/cut_rod.cpp +++ b/dynamic_programming/cut_rod.cpp @@ -92,6 +92,15 @@ static void test() { assert(max_profit2 == expected_max_profit2); std::cout << "Maximum profit with " << n2 << " inch road is " << max_profit2 << std::endl; + // Test 3 + const int16_t n3 = 5; // size of rod + std::array price3 = {2,9,17,23,45}; // price array + const int64_t max_profit3 = + dynamic_programming::cut_rod::maxProfitByCuttingRod(price3, n3); + const int64_t expected_max_profit3 = 45; + assert(max_profit3 == expected_max_profit3); + std::cout << "Maximum profit with " << n3 << " inch road is " << max_profit3 + << std::endl; } /**