浏览代码

update test and read me

Nhu Nguyen 6 年前
父节点
当前提交
5b2f4c3a53
共有 3 个文件被更改,包括 93 次插入31 次删除
  1. 7
    19
      Inventory.java
  2. 12
    0
      InventoryTest.java
  3. 74
    12
      README.MD

+ 7
- 19
Inventory.java 查看文件

7
         this.items = items;
7
         this.items = items;
8
     }
8
     }
9
 
9
 
10
-    public Inventory() {
11
-        super();
12
-        items = new Item[] {
13
-                    new Item("+5 Dexterity Vest", 10, 20), 
14
-                    new Item("Aged Brie", 2, 0),
15
-                    new Item("Elixir of the Mongoose", 5, 7),
16
-                    new Item("Sulfuras, Hand of Ragnaros", 0, 80),
17
-                    new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
18
-                    new Item("Conjured Mana Cake", 3, 6) 
19
-                };
20
-
21
-    }
22
 
10
 
23
     public void updateQuality() {
11
     public void updateQuality() {
24
         for (int i = 0; i < items.length; i++) {
12
         for (int i = 0; i < items.length; i++) {
25
-            if (items[i].getName() != "Aged Brie"
26
-                    && items[i].getName() != "Backstage passes to a TAFKAL80ETC concert") {
13
+            if (!items[i].getName().equals("Aged Brie")
14
+                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
27
                 if (items[i].getQuality() > 0) {
15
                 if (items[i].getQuality() > 0) {
28
-                    if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
16
+                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
29
                         items[i].setQuality(items[i].getQuality() - 1);
17
                         items[i].setQuality(items[i].getQuality() - 1);
30
                     }
18
                     }
31
                 }
19
                 }
49
                 }
37
                 }
50
             }
38
             }
51
 
39
 
52
-            if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
40
+            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
53
                 items[i].setSellIn(items[i].getSellIn() - 1);
41
                 items[i].setSellIn(items[i].getSellIn() - 1);
54
             }
42
             }
55
 
43
 
56
             if (items[i].getSellIn() < 0) {
44
             if (items[i].getSellIn() < 0) {
57
-                if (items[i].getName() != "Aged Brie") {
58
-                    if (items[i].getName() != "Backstage passes to a TAFKAL80ETC concert") {
45
+                if (!items[i].getName().equals("Aged Brie")) {
46
+                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
59
                         if (items[i].getQuality() > 0) {
47
                         if (items[i].getQuality() > 0) {
60
-                            if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
48
+                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
61
                                 items[i].setQuality(items[i].getQuality() - 1);
49
                                 items[i].setQuality(items[i].getQuality() - 1);
62
                             }
50
                             }
63
                         }
51
                         }

+ 12
- 0
InventoryTest.java 查看文件

109
     }
109
     }
110
 
110
 
111
     @Test
111
     @Test
112
+    public void testUpdate_WhenAgedBrieOnceTheSellInDatePassed() throws Exception {
113
+        Item agedBrie = new Item(AGED_BRIE_NAME, -1, 20);
114
+        int expectedQuality = agedBrie.getQuality() + 2;
115
+        Item[] items = {agedBrie};
116
+        Inventory sut = new Inventory(items);
117
+
118
+        sut.updateQuality();
119
+
120
+        assertEquals(expectedQuality, agedBrie.getQuality());
121
+    }
122
+
123
+    @Test
112
     public void testUpdate_ForBackstagePassesAfterTheConcertOccurred() throws Exception {
124
     public void testUpdate_ForBackstagePassesAfterTheConcertOccurred() throws Exception {
113
         Item backStagePass = new Item(BACKSTAGE_PASS_NAME, -1, 20);
125
         Item backStagePass = new Item(BACKSTAGE_PASS_NAME, -1, 20);
114
         Item[] items = {backStagePass};
126
         Item[] items = {backStagePass};

+ 74
- 12
README.MD 查看文件

1
-------------------------------------------------------------------------
2
-This is the project README file. Here, you should describe your project.
3
-Tell the reader (someone who does not know anything about this project)
4
-all he/she needs to know. The comments should usually include at least:
5
-------------------------------------------------------------------------
6
-
7
-PROJECT TITLE:
8
-PURPOSE OF PROJECT:
9
-VERSION or DATE:
10
-HOW TO START THIS PROJECT:
11
-AUTHORS:
12
-USER INSTRUCTIONS:
1
+# Clean Code
2
+
3
+### **Objective:**
4
+* Refactor (aka clean up) the code in the `Inventory` class to make it more maintainable and readable.
5
+
6
+### **Purpose:**
7
+* To understand why writing test matter
8
+* To understand why writing readable code matter
9
+
10
+### **Instructions:**
11
+
12
+1. Fork this Repository
13
+    * [fork](https://help.github.com/articles/fork-a-repo/) this repository to your personal github account
14
+    * [clone](https://help.github.com/articles/cloning-a-repository/) **your** `forked` repository to your local machine.
15
+    * clean up the code in the `Inventory` class
16
+    * commit your changes
17
+    * submit a `pull request` which compares Zipcoder your branch with the branch level (eg. if you work on level2, the base should be zipcode's level2 branch compare to your level2 branch)
18
+3. DO NOT CHANGE THE TEST
19
+
20
+# Levels
21
+This lab is divided into two levels. If you are 90% done with your labs or if you want to challenge yourself, get level2 with `git checkout level2` after you clone the repository. Otherwise, work on the master branch. 
22
+
23
+# Part 1 - Original Description of the Gilded Rose
24
+
25
+Hi and welcome to team Gilded Rose. As you know, we are a small inn
26
+with a prime location in a prominent city run by a friendly innkeeper
27
+named Allison. We also buy and sell only the finest
28
+goods. Unfortunately, our goods are constantly degrading in quality as
29
+they approach their sell by date. We have a system in place that
30
+updates our inventory for us. It was developed by a no-nonsense type
31
+named Leeroy, who has moved on to new adventures. Your task is to add
32
+the new feature to our system so that we can begin selling a new
33
+category of items. First an introduction to our system:
34
+
35
+- All items have a SellIn value which denotes the number of days we
36
+  have to sell the item
37
+- All items have a Quality value which denotes how valuable the item
38
+  is
39
+- At the end of each day our system lowers both values for every item
40
+
41
+Pretty simple, right? Well this is where it gets interesting:
42
+
43
+  - Once the sell by date has passed, Quality degrades twice as fast
44
+  - The Quality of an item is never negative
45
+  - "Aged Brie" actually increases in Quality the older it gets
46
+  - The Quality of an item is never more than 50
47
+  - "Sulfuras", being a legendary item, never has to be sold or
48
+    decreases in Quality
49
+  - "Backstage passes", like aged brie, increases in Quality as it's
50
+    SellIn value approaches; Quality increases by 2 when there are 10
51
+    days or less and by 3 when there are 5 days or less but Quality
52
+    drops to 0 after the concert
53
+
54
+Just for clarification, an item can never have its Quality increase
55
+above 50, however "Sulfuras" is a legendary item and as such its
56
+Quality is 80 and it never alters.
57
+
58
+DO NOT alter the Item class or Items property as those belong to the goblin
59
+in the corner who will insta-rage and one-shot you as he doesn't
60
+believe in shared code ownership (you can make the UpdateQuality
61
+method and Items property static if you like, we'll cover for
62
+you).
63
+
64
+## Part 2 - Add a new item
65
+
66
+We have recently signed a supplier of conjured items. This requires an update to our system:
67
+
68
+- "Conjured" items degrade in Quality twice as fast as normal items
69
+
70
+Feel free to make any changes to the UpdateQuality method and add any
71
+new code as long as everything still works correctly.
72
+
73
+
74
+This was "borrowed" from [alexaitken](https://github.com/alexaitken/GildedRose_java) which originated from [Bobby Johnson's Blog](https://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/).