Browse Source

Optimizing: Price of Item is float now

feature-pr/shop
Maxim Volkov 3 years ago
parent
commit
f6511309b1
  1. 6
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java
  2. 7
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

6
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java

@ -2,7 +2,7 @@ package de.hs_fulda.ciip.projjpn;
public class Item { public class Item {
private int price;
private float price;
// customerReview // customerReview
// productTitle // productTitle
// description // description
@ -17,11 +17,11 @@ public class Item {
availability = newAmount; availability = newAmount;
} }
public void updatePrice(int price) {
public void updatePrice(float price) {
this.price = price; this.price = price;
} }
public int getCurrentPrice() {
public float getCurrentPrice() {
return price; return price;
} }
} }

7
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

@ -29,20 +29,19 @@ public class ItemTest extends TestCase {
// Given // Given
Item item = new Item(); Item item = new Item();
int quantity = 3; int quantity = 3;
int price = 5;
float price = 5;
item.updateAvailability(quantity); item.updateAvailability(quantity);
item.updatePrice(price); item.updatePrice(price);
// When // When
int expectedPrice = quantity * price;
float expectedPrice = quantity * price;
// Then // Then
int actualPrice = 0;
float actualPrice = 0;
for(int i = 0; i < quantity; i++) { for(int i = 0; i < quantity; i++) {
actualPrice += item.getCurrentPrice(); actualPrice += item.getCurrentPrice();
} }
assertEquals(expectedPrice, actualPrice); assertEquals(expectedPrice, actualPrice);
} }
} }
Loading…
Cancel
Save