Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reward value #1451

Open
wants to merge 3 commits into
base: flow
Choose a base branch
from
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
31 changes: 31 additions & 0 deletions src/main/java/RewardValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class RewardValue {
private Double cash = null;
private Integer miles = null;
public static final double MILES_TO_CASH = 0.0035;

public RewardValue(double cashValue) {
if (cashValue >= 0)
cash = cashValue;
else
throw new IllegalArgumentException("cash value must be positive");
}

public RewardValue(int milesValue) {
if (milesValue >= 0)
miles = milesValue;
else
throw new IllegalArgumentException("miles value must be positive");
}

public double getCashValue() {
if (cash != null)
return cash;
return MILES_TO_CASH * miles;
}

public int getMilesValue() {
if (miles != null)
return miles;
return (int) (1 / MILES_TO_CASH * cash);
}
}
11 changes: 9 additions & 2 deletions src/test/java/RewardValueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RewardValueTests {
public static final double MILES_TO_CASH = 0.0035;

@Test
void create_with_cash_value() {
Expand All @@ -20,11 +21,17 @@ void create_with_miles_value() {

@Test
void convert_from_cash_to_miles() {
assert false;
double cashValue = 100;
var rewardValue = new RewardValue(cashValue);
int milesValue = rewardValue.getMilesValue();
assertEquals(milesValue, (int) (cashValue / MILES_TO_CASH));
}

@Test
void convert_from_miles_to_cash() {
assert false;
int milesValue = 1000;
var rewardValue = new RewardValue(milesValue);
double cashValue = rewardValue.getCashValue();
assertEquals(cashValue, milesValue * MILES_TO_CASH);
}
}