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

Ilkka Hietaniemi #41

Open
wants to merge 2 commits into
base: testing
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
84 changes: 29 additions & 55 deletions src/fi/oulu/tol/sqat/GildedRose.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

public class GildedRose {

private static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
private static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
private static final String AGED_BRIE = "Aged Brie";
private static final int SELL_IN_TEN = 10, SELL_IN_FIVE = 5;
private static List<Item> items = null;

public List<Item> getItems() {
Expand All @@ -21,78 +25,48 @@ public GildedRose() {
}
public static void updateEndOfDay()
{
for (int i = 0; i < items.size(); i++)
{
if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
for(Item item:items){
if (!SULFURAS.equals(item.getName()))
{
if (items.get(i).getQuality() > 0)
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
}
item.decreaseSellIn();
}
else

if ((AGED_BRIE.equals(item.getName())) || BACKSTAGE_PASSES.equals(item.getName()))
{
if (items.get(i).getQuality() < 50)
if (BACKSTAGE_PASSES.equals(item.getName()) && item.getSellIn() <= SELL_IN_TEN)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
item.increaseQuality();
if (item.getSellIn() <= SELL_IN_FIVE)
{
if (items.get(i).getSellIn() < 11)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}

if (items.get(i).getSellIn() < 6)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
item.increaseQuality();
}
}
item.increaseQuality();
}

if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
else if (!SULFURAS.equals(item.getName()))
{
items.get(i).setSellIn(items.get(i).getSellIn() - 1);
item.decreaseQuality();
}

if (items.get(i).getSellIn() < 0)

if (item.isExpired())
{
if (!"Aged Brie".equals(items.get(i).getName()))
if (AGED_BRIE.equals(item.getName()))
{
if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getQuality() > 0)
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
}
}
else
{
items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality());
}
item.increaseQuality();
}
else
else if (BACKSTAGE_PASSES.equals(item.getName()))
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
item.setQuality(0);
}
else if(!SULFURAS.equals(item.getName()))
{
item.decreaseQuality();
}
}
}
}

}
24 changes: 24 additions & 0 deletions src/fi/oulu/tol/sqat/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


public class Item {

final int MAX_QUALITY = 50, MIN_QUALITY = 0;

String name;
int sellIn;
int quality;
Expand Down Expand Up @@ -31,5 +34,26 @@ public int getQuality() {
public void setQuality(int quality) {
this.quality = quality;
}
public void decreaseQuality(){
if(this.quality > MIN_QUALITY){
this.quality--;
}
}
public void increaseQuality(){
if(this.quality < MAX_QUALITY){
this.quality++;
}
}
public void decreaseSellIn(){
this.sellIn--;
}
public boolean isExpired(){
if(this.sellIn < 0){
return true;
}
else{
return false;
}
}
}

114 changes: 112 additions & 2 deletions src/fi/oulu/tol/sqat/tests/GildedRoseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import org.junit.Test;
import org.junit.Before;

import fi.oulu.tol.sqat.GildedRose;
import fi.oulu.tol.sqat.Item;
Expand All @@ -19,11 +20,26 @@ public class GildedRoseTest {
// Item("Sulfuras, Hand of Ragnaros", 0, 80));
// Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
// Item("Conjured Mana Cake", 3, 6));

public GildedRose store;

public GildedRoseTest(){
store = new GildedRose();
}
@Before
public void addItemsToStore(){
store.addItem(new Item("+5 Dexterity Vest", 10, 20));
store.addItem(new Item("Aged Brie", 2, 0));
store.addItem(new Item("Elixir of the Mongoose", 5, 7));
store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
store.addItem(new Item("Conjured Mana Cake", 3, 6));
}

@Test
public void testUpdateEndOfDay_AgedBrie_Quality_10_11() {
// Arrange
GildedRose store = new GildedRose();
store = new GildedRose();
store.addItem(new Item("Aged Brie", 2, 10) );

// Act
Expand All @@ -37,6 +53,100 @@ public void testUpdateEndOfDay_AgedBrie_Quality_10_11() {

@Test
public void testUpdateEndOfDay() {
fail("Test not implemented");
//Arrange


//Act
store.updateEndOfDay();

//Assert
List<Item> items = store.getItems();
Item itemDex = items.get(0);
assertEquals(19, itemDex.getQuality());
}
@Test
public void testUpdateEndOfDaysNegative(){
//Arrange


//Act
for(int i = 30; i > 0; i--){
store.updateEndOfDay();
}
List<Item> items = store.getItems();
Item itemDex = items.get(0);
assertEquals(0, itemDex.getQuality());
}
@Test
public void testUpdateEndOfDaysSeveralItems(){
//Arrange

//Act
store.updateEndOfDay();

List<Item> items = store.getItems();
Item item = items.get(3);
assertEquals(80, item.getQuality());
}
@Test
public void testUpdateSellIn(){
//Arrange

//Act
store.updateEndOfDay();

List<Item> items = store.getItems();
Item item = items.get(2);
assertEquals(4, item.getSellIn());
}
@Test
public void testQualityDecreaseFast(){
//Arrange

//Act
for(int i = 0; i < 12; i++){
store.updateEndOfDay();
}

List<Item> items = store.getItems();
Item item = items.get(0);
assertEquals(6, item.getQuality());
}
@Test
public void testBrieMaxQuality(){
//Arrange

//Act
for(int i = 0; i < 60; i++){
store.updateEndOfDay();
}

List<Item> items = store.getItems();
Item item = items.get(1);
assertEquals(50, item.getQuality());
}
@Test
public void tesBrieThreeDays(){
//Arrange

//Act
store.updateEndOfDay();
store.updateEndOfDay();
store.updateEndOfDay();
List<Item> items = store.getItems();
Item item = items.get(1);
assertEquals(4, item.getQuality());
}
@Test
public void testUpdateEndOfDay_AgedBrie_Quality_0_10() {
// Arrange
GildedRose store1 = new GildedRose();
store1.addItem(new Item("Aged Brie", 0, 10) );
// Act
store1.updateEndOfDay();
// Assert
int quality = store.getItems().get(0).getQuality();
String failMessage = "The Quality of Aged Brie increases twice afterSellIn date has passed";
assertEquals(failMessage, 12, quality);
}
}