Skip to content

Commit

Permalink
Merge pull request #183 from jtankw3/master
Browse files Browse the repository at this point in the history
Fix bug and improve test
  • Loading branch information
JonathanLeeWH authored Apr 10, 2019
2 parents 3d0c4fb + 6a0aa38 commit ca6ca5a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/model/medicine/Quantity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Represents the quantity of a Medicine in the inventory.
* Guarantees: immutable; is valid as declared in {@link #isValidQuantity(String)}
*/
public class Quantity {
public class Quantity implements Comparable<Quantity> {

public static final int MAX_QUANTITY = 1000000000;
public static final int MIN_QUANTITY = 0;
Expand Down Expand Up @@ -60,6 +60,11 @@ public boolean equals(Object other) {
&& value == ((Quantity) other).value); // state check
}

@Override
public int compareTo(Quantity other) {
return Integer.compare(getNumericValue(), other.getNumericValue());
}

@Override
public int hashCode() {
return this.toString().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"batchNumber" : "GKP1685",
"expiry" : "15/08/2019",
"quantity" : "300"
},
{
"batchNumber" : "GKP1682",
"expiry" : "31/07/2019",
"quantity" : "5"
} ]
}, {
"name" : "Lipitor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import seedu.address.model.UserPrefs;
import seedu.address.model.medicine.Batch;
import seedu.address.model.medicine.BatchNumber;
import seedu.address.model.medicine.Expiry;
import seedu.address.model.medicine.Medicine;
import seedu.address.model.medicine.Quantity;
import seedu.address.testutil.BatchBuilder;
Expand Down Expand Up @@ -201,16 +202,17 @@ public void execute_removeBatchUnfilteredListOneOtherBatch_success() {
Batch batchToRemove = iter.next();

assertTrue(iter.hasNext()); // There is one more batch after removing
Batch batchRemaining = iter.next();

batches.remove(batchToRemove.getBatchNumber());

int newQuantity = medicineToUpdate.getTotalQuantity().getNumericValue()
- batchToRemove.getQuantity().getNumericValue();

Expiry newExpiry = batches.values().stream().min(Comparator.comparing(Batch::getExpiry)).get().getExpiry();

Medicine updatedMedicine = new MedicineBuilder(medicineToUpdate)
.withQuantity(Integer.toString(newQuantity))
.withExpiry(batchRemaining.getExpiry().toString())
.withExpiry(newExpiry.toString())
.withBatches(batches).build();

Batch inputBatch = new BatchBuilder(batchToRemove).withQuantity("0").build();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/testutil/TypicalMedicines.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class TypicalMedicines {
.withQuantity("0").withExpiry("-").build();
public static final Medicine LEVOTHYROXINE = new MedicineBuilder().withName("Levothyroxine Sodium")
.withCompany("3M Pharmaceuticals").withQuantity("533").withExpiry("13/08/2019").withTags("thyroid")
.withBatches("GKP1684", "233", "13/08/2019", "GKP1685", "300", "15/08/2019").build();
.withBatches("GKP1684", "233", "13/08/2019", "GKP1685", "300", "15/08/2019", "GKP1682", "5", "31/07/2019")
.build();
public static final Medicine LISINOPRIL = new MedicineBuilder().withName("Lisinopril")
.withCompany("Takeda Pharmaceutical Co.").withQuantity("94").withExpiry("06/07/2019")
.withBatches("307002", "94", "06/07/2019").build();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/ui/InformationPanelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ private void assertSorted(List<Batch> data, SortProperty sortProperty, SortDirec
sortedData.sort(Comparator.comparing(b -> b.getBatchNumber().toString()));
break;
case EXPIRY:
sortedData.sort(Comparator.comparing(b -> b.getExpiry()));
sortedData.sort(Comparator.comparing(Batch::getExpiry));
break;
case QUANTITY:
sortedData.sort(Comparator.comparing(b -> b.getQuantity().getNumericValue()));
sortedData.sort(Comparator.comparing(Batch::getQuantity));
break;
default:
throw new IllegalArgumentException("Unknown Sort Property");
Expand Down

0 comments on commit ca6ca5a

Please sign in to comment.