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. diff --git a/src/pricingutil.cpp b/src/pricingutil.cpp index 96bee04..c344ab5 100644 --- a/src/pricingutil.cpp +++ b/src/pricingutil.cpp @@ -1 +1,12 @@ #include "pricingutil.h" + +PricingUtil::PricingUtil(): val(0) {} + +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; +} 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; }; diff --git a/tst/test_pricingutil.cpp b/tst/test_pricingutil.cpp index af8a3dc..33f3b5d 100644 --- a/tst/test_pricingutil.cpp +++ b/tst/test_pricingutil.cpp @@ -1,5 +1,40 @@ #include +#include "pricingutil.h" 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.8f, 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.8f); + } \ No newline at end of file