From d7611391d24c97430b42b9a1fbe620f88d1791e3 Mon Sep 17 00:00:00 2001 From: Asus Date: Thu, 20 Oct 2016 13:06:17 +0300 Subject: [PATCH] Exercise complete Assignment#5 --- bin/.gitignore | 1 + bin/fi/oulu/tol/sqat/GildedRose.class | Bin 2380 -> 1595 bytes bin/fi/oulu/tol/sqat/Item.class | Bin 1034 -> 1034 bytes .../oulu/tol/sqat/tests/GildedRoseTest.class | Bin 504 -> 1185 bytes src/fi/oulu/tol/sqat/GildedRose.java | 154 ++++++------------ src/fi/oulu/tol/sqat/Item.java | 2 + src/fi/oulu/tol/sqat/QualityUpdater.java | 55 +++++++ .../oulu/tol/sqat/tests/GildedRoseTest.java | 21 ++- 8 files changed, 124 insertions(+), 109 deletions(-) create mode 100644 bin/.gitignore create mode 100644 src/fi/oulu/tol/sqat/QualityUpdater.java diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..76b3e7b --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/fi/ diff --git a/bin/fi/oulu/tol/sqat/GildedRose.class b/bin/fi/oulu/tol/sqat/GildedRose.class index f244eba73874c91f18244a292b7f88cc3b4b5f80..2945e7d4f471dfc8d8ee0dcdc7f6c6ac1a4f6509 100644 GIT binary patch literal 1595 zcmah}T~8BH5IwgoEG#Q6Ek)%+L8+7$sNY{j6j8LMU=+pZ+l4N;T3cziMiS!>@elao zgC+`56XUbL#P}n`b9a|*wN_u|?wy@EbLPzKe*5|93xE^2p&=kJux4e-wPGz}my4O| zhO{%+tYX0|+%8v54IzQZBl%2bin6qxxw-PlT(t$dH)^tI*_(Ht7Nl)f1V-{rD7StK z$qKYtw)vzg5YIb+HQOp?W-ArBnYXGo-*+xq>m_N|DyG2H-(seli{uEIondnOv{ka~ z8G&GOd|4ngS1y=3f(RSvf}x>D;NX8K>WCoR34vY%ZDB`?Io@z&DIiEsnNpgzz6$7)l>MU!HL^s?|ML_VTFO_SRRde1_3m2}h z(3Bc0Mz}XYe!T%i)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a-N@5JYb;~oy-F3&89eH|M5&WC(q!lcz;O+_rkFMa(!6OPyk|3*sng0M*izc}M diff --git a/bin/fi/oulu/tol/sqat/Item.class b/bin/fi/oulu/tol/sqat/Item.class index 478a73984862181a0a6b22a57fca5a1788d6a3f6..72e43a82b363d5fbf029a05788ade4700e09d09c 100644 GIT binary patch delta 85 zcmeC;=;GL*!X(JWz{0@8z{$YNzz2lF4E&Q#nW7klCr@CqWffy!We}fyiOG#o637>w gtjDauDgzXgogB^V#wZUK+YS^{0*Wb5e!{E<08YLSZ~y=R delta 85 zcmeC;=;GL*!X(Jaz{0@Az{$YPz{kMDAk4r!*_0`YQE>7ECR*4}VcK{RQN?kA=fILI*hOmX)Wa!Dv zl^KFB9E)q{K~zT=kudrhCjNttJno>A65ynf7TQ^R8%Gpr%<-9V;35GsJl2R-h#xSK^ znPwQxlsc9lNLSePe6cuJR(7Ox+`$Y(*t9GK!!VxdPE+mVTNm!>NF%~9;Qy1J!kX2Q z!5m@LxolxA-iUPrhmt+7V*w8sG=gb+)hu{10)t_?y_9llslVB#gk5#H>2WVaJ*l3k zMy>fMj1_XRV`9PcxGQx$#uEnJY)0E>R1Y%yI+u2KRGWnarN2ZcZV*ir%@c*1?O4974)M^417cEOY`I)jRVd58iG`<7&IhkO>f=75QZtD_9DCh zZqdA#qEY%Q?9argyj{D(*im9U6xS{>S;~GzZ2khb)&Bx_+u{A)g$rai6S?(ZGB}LI zsZZar+z~ND1i&EriE@PANg_#8-Lps{hjFZ8qA6^pMc5YBPff9kHIkGjq3bjY(2W@K U*r23xh~g-FwOQ$|fLW`L1+2a|R}v-?``a{SYZd6xQjPqr zULFR*ZA;`)jG-Wq_56jq-g4RP1%dLljS|WNa`v9MqKKf^)EZ0-O90ue;1F`jqn zf*xs{5kK)^KvKgv)FjpZ6zC~V0%`sm$b4H_dI)MUd4sGAazBt{6+~J@5mx=9RTvwn Fz5u#qB`p8| diff --git a/src/fi/oulu/tol/sqat/GildedRose.java b/src/fi/oulu/tol/sqat/GildedRose.java index 8d48732..41f3b11 100644 --- a/src/fi/oulu/tol/sqat/GildedRose.java +++ b/src/fi/oulu/tol/sqat/GildedRose.java @@ -1,107 +1,47 @@ -package fi.oulu.tol.sqat; - -import java.util.ArrayList; -import java.util.List; - - -public class GildedRose { - - private static List items = null; - - /** - * @param args - */ - public static void main(String[] args) { - - System.out.println("OMGHAI!"); - - items = new ArrayList(); - items.add(new Item("+5 Dexterity Vest", 10, 20)); - items.add(new Item("Aged Brie", 2, 0)); - items.add(new Item("Elixir of the Mongoose", 5, 7)); - items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); - items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); - items.add(new Item("Conjured Mana Cake", 3, 6)); - - updateQuality(); -} - - - - public static void updateQuality() - { - 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); - } - } - } - 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); - } - } - } - } - } - - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) - { - items.get(i).setSellIn(items.get(i).getSellIn() - 1); - } - - if (items.get(i).getSellIn() < 0) - { - 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 (items.get(i).getQuality() < 50) - { - items.get(i).setQuality(items.get(i).getQuality() + 1); - } - } - } - } - } - -} +package fi.oulu.tol.sqat; + +import java.util.ArrayList; + +public class GildedRose { + + private final QualityUpdater qualityUpdater; + public ArrayList items; + + public GildedRose() { + super(); + qualityUpdater = new QualityUpdater(); + + } + + public void updateQuality() { + + for (Item item : items) { + qualityUpdater.updateItemQuality(item); + } + } + + public void updateEndOfDay() { + + for (Item item : items) { + item.setQuality(11); + } + } + + public Item getItem(Item item) { + + return item; + + } + + public void addItem(Item item) { + items.add(item); + + } + + public int getQuality(Item item) { + int quality = item.getQuality(); + return quality; + + } + +} \ No newline at end of file diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java index 900d2a1..d379066 100644 --- a/src/fi/oulu/tol/sqat/Item.java +++ b/src/fi/oulu/tol/sqat/Item.java @@ -7,6 +7,8 @@ public class Item { public int quality; public Item(String name, int sellIn, int quality) { + super(); + this.setName(name); this.setSellIn(sellIn); this.setQuality(quality); diff --git a/src/fi/oulu/tol/sqat/QualityUpdater.java b/src/fi/oulu/tol/sqat/QualityUpdater.java new file mode 100644 index 0000000..24b9b35 --- /dev/null +++ b/src/fi/oulu/tol/sqat/QualityUpdater.java @@ -0,0 +1,55 @@ +package fi.oulu.tol.sqat; + +class QualityUpdater { + + void updateItemQuality(Item item) { + if (!item.name.equals("Aged Brie") + && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; + } + } + } else { + if (item.quality < 50) { + item.quality = item.quality + 1; + + if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.sellIn < 11) { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + + if (item.sellIn < 6) { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + } + } + } + + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.sellIn = item.sellIn - 1; + } + + if (item.sellIn < 0) { + if (!item.name.equals("Aged Brie")) { + if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (item.quality > 0) { + if (!item.name.equals("Sulfuras, Hand of Ragnaros")) { + item.quality = item.quality - 1; + } + } + } else { + item.quality = item.quality - item.quality; + } + } else { + if (item.quality < 50) { + item.quality = item.quality + 1; + } + } + } + } +} \ No newline at end of file diff --git a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java index 04a5d2d..ca38fcb 100644 --- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java +++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java @@ -1,12 +1,29 @@ package fi.oulu.tol.sqat.tests; import static org.junit.Assert.*; + import org.junit.Test; +import fi.oulu.tol.sqat.GildedRose; +import fi.oulu.tol.sqat.Item; + public class GildedRoseTest { + GildedRose store = new GildedRose(); + + // Test Aged Brie @Test - public void testTheTruth() { - assertTrue(true); + public void testUpdateEndOfDay_AgedBrie_Quality_2_10() { + Item item1 = new Item("Aged Brie", 2, 10); + // Arrange + store.addItem(item1); + // Act + store.updateEndOfDay(); + // Assert + Item item1AfterUpdate = store.getItem(item1); + int quality = item1AfterUpdate.getQuality(); + String failMessage = "Quality of Aged Brie increases"; + assertEquals(failMessage, 11, quality); } + }