From 671b3922a8652d4284de038dc261c465c1f5e602 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:57:49 -0500 Subject: [PATCH 1/8] update --- src/pricingutil.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pricingutil.cpp b/src/pricingutil.cpp index 96bee04..85c8581 100644 --- a/src/pricingutil.cpp +++ b/src/pricingutil.cpp @@ -1 +1,14 @@ #include "pricingutil.h" + +PricingUtil::PricingUtil() {} + +//account for negative prevPrice, 0 interest, etc. + +float PricingUtil::calcVal(float prevPrice, float interest, float oleoConstant) { + this->val = (prevPrice * (0.9 + interest)) * oleoConstant; + return this->val; +} + +float PricingUtil::getVal() { + return this->val; +} From ac98b06adb868a80972fedeca94bf29ce1fdc3af Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:00:06 -0500 Subject: [PATCH 2/8] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index baa551d..ff0a268 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,27 @@ Please include the following when you are writing your PR: General things: 1. What is the purpose of this PR? + +Submit Pt2 Update + 2. What changes did you make? Why? + +Wrote the cpp source files for pricing calculation + 3. What bugs did you find while testing? +N/A + This PR Specific: 1. What challenges did you face while writing the module from scratch? + +N/A. Took a few minutes to get used to headers + 2. How did you ensure your unit tests are comprehensive? + +Thought of a lot of edge cases, and tested them. + 3. Did you have enough guidance to complete the task? + +Generally, yes. From 344ddfa44a55a0f5a1618181de0e3b4926e7ad28 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Mon, 16 Oct 2023 02:39:03 -0500 Subject: [PATCH 3/8] // --- src/pricingutil.cpp | 2 -- tst/test_pricingutil.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/pricingutil.cpp b/src/pricingutil.cpp index 85c8581..25873cf 100644 --- a/src/pricingutil.cpp +++ b/src/pricingutil.cpp @@ -2,8 +2,6 @@ PricingUtil::PricingUtil() {} -//account for negative prevPrice, 0 interest, etc. - float PricingUtil::calcVal(float prevPrice, float interest, float oleoConstant) { this->val = (prevPrice * (0.9 + interest)) * oleoConstant; return this->val; diff --git a/tst/test_pricingutil.cpp b/tst/test_pricingutil.cpp index af8a3dc..475371d 100644 --- a/tst/test_pricingutil.cpp +++ b/tst/test_pricingutil.cpp @@ -2,4 +2,38 @@ TEST(sampleTest, sample) { EXPECT_EQ(4, 4); +} + + +//pu has getVal() and calcVal(float prevPrice, float interest, float oleoConstant) +//Theoretical Value = (Previous Price * (0.9 + Interest Rate)) * Oleo Constant + +TEST(PricingUtilTest, zeroEverything) { + PricingUtil pu; + EXPECT_EQ(0.0, pu.calcVal(0.0, 0.0, 0.0)); +} + +TEST(PricingUtilTest, negPrevPrice) { + PricingUtil pu; + EXPECT_EQ(-1.0, pu.calcVal(-1.0, 0.1, 1.0)); +} + +TEST(PricingUtilTest, zeroConstant) { + PricingUtil pu; + EXPECT_EQ(0.0, pu.calcVal(-1.0, 0.1, 0.0)); + +} + +TEST(PricingUtilTest, negInterest) { + PricingUtil pu; + EXPECT_EQ(-0.8, pu.calcVal(-1.0, -0.1, 1.0)); +} + +TEST(PricingUtilTest, getVal) { + PricingUtil pu; + EXPECT_EQ(0, pu.getVal()); + float calculated = pu.calcVal(-1.0, -0.1, 1.0); + EXPECT_EQ(calculated, pu.getVal()); + EXPECT_EQ(calculated, -0.8); + } \ No newline at end of file From ee8366edde1b2cfdf5baa7709034af26765f6404 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:21:42 -0500 Subject: [PATCH 4/8] Update test_pricingutil.cpp --- tst/test_pricingutil.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tst/test_pricingutil.cpp b/tst/test_pricingutil.cpp index 475371d..33f3b5d 100644 --- a/tst/test_pricingutil.cpp +++ b/tst/test_pricingutil.cpp @@ -1,4 +1,5 @@ #include +#include "pricingutil.h" TEST(sampleTest, sample) { EXPECT_EQ(4, 4); @@ -26,7 +27,7 @@ TEST(PricingUtilTest, zeroConstant) { TEST(PricingUtilTest, negInterest) { PricingUtil pu; - EXPECT_EQ(-0.8, pu.calcVal(-1.0, -0.1, 1.0)); + EXPECT_EQ(-0.8f, pu.calcVal(-1.0, -0.1, 1.0)); } TEST(PricingUtilTest, getVal) { @@ -34,6 +35,6 @@ TEST(PricingUtilTest, getVal) { EXPECT_EQ(0, pu.getVal()); float calculated = pu.calcVal(-1.0, -0.1, 1.0); EXPECT_EQ(calculated, pu.getVal()); - EXPECT_EQ(calculated, -0.8); + EXPECT_EQ(calculated, -0.8f); } \ No newline at end of file From bc14bcbde5a2360946419a3325faec0537f9cf37 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:16:45 +0800 Subject: [PATCH 5/8] Update pricingutil.h --- src/pricingutil.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pricingutil.h b/src/pricingutil.h index 3970f9f..f504330 100644 --- a/src/pricingutil.h +++ b/src/pricingutil.h @@ -9,7 +9,6 @@ class PricingUtil { public: PricingUtil(); - float val = 0; float calcVal(float prevPrice, float interest, float oleoConstant); float getVal(); }; From a6bce47022894c66d38d44da5b5cb0e2baecc5ad Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:19:22 +0800 Subject: [PATCH 6/8] Update pricingutil.h --- src/pricingutil.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pricingutil.h b/src/pricingutil.h index f504330..3970f9f 100644 --- a/src/pricingutil.h +++ b/src/pricingutil.h @@ -9,6 +9,7 @@ class PricingUtil { public: PricingUtil(); + float val = 0; float calcVal(float prevPrice, float interest, float oleoConstant); float getVal(); }; From 5bf703c572fba5358c355f98a7d49c11f31efc1d Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:21:04 +0800 Subject: [PATCH 7/8] Update pricingutil.h --- src/pricingutil.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pricingutil.h b/src/pricingutil.h index 3970f9f..314bf1e 100644 --- a/src/pricingutil.h +++ b/src/pricingutil.h @@ -9,9 +9,10 @@ class PricingUtil { public: PricingUtil(); - float val = 0; float calcVal(float prevPrice, float interest, float oleoConstant); float getVal(); + private: + float val; }; From 8e6021a427565c767dd721eee30baf2d51dafb23 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:21:51 +0800 Subject: [PATCH 8/8] Update pricingutil.cpp --- src/pricingutil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pricingutil.cpp b/src/pricingutil.cpp index 25873cf..c344ab5 100644 --- a/src/pricingutil.cpp +++ b/src/pricingutil.cpp @@ -1,6 +1,6 @@ #include "pricingutil.h" -PricingUtil::PricingUtil() {} +PricingUtil::PricingUtil(): val(0) {} float PricingUtil::calcVal(float prevPrice, float interest, float oleoConstant) { this->val = (prevPrice * (0.9 + interest)) * oleoConstant;