|
@@ -0,0 +1,86 @@
|
|
1
|
+# Clean Code
|
|
2
|
+
|
|
3
|
+### **Objective:**
|
|
4
|
+* To learn to read code and write test for the `Inventory` class
|
|
5
|
+* To refactor (aka clean up) the code in the `Inventory` class to make it more maintainable and readable
|
|
6
|
+
|
|
7
|
+### **Purpose:**
|
|
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 `master` to your `master`.
|
|
18
|
+3. DO NOT CHANGE THE ITEM CLASS
|
|
19
|
+
|
|
20
|
+### See test coverage
|
|
21
|
+1. Right click on the `java` folder in the `test` directory
|
|
22
|
+2. Select `Run all with test coverage`
|
|
23
|
+3. Note a window pop up which display which line is covered
|
|
24
|
+
|
|
25
|
+# Part 1 - Original Description of the Gilded Rose
|
|
26
|
+
|
|
27
|
+Hi and welcome to team Gilded Rose. As you know, we are a small inn
|
|
28
|
+with a prime location in a prominent city run by a friendly innkeeper
|
|
29
|
+named Allison. We also buy and sell only the finest
|
|
30
|
+goods. Unfortunately, our goods are constantly degrading in quality as
|
|
31
|
+they approach their sell by date. We have a system in place that
|
|
32
|
+updates our inventory for us. It was developed by a no-nonsense type
|
|
33
|
+named Leeroy, who has moved on to new adventures. Your task is to add
|
|
34
|
+the new feature to our system so that we can begin selling a new
|
|
35
|
+category of items. But before you can add a new feature, you need to add a test
|
|
36
|
+that provides 100% line coverage for the `Inventory` class.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+First an introduction to our system:
|
|
40
|
+
|
|
41
|
+- All items have a SellIn value which denotes the number of days we
|
|
42
|
+ have to sell the item
|
|
43
|
+- All items have a Quality value which denotes how valuable the item
|
|
44
|
+ is
|
|
45
|
+- At the end of each day our system lowers both values for every item
|
|
46
|
+
|
|
47
|
+Pretty simple, right? Well this is where it gets interesting:
|
|
48
|
+
|
|
49
|
+ - Once the sell by date has passed, Quality degrades twice as fast
|
|
50
|
+ - The Quality of an item is never negative
|
|
51
|
+ - "Aged Brie" actually increases in Quality the older it gets
|
|
52
|
+ - The Quality of an item is never more than 50
|
|
53
|
+ - "Sulfuras", being a legendary item, never has to be sold or
|
|
54
|
+ decreases in Quality
|
|
55
|
+ - "Backstage passes", like aged brie, increases in Quality as it's
|
|
56
|
+ SellIn value approaches; Quality increases by 2 when there are 10
|
|
57
|
+ days or less and by 3 when there are 5 days or less but Quality
|
|
58
|
+ drops to 0 after the concert
|
|
59
|
+
|
|
60
|
+Just for clarification, an item can never have its Quality increase
|
|
61
|
+above 50, however "Sulfuras" is a legendary item and as such its
|
|
62
|
+Quality is 80 and it never alters.
|
|
63
|
+
|
|
64
|
+DO NOT alter the Item class or Items property as those belong to the goblin
|
|
65
|
+in the corner who will insta-rage and one-shot you as he doesn't
|
|
66
|
+believe in shared code ownership (you can make the UpdateQuality
|
|
67
|
+method and Items property static if you like, we'll cover for
|
|
68
|
+you).
|
|
69
|
+
|
|
70
|
+## Part 2 - Refactor the code
|
|
71
|
+
|
|
72
|
+Note how hard it is to read this code. Your task is to refactor the code to make it more readable. First create a new branch called `refactor`.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+## Part 3 - Add a new item
|
|
77
|
+
|
|
78
|
+We have recently signed a supplier of conjured items. This requires an update to our system. First create a new branch called `new-item`. Add a `conjured` item.
|
|
79
|
+
|
|
80
|
+- "Conjured" items degrade in Quality twice as fast as normal items
|
|
81
|
+
|
|
82
|
+Feel free to make any changes to the UpdateQuality method and add any
|
|
83
|
+new code as long as everything still works correctly.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+This originated from [Bobby Johnson's Blog](https://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/).
|