Skip to content

Commit

Permalink
Conflicts fixed
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/CS2113-AY1819S1-T09-4/main into MonthlyLimitsFeatures

# Conflicts:
#	src/test/java/seedu/planner/logic/commands/EditLimitCommandTest.java
  • Loading branch information
OscarZeng committed Nov 7, 2018
2 parents ed4d1df + f245be4 commit a447154
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SortCommand extends Command {
+ "Example: " + COMMAND_WORD + " " + CATEGORY_NAME + " " + DESCENDING_CONDITION;

public static final Set<String> CATEGORY_SET = new HashSet<>(Arrays.asList(CATEGORY_NAME, CATEGORY_MONEYFLOW,
CATEGORY_MONEY, CATEGORY_DATE));
CATEGORY_MONEY, SortCommand.CATEGORY_DATE));
public static final Set<String> ORDER_SET = new HashSet<>(Arrays.asList(DESCENDING_CONDITION, ASCENDING_CONDITION));

private final String category;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/planner/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.planner.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.planner.model.tag.Tag.MESSAGE_TAG_NUM_CONSTRAINTS;
import static seedu.planner.model.tag.Tag.NUM_MAX_TAGS;

import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -134,6 +136,9 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
}
if (tagSet.size() > NUM_MAX_TAGS) {
throw new ParseException(String.format(MESSAGE_TAG_NUM_CONSTRAINTS, NUM_MAX_TAGS));
}
return tagSet;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/planner/model/record/MoneyFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class MoneyFlow {
+ "There must be at least 1 digit in this field.\n"
+ "2. At most 1 decimal point can be present. Decimal point is optional."
+ "If decimal point is present, it must have at least 1 digit and at most 2 digits after it.\n"
+ "3. The maximum whole number allowed is 1e16 - 1. Anything more than this is not allowed. ";
+ "3. The maximum whole number allowed is 1e12 - 1. Anything more than this is not allowed. ";

public static final String SIGN_REGEX = ("(?<sign>[-+])");
public static final String MONEYFLOW_NO_SIGN_REGEX = ("(?<money>.*)");
public static final String CURRENCY = "$";
public static final String POSITIVE_SIGN = "+";
public static final String NEGATIVE_SIGN = "-";

private static final String MONEYFLOW_VALIDATION_REGEX = "^[+-](0|[1-9]\\d{0,14})(\\.\\d{1,2})?";
private static final String MONEYFLOW_VALIDATION_REGEX = "^[+-](0|[1-9]\\d{0,11})(\\.\\d{1,2})?";

public final String value;
public final double valueDouble;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/planner/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
*/
public class Tag {

public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String TAG_VALIDATION_REGEX = "\\p{Alnum}+";
public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric,"
+ " less than 50 characters long.";
public static final String MESSAGE_TAG_NUM_CONSTRAINTS = "Number of tags should not exceed %d.";
public static final String TAG_VALIDATION_REGEX = "\\p{Alnum}{1,50}";
public static final int NUM_MAX_TAGS = 2;

public final String tagName;

Expand Down
51 changes: 26 additions & 25 deletions src/main/java/seedu/planner/ui/MixedPieChartDataList.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,66 @@
/**
* This class is responsible for converting data as a {@code ObservableList<CategoryStatistic>} into data that can be
* easily read by the custom pieChart implementation which requires different values for the label and the legend
* Label refers to the value after converting to percentages and legend is the original value.
*/
public class MixedPieChartDataList {

private static final String untaggedLabel = "<<untagged>>";

private List<PieChart.Data> expenseChartLabelData;

private List<PieChart.Data> incomeChartLabelData;
private List<PieChart.Data> expenseChartLegendData;

private List<PieChart.Data> incomeChartLegendData;
private List<PieChart.Data> expenseChartLabelData;
private List<PieChart.Data> incomeChartLabelData;

private Double totalIncome = 0.0;
private Double totalExpense = 0.0;

public MixedPieChartDataList(ObservableList<CategoryStatistic> data) {
expenseChartLabelData = new ArrayList<>();
incomeChartLabelData = new ArrayList<>();
expenseChartLegendData = new ArrayList<>();
incomeChartLegendData = new ArrayList<>();
for (CategoryStatistic d : data) {
addToExpenseLabelData(d);
addToIncomeLabelData(d);
addToExpenseLegendData(d);
addToIncomeLegendData(d);
}
expenseChartLegendData = expenseChartLabelData.stream().map(d -> convertToPercentages(d, totalExpense))
expenseChartLabelData = expenseChartLegendData.stream().map(d -> convertToPercentages(d, totalExpense))
.collect(Collectors.toList());
incomeChartLegendData = incomeChartLabelData.stream().map(d -> convertToPercentages(d, totalIncome))
incomeChartLabelData = incomeChartLegendData.stream().map(d -> convertToPercentages(d, totalIncome))
.collect(Collectors.toList());
}

/**
* Process given data and adds new PieChart.Data to the incomeChartLabelData
* Process given data and adds new PieChart.Data to the incomeChartLegendData
* @param data data to be added
*/
private void addToIncomeLabelData(CategoryStatistic data) {
private void addToIncomeLegendData(CategoryStatistic data) {
if (data.getTotalIncome() > 0.0) {
String label;
if (data.getTags().isEmpty()) {
label = untaggedLabel;
} else {
label = data.getTags().toString();
}
incomeChartLabelData.add(new PieChart.Data(label, data.getTotalIncome()));
incomeChartLegendData.add(new PieChart.Data(label, data.getTotalIncome()));
totalIncome += data.getTotalIncome();
} else {
return;
}
}

/**
* Process given data and adds new PieChart.Data to the expenseChartLabelData
* Process given data and adds new PieChart.Data to the expenseChartLegendData
* @param data data to be added
*/
private void addToExpenseLabelData(CategoryStatistic data) {
private void addToExpenseLegendData(CategoryStatistic data) {
if (data.getTotalExpense() > 0.0) {
String label;
if (data.getTags().isEmpty()) {
label = untaggedLabel;
} else {
label = data.getTags().toString();
}
expenseChartLabelData.add(new PieChart.Data(label, data.getTotalExpense()));
expenseChartLegendData.add(new PieChart.Data(label, data.getTotalExpense()));
totalExpense += data.getTotalExpense();
} else {
return;
Expand All @@ -92,19 +93,11 @@ private PieChart.Data convertToPercentages(PieChart.Data data, Double total) {
}

public boolean isExpenseDataEmpty() {
return expenseChartLabelData.size() == 0 && expenseChartLegendData.size() == 0;
return expenseChartLegendData.size() == 0 && expenseChartLabelData.size() == 0;
}

public boolean isIncomeDataEmpty() {
return incomeChartLabelData.size() == 0 && incomeChartLegendData.size() == 0;
}

public List<PieChart.Data> getExpenseChartLabelData() {
return expenseChartLabelData;
}

public List<PieChart.Data> getIncomeChartLabelData() {
return incomeChartLabelData;
return incomeChartLegendData.size() == 0 && incomeChartLabelData.size() == 0;
}

public List<PieChart.Data> getExpenseChartLegendData() {
Expand All @@ -114,4 +107,12 @@ public List<PieChart.Data> getExpenseChartLegendData() {
public List<PieChart.Data> getIncomeChartLegendData() {
return incomeChartLegendData;
}

public List<PieChart.Data> getExpenseChartLabelData() {
return expenseChartLabelData;
}

public List<PieChart.Data> getIncomeChartLabelData() {
return incomeChartLabelData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import static org.junit.Assert.assertFalse;
import static seedu.planner.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.planner.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.planner.testutil.TypicalLimits.LIMIT_100;
import static seedu.planner.testutil.TypicalLimits.LIMIT_500;
import static seedu.planner.testutil.TypicalLimits.LIMIT_ALL_DIFFERENT;
import static seedu.planner.testutil.TypicalLimits.LIMIT_SINGLE_DATE_100;
import static seedu.planner.testutil.TypicalLimits.LIMIT_SINGLE_DATE_500;
import static seedu.planner.testutil.TypicalLimits.LIMIT_SINGLE_DATE_ALL_DIFF;
import static seedu.planner.testutil.TypicalRecords.getTypicalFinancialPlanner;

import org.junit.Test;
Expand All @@ -22,6 +16,7 @@
import seedu.planner.model.UserPrefs;
import seedu.planner.model.record.Limit;
import seedu.planner.testutil.LimitBuilder;
import seedu.planner.testutil.TypicalLimits;
//@@Author OscarZeng

public class EditLimitCommandTest {
Expand All @@ -30,8 +25,8 @@ public class EditLimitCommandTest {

@Test
public void execute_hasSameDatesLimitInside_success() {
Limit editedLimit = new LimitBuilder(LIMIT_100).build();
Limit originalLimit = new LimitBuilder(LIMIT_500).build();
Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_100).build();
Limit originalLimit = new LimitBuilder(TypicalLimits.LIMIT_500).build();
EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
String expectedMessage = EditLimitCommand.MESSAGE_SUCCESS + "Original Limit:\n"
+ model.generateLimitOutput(model.isExceededLimit(originalLimit),
Expand All @@ -49,8 +44,8 @@ public void execute_hasSameDatesLimitInside_success() {

@Test
public void execute_singleDateLimitInList_success() {
Limit editedLimit = new LimitBuilder(LIMIT_SINGLE_DATE_100).build();
Limit originalLimit = new LimitBuilder(LIMIT_SINGLE_DATE_500).build();
Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_SINGLE_DATE_100).build();
Limit originalLimit = new LimitBuilder(TypicalLimits.LIMIT_SINGLE_DATE_500).build();
EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
String expectedMessage = EditLimitCommand.MESSAGE_SUCCESS + "Original Limit:\n"
+ model.generateLimitOutput(model.isExceededLimit(originalLimit),
Expand All @@ -68,8 +63,8 @@ public void execute_singleDateLimitInList_success() {

@Test
public void execute_hasNoSameDatesLimitInside_fail() {
Limit editedLimit = new LimitBuilder(LIMIT_100).build();
Limit originalLimit = new LimitBuilder(LIMIT_ALL_DIFFERENT).build();
Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_100).build();
Limit originalLimit = new LimitBuilder(TypicalLimits.LIMIT_ALL_DIFFERENT).build();
EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
String expectedMessage = Messages.MESSAGE_LIMITS_DO_NOT_EXIST;
model.addLimit(originalLimit);
Expand All @@ -79,8 +74,10 @@ public void execute_hasNoSameDatesLimitInside_fail() {

@Test
public void execute_hasNoSameSingleDateLimitInside_fail() {
Limit editedLimit = new LimitBuilder(LIMIT_SINGLE_DATE_100).build();
Limit originalLimit = new LimitBuilder(LIMIT_SINGLE_DATE_ALL_DIFF).build();

Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_SINGLE_DATE_100).build();
Limit originalLimit = new LimitBuilder(TypicalLimits.LIMIT_SINGLE_DATE_ALL_DIFF).build();

EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
String expectedMessage = Messages.MESSAGE_LIMITS_DO_NOT_EXIST;
model.addLimit(originalLimit);
Expand All @@ -90,7 +87,7 @@ public void execute_hasNoSameSingleDateLimitInside_fail() {

@Test
public void execute_emptyLimitList_fail() {
Limit editedLimit = new LimitBuilder(LIMIT_100).build();
Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_100).build();
EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
String expectedMessage = Messages.MESSAGE_LIMITS_DO_NOT_EXIST;

Expand All @@ -99,8 +96,8 @@ public void execute_emptyLimitList_fail() {

@Test
public void executeUndoRedo_validLimitEditedExecution_success() throws Exception {
Limit originalLimit = new LimitBuilder(LIMIT_100).build();
Limit editedLimit = new LimitBuilder(LIMIT_500).build();
Limit originalLimit = new LimitBuilder(TypicalLimits.LIMIT_100).build();
Limit editedLimit = new LimitBuilder(TypicalLimits.LIMIT_500).build();
model.addLimit(originalLimit);
EditLimitCommand editLimitCommand = new EditLimitCommand(editedLimit);
Model expectedModel = new ModelManager(model.getFinancialPlanner(), new UserPrefs());
Expand All @@ -121,15 +118,15 @@ public void executeUndoRedo_validLimitEditedExecution_success() throws Exception

@Test
public void equals() {
final EditLimitCommand editLimitCommand2 = new EditLimitCommand(LIMIT_100);
final EditLimitCommand editLimitCommand1 = new EditLimitCommand(LIMIT_SINGLE_DATE_100);
final EditLimitCommand editLimitCommand2 = new EditLimitCommand(TypicalLimits.LIMIT_100);
final EditLimitCommand editLimitCommand1 = new EditLimitCommand(TypicalLimits.LIMIT_SINGLE_DATE_100);

// same limits -> returns true
EditLimitCommand sameLimitCommand = new EditLimitCommand(LIMIT_100);
EditLimitCommand sameLimitCommand = new EditLimitCommand(TypicalLimits.LIMIT_100);
assertTrue(editLimitCommand2.equals(sameLimitCommand));

// same limits -> returns true
EditLimitCommand differentLimitCommand = new EditLimitCommand(LIMIT_ALL_DIFFERENT);
EditLimitCommand differentLimitCommand = new EditLimitCommand(TypicalLimits.LIMIT_ALL_DIFFERENT);
assertFalse(editLimitCommand2.equals(differentLimitCommand));

// same object -> returns true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package seedu.planner.logic.commands;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.planner.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.planner.logic.commands.FindTagCommand.MESSAGE_SUCCESS;
import static seedu.planner.logic.commands.FindTagCommand.convertKeywordsToMessage;
Expand All @@ -14,6 +12,7 @@
import java.util.Arrays;
import java.util.Collections;

import org.junit.Assert;
import org.junit.Test;

import seedu.planner.logic.CommandHistory;
Expand Down Expand Up @@ -45,20 +44,20 @@ public void equals() {
FindTagCommand findSecondCommand = new FindTagCommand(secondPredicate, inputSecondStringArray);

// same object -> returns true
assertTrue(findFirstCommand.equals(findFirstCommand));
Assert.assertEquals(findFirstCommand, findFirstCommand);

// same values -> returns true
FindTagCommand findFirstCommandCopy = new FindTagCommand(firstPredicate, inputFirstStringArray);
assertTrue(findFirstCommand.equals(findFirstCommandCopy));
assertEquals(findFirstCommand, findFirstCommandCopy);

// different types -> returns false
assertFalse(findFirstCommand.equals(1));
Assert.assertNotEquals(1, findFirstCommand);

// null -> returns false
assertFalse(findFirstCommand.equals(null));
Assert.assertNotEquals(null, findFirstCommand);

// different record -> returns false
assertFalse(findFirstCommand.equals(findSecondCommand));
Assert.assertNotEquals(findFirstCommand, findSecondCommand);
}

@Test
Expand Down
Loading

0 comments on commit a447154

Please sign in to comment.