Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
11 changes: 11 additions & 0 deletions src/pricingutil.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 2 additions & 1 deletion src/pricingutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
class PricingUtil {
public:
PricingUtil();
float val = 0;
float calcVal(float prevPrice, float interest, float oleoConstant);
float getVal();
private:
float val;
};


Expand Down
35 changes: 35 additions & 0 deletions tst/test_pricingutil.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#include <gtest/gtest.h>
#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);

}