mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
First simplification of app + unittests
This commit is contained in:
parent
181b48aff7
commit
d83aa3ca8c
@ -3,60 +3,88 @@ package com.gildedrose;
|
|||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
|
|
||||||
|
String itemName;
|
||||||
|
int itemQuality;
|
||||||
|
int itemSellIn;
|
||||||
|
|
||||||
public GildedRose(Item[] items) {
|
public GildedRose(Item[] items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
if (!items[i].name.equals("Aged Brie")
|
itemName = items[i].name;
|
||||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
itemQuality = items[i].quality;
|
||||||
if (items[i].quality > 0) {
|
itemSellIn = items[i].sellIn;
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
|
||||||
items[i].quality = items[i].quality - 1;
|
if (!itemIsAgedBrie(itemName)
|
||||||
|
&& !itemIsBackstagePasses(itemName)) {
|
||||||
|
if (itemQuality > 0) {
|
||||||
|
if (!itemIsSulfuras(itemName)) {
|
||||||
|
decreaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality < 50) {
|
if (itemQuality < 50) {
|
||||||
items[i].quality = items[i].quality + 1;
|
itemQuality = itemQuality + 1;
|
||||||
|
|
||||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (itemIsBackstagePasses(itemName)) {
|
||||||
if (items[i].sellIn < 11) {
|
if (itemSellIn < 11) {
|
||||||
if (items[i].quality < 50) {
|
if (itemQuality < 50) {
|
||||||
items[i].quality = items[i].quality + 1;
|
increaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].sellIn < 6) {
|
if (itemSellIn < 6) {
|
||||||
if (items[i].quality < 50) {
|
if (itemQuality < 50) {
|
||||||
items[i].quality = items[i].quality + 1;
|
increaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!itemIsSulfuras(itemName)) {
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
decreaseByOne(itemSellIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].sellIn < 0) {
|
if (itemSellIn < 0) {
|
||||||
if (!items[i].name.equals("Aged Brie")) {
|
if (!itemIsAgedBrie(itemName)) {
|
||||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!itemIsBackstagePasses(itemName)) {
|
||||||
if (items[i].quality > 0) {
|
if (itemQuality > 0) {
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!itemIsSulfuras(itemName)) {
|
||||||
items[i].quality = items[i].quality - 1;
|
decreaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
decreaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality < 50) {
|
if (itemQuality < 50) {
|
||||||
items[i].quality = items[i].quality + 1;
|
increaseByOne(itemQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void increaseByOne (int itemValue) {
|
||||||
|
itemValue++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decreaseByOne (int itemValue) {
|
||||||
|
itemValue--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean itemIsSulfuras(String itemName) {
|
||||||
|
return ProjectConstants.SULFURAS.equals(itemName) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean itemIsBackstagePasses(String itemName) {
|
||||||
|
return ProjectConstants.BACKSTAGE_PASSES.equals(itemName) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean itemIsAgedBrie(String itemName) {
|
||||||
|
return ProjectConstants.AGED_BRIE.equals(itemName) ? true : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
7
Java/src/main/java/com/gildedrose/ProjectConstants.java
Normal file
7
Java/src/main/java/com/gildedrose/ProjectConstants.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
class ProjectConstants {
|
||||||
|
public static final String AGED_BRIE = "Aged Brie";
|
||||||
|
public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
|
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||||
|
}
|
||||||
@ -1,17 +1,46 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
class GildedRoseTest {
|
class GildedRoseTest {
|
||||||
|
|
||||||
@Test
|
GildedRose app;
|
||||||
void foo() {
|
|
||||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
@BeforeAll
|
||||||
GildedRose app = new GildedRose(items);
|
public void init() {
|
||||||
app.updateQuality();
|
Item[] items = new Item[] { new Item(ProjectConstants.SULFURAS, 0, 0) };
|
||||||
assertEquals("fixme", app.items[0].name);
|
app = new GildedRose(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void increaseByOne() {
|
||||||
|
int initial = 2;
|
||||||
|
app.increaseByOne(initial);
|
||||||
|
assertEquals("3", initial);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decreaseByOne() {
|
||||||
|
int initial = 2;
|
||||||
|
app.decreaseByOne(initial);
|
||||||
|
assertEquals("1", initial);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void itemIsSulfuras() {
|
||||||
|
String itemName = app.items[0].name;
|
||||||
|
boolean result = app.itemIsSulfuras(itemName);
|
||||||
|
assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ItemIsAgedBrieFalse() {
|
||||||
|
String itemName = app.items[0].name;
|
||||||
|
boolean result = app.itemIsAgedBrie(itemName);
|
||||||
|
assertFalse(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user