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 #1459

Open
wants to merge 2 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
27 changes: 27 additions & 0 deletions src/main/java/RewardValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class RewardValue {
private Double Cash = null;
private Integer Miles = null;
public static final double MILES_TO_CASH = 0.0035;

public RewardValue(double CashValue) {
this.Cash = CashValue;
}

public RewardValue(int MilesValue) {
this.Miles = MilesValue;
}

public double getCashValue() {
if (Cash != null) {
return Cash;
}
return MILES_TO_CASH * Miles;
}

public Integer getMilesValue() {
if (Miles != null) {
return Miles;
}
return (int) (1 / MILES_TO_CASH * Cash);
}
}
12 changes: 10 additions & 2 deletions src/test/java/RewardValueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ void create_with_miles_value() {

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

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