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

Asignment completed. #60

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
Binary file modified bin/fi/oulu/tol/sqat/GildedRose.class
Binary file not shown.
Binary file modified bin/fi/oulu/tol/sqat/Item.class
Binary file not shown.
Binary file modified bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class
Binary file not shown.
153 changes: 93 additions & 60 deletions src/fi/oulu/tol/sqat/GildedRose.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,113 @@ public void addItem(Item item) {
public GildedRose() {
items = new ArrayList<Item>();
}
private static boolean updateQuality(int index, int quantity){
if (items.size() > index){
Item item = items.get(index);
int quality = item.getQuality();
item.setQuality(quality + quantity);
return true;
}
return false;

}
private static boolean isNotBrie(int i){
return !itemMatches(i, "Aged Brie");

}
private static boolean isNotBackstagePass(int i){
return !isBackstagePass(i);
}
private static boolean isBackstagePass(int i) {
return itemMatches(i,"Backstage passes to a TAFKAL80ETC concert");
}
private static boolean isNotSulfuras(int i){
return !itemMatches(i, "Sulfuras, Hand of Ragnaros");

}
private static boolean itemMatches(int i, String name){
Item item = getItem(i);
if (item.getName().contentEquals(name)) return true;
return false;
}
private static int getQuality(int i){
Item item = getItem(i);
return item.getQuality();
}
private static void setQuality(int i, int quality){
Item item = getItem(i);
item.setQuality(quality);
}
private static Item getItem(int i){
return items.get(i);
}
private static int getSellIn(int i){
return getItem(i).getSellIn();
}
private static void updateSellIn(int i, int quantity){
Item item = getItem(i);
int current = item.getSellIn();
item.setSellIn(current + quantity);
}
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()))
{
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);
}
for (int i = 0; i < items.size(); i++){
if (isNotBrie(i) && isNotBackstagePass(i)){
if (getQuality(i) > 0 && isNotSulfuras(i)){
updateQuality(i, -1);
}
}
else
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
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);
}
}
else{
if (getQuality(i) < 50){
updateQuality(i, 1);
if (isBackstagePass(i)){
updateBackstagePass(i);
}
}
}

if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setSellIn(items.get(i).getSellIn() - 1);
if (isNotSulfuras(i)){
updateSellIn(i, -1);
}
if (getSellIn(i) < 0){
updateSellInLessThanZero(i);
}
}
}
private static void updateBackstagePass(int i) {
if (getSellIn(i) < 11)
{
updateQuality(i, 1);
}
if (getSellIn(i) < 6)
{
updateQuality(i, 1);
}
}

if (items.get(i).getSellIn() < 0)
private static void updateSellInLessThanZero(int i){
if (isNotBrie(i))
{
if (isNotBackstagePass(i))
{
if (!"Aged Brie".equals(items.get(i).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());
}
}
else
if (getQuality(i) > 0 && isNotSulfuras(i))
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
updateQuality(i, -1);
}
}
else
{
setQuality(i, 0);
}
}
else
{
if (getQuality(i) < 50)
{
updateQuality(i, 1);
}
}
}



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

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

import fi.oulu.tol.sqat.GildedRose;
Expand All @@ -19,24 +20,125 @@ 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 static GildedRose store;


@Before
public void SetUp(){
store = new GildedRose();
store.addItem(new Item("+5 Dexterity Vest", 10, 20));
store.addItem(new Item("Aged Brie", 2, 10));
store.addItem(new Item("Elixir of the Mongoose", 5, 12));
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.addItem(new Item("Aged Brie", 2, 10) );
//GildedRose store = new GildedRose();

// Act
store.updateEndOfDay();

// Assert
List<Item> items = store.getItems();
Item itemBrie = items.get(0);
Item itemBrie = items.get(1);
assertEquals(11, itemBrie.getQuality());
}
@Test
public void Test_manacake_quality_after_2_updates(){
for (int i=0; i<2; i++){
store.updateEndOfDay();
}
Item cake = store.getItems().get(5);
assertEquals(4, cake.getQuality());
}
@Test
public void Test_manacake_selling_after_2_updates(){
for (int i=0; i<2; i++){
store.updateEndOfDay();
}
Item cake = store.getItems().get(5);
assertEquals(1, cake.getSellIn());
}

@Test
public void testUpdateEndOfDay() {
fail("Test not implemented");
public void testUpdateEndOfDay_sulfurs() {
//GildedRose store = new GildedRose();


store.updateEndOfDay();
assertEquals(80, store.getItems().get(3).getQuality());
}
@Test
public void Test_Dexterity_vest_quality_after_1_update(){
store.updateEndOfDay();
Item vest = store.getItems().get(0);
assertEquals(19, vest.getQuality());
}
@Test
public void Test_Dexterity_vest_Sellin_after_1_update(){
store.updateEndOfDay();
Item vest = store.getItems().get(0);
assertEquals(9, vest.getSellIn());
}
@Test
public void Test_aged_brie_quality_after_50_updates_should_be_50(){
for (int i=0; i<50; i++){
store.updateEndOfDay();
}
Item brie = store.getItems().get(1);
assertEquals(50, brie.getQuality());
}
@Test
public void Test_aged_brie_selling_after_50_updates_should_be_50(){
for (int i=0; i<50; i++){
store.updateEndOfDay();
}
Item brie = store.getItems().get(1);
assertEquals(-48, brie.getSellIn());
}
@Test
public void Test_Mana_cake_quality_after_10_updates_should_be_zero(){
for (int i=0; i<10; i++){
store.updateEndOfDay();
}
Item cake = store.getItems().get(5);
assertEquals(0, cake.getQuality());
}
@Test
public void Test_backstage_pass_value_when_time_is_droped_to_zero(){
for (int i=0; i<16; i++){
store.updateEndOfDay();
}
Item pass = store.getItems().get(4);
assertEquals(0, pass.getQuality());
}
@Test
public void Test_backstage_pass_double_value_increase_when_time_is_lowered_bellow_10(){
for (int i=0; i<6; i++){
store.updateEndOfDay();
}
Item pass = store.getItems().get(4);
assertEquals(27, pass.getQuality());
}
@Test
public void Test_if_quality_drops_by_2_when_time_has_passed(){
for (int i=0; i<7; i++){
store.updateEndOfDay();
}
Item elixir = store.getItems().get(2);

assertEquals(3, elixir.getQuality());
}
@Test
public void Test_if_backstage_pass_quality_increses_by_3_when_3_days_left(){
for (int i=0; i<12; i++){
store.updateEndOfDay();
}
Item pass = store.getItems().get(4);
assertEquals(41, pass.getQuality());
}
}