Nhu Nguyen 6 년 전
커밋
855eda3b87
6개의 변경된 파일535개의 추가작업 그리고 0개의 파일을 삭제
  1. 179
    0
      .gitignore
  2. 76
    0
      Inventory.java
  3. 179
    0
      InventoryTest.java
  4. 36
    0
      Item.java
  5. 12
    0
      README.MD
  6. 53
    0
      package.bluej

+ 179
- 0
.gitignore 파일 보기

@@ -0,0 +1,179 @@
1
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
2
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3
+
4
+# User-specific stuff:
5
+.idea/**/workspace.xml
6
+.idea/**/tasks.xml
7
+.idea/dictionaries
8
+
9
+# Sensitive or high-churn files:
10
+.idea/**/dataSources/
11
+.idea/**/dataSources.ids
12
+.idea/**/dataSources.xml
13
+.idea/**/dataSources.local.xml
14
+.idea/**/sqlDataSources.xml
15
+.idea/**/dynamic.xml
16
+.idea/**/uiDesigner.xml
17
+
18
+# Gradle:
19
+.idea/**/gradle.xml
20
+.idea/**/libraries
21
+
22
+# CMake
23
+cmake-build-debug/
24
+
25
+# Mongo Explorer plugin:
26
+.idea/**/mongoSettings.xml
27
+
28
+## File-based project format:
29
+*.iws
30
+
31
+## Plugin-specific files:
32
+
33
+# IntelliJ
34
+/out/
35
+
36
+# mpeltonen/sbt-idea plugin
37
+.idea_modules/
38
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
39
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
40
+
41
+# User-specific stuff:
42
+*.iml
43
+.idea/**
44
+.idea/**/workspace.xml
45
+.idea/**/tasks.xml
46
+.idea/dictionaries
47
+
48
+# Sensitive or high-churn files:
49
+.idea/**/dataSources/
50
+.idea/**/dataSources.ids
51
+.idea/**/dataSources.xml
52
+.idea/**/dataSources.local.xml
53
+.idea/**/sqlDataSources.xml
54
+.idea/**/dynamic.xml
55
+.idea/**/uiDesigner.xml
56
+
57
+# Gradle:
58
+.idea/**/gradle.xml
59
+.idea/**/libraries
60
+
61
+# CMake
62
+cmake-build-debug/
63
+
64
+# Mongo Explorer plugin:
65
+.idea/**/mongoSettings.xml
66
+
67
+## File-based project format:
68
+*.iws
69
+
70
+## Plugin-specific files:
71
+
72
+# IntelliJ
73
+/out/
74
+
75
+# mpeltonen/sbt-idea plugin
76
+.idea_modules/
77
+
78
+# JIRA plugin
79
+atlassian-ide-plugin.xml
80
+
81
+# Cursive Clojure plugin
82
+.idea/replstate.xml
83
+
84
+# Crashlytics plugin (for Android Studio and IntelliJ)
85
+com_crashlytics_export_strings.xml
86
+crashlytics.properties
87
+crashlytics-build.properties
88
+fabric.properties# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
89
+                 # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
90
+
91
+                 # User-specific stuff:
92
+                 .idea/**/workspace.xml
93
+                 .idea/**/tasks.xml
94
+                 .idea/dictionaries
95
+
96
+                 # Sensitive or high-churn files:
97
+                 .idea/**/dataSources/
98
+                 .idea/**/dataSources.ids
99
+                 .idea/**/dataSources.xml
100
+                 .idea/**/dataSources.local.xml
101
+                 .idea/**/sqlDataSources.xml
102
+                 .idea/**/dynamic.xml
103
+                 .idea/**/uiDesigner.xml
104
+
105
+                 # Gradle:
106
+                 .idea/**/gradle.xml
107
+                 .idea/**/libraries
108
+
109
+                 # CMake
110
+                 cmake-build-debug/
111
+
112
+                 # Mongo Explorer plugin:
113
+                 .idea/**/mongoSettings.xml
114
+
115
+                 ## File-based project format:
116
+                 *.iws
117
+
118
+                 ## Plugin-specific files:
119
+
120
+                 # IntelliJ
121
+                 /out/
122
+
123
+                 # mpeltonen/sbt-idea plugin
124
+                 .idea_modules/
125
+
126
+                 # JIRA plugin
127
+                 atlassian-ide-plugin.xml
128
+
129
+                 # Cursive Clojure plugin
130
+                 .idea/replstate.xml
131
+
132
+                 # Crashlytics plugin (for Android Studio and IntelliJ)
133
+                 com_crashlytics_export_strings.xml
134
+                 crashlytics.properties
135
+                 crashlytics-build.properties
136
+                 fabric.properties
137
+# JIRA plugin
138
+atlassian-ide-plugin.xml
139
+
140
+# Cursive Clojure plugin
141
+.idea/replstate.xml
142
+
143
+# Crashlytics plugin (for Android Studio and IntelliJ)
144
+com_crashlytics_export_strings.xml
145
+crashlytics.properties
146
+crashlytics-build.properties
147
+fabric.properties
148
+
149
+.project
150
+.classpath
151
+.settings
152
+
153
+
154
+#maven build target
155
+target/
156
+
157
+# ---> Java
158
+# Compiled class file
159
+*.class
160
+
161
+# Log file
162
+*.log
163
+
164
+# BlueJ files
165
+*.ctxt
166
+
167
+# Mobile Tools for Java (J2ME)
168
+.mtj.tmp/
169
+
170
+# Package Files #
171
+*.jar
172
+*.war
173
+*.ear
174
+*.zip
175
+*.tar.gz
176
+*.rar
177
+
178
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
179
+hs_err_pid*

+ 76
- 0
Inventory.java 파일 보기

@@ -0,0 +1,76 @@
1
+
2
+public class Inventory {
3
+    private Item[] items;
4
+
5
+    public Inventory(Item[] items) {
6
+        super();
7
+        this.items = items;
8
+    }
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
+
23
+    public void updateQuality() {
24
+        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") {
27
+                if (items[i].getQuality() > 0) {
28
+                    if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
29
+                        items[i].setQuality(items[i].getQuality() - 1);
30
+                    }
31
+                }
32
+            } else {
33
+                if (items[i].getQuality() < 50) {
34
+                    items[i].setQuality(items[i].getQuality() + 1);
35
+
36
+                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
37
+                        if (items[i].getSellIn() < 11) {
38
+                            if (items[i].getQuality() < 50) {
39
+                                items[i].setQuality(items[i].getQuality() + 1);
40
+                            }
41
+                        }
42
+
43
+                        if (items[i].getSellIn() < 6) {
44
+                            if (items[i].getQuality() < 50) {
45
+                                items[i].setQuality(items[i].getQuality() + 1);
46
+                            }
47
+                        }
48
+                    }
49
+                }
50
+            }
51
+
52
+            if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
53
+                items[i].setSellIn(items[i].getSellIn() - 1);
54
+            }
55
+
56
+            if (items[i].getSellIn() < 0) {
57
+                if (items[i].getName() != "Aged Brie") {
58
+                    if (items[i].getName() != "Backstage passes to a TAFKAL80ETC concert") {
59
+                        if (items[i].getQuality() > 0) {
60
+                            if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
61
+                                items[i].setQuality(items[i].getQuality() - 1);
62
+                            }
63
+                        }
64
+                    } else {
65
+                        items[i].setQuality(items[i].getQuality()
66
+                                - items[i].getQuality());
67
+                    }
68
+                } else {
69
+                    if (items[i].getQuality() < 50) {
70
+                        items[i].setQuality(items[i].getQuality() + 1);
71
+                    }
72
+                }
73
+            }
74
+        }
75
+}
76
+}

+ 179
- 0
InventoryTest.java 파일 보기

@@ -0,0 +1,179 @@
1
+import static org.junit.Assert.*;
2
+import java.util.Arrays;
3
+import org.junit.Test;
4
+
5
+public class InventoryTest {
6
+	
7
+	@Test
8
+	public void should_never_changes_quailty_of_Sulfuras() throws Exception {
9
+		Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
10
+		
11
+		Inventory sut = new Inventory((Item[]) Arrays.asList(new Item("Sulfuras, Hand of Ragnaros", 0, 80)).toArray());
12
+		
13
+		sut.updateQuality();
14
+		
15
+		assertEquals(80, sulfuras.getQuality());
16
+		
17
+		
18
+	}
19
+	@Test
20
+	public void should_never_changes_sellIn_of_Sulfuras() throws Exception {
21
+		Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
22
+		
23
+		Inventory sut = new Inventory((Item[]) Arrays.asList(sulfuras).toArray());
24
+		
25
+		sut.updateQuality();
26
+		
27
+		assertEquals(0, sulfuras.getSellIn());
28
+		
29
+		
30
+	}
31
+	
32
+	
33
+	
34
+	@Test
35
+	public void should_lower_the_sellIn_by_one_for_normal_items() throws Exception {
36
+		Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
37
+		
38
+		Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
39
+		
40
+		sut.updateQuality();
41
+		
42
+		
43
+		assertEquals(9, normalItem.getSellIn());
44
+	}
45
+	
46
+	@Test
47
+	public void should_lower_the_quality_by_one_for_normal_items() throws Exception {
48
+		Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
49
+		
50
+		Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
51
+		
52
+		sut.updateQuality();
53
+		
54
+		
55
+		assertEquals(19, normalItem.getQuality());
56
+	}
57
+	
58
+	@Test
59
+	public void should_not_lower_the_quality_below_zero() throws Exception {
60
+		Item normalItem = new Item("+5 Dexterity Vest", 10, 0);
61
+		
62
+		Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
63
+		
64
+		sut.updateQuality();
65
+		
66
+		
67
+		assertEquals(0, normalItem.getQuality());
68
+	}
69
+	
70
+	@Test
71
+	public void should_lower_the_quality_twice_as_fast_once_the_sell_in_date_has_passed() throws Exception {
72
+		Item normalItem = new Item("+5 Dexterity Vest", -1, 25);
73
+		
74
+		Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
75
+		
76
+		sut.updateQuality();
77
+		
78
+		
79
+		assertEquals(23, normalItem.getQuality());
80
+	}
81
+	
82
+	
83
+	@Test
84
+	public void should_increase_the_quality_of_aged_brie_as_it_gets_older() throws Exception {
85
+		Item agedBrie = new Item("Aged Brie", 10, 25);
86
+		
87
+		Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
88
+		
89
+		sut.updateQuality();
90
+		
91
+		
92
+		assertEquals(26, agedBrie.getQuality());
93
+	}
94
+	
95
+	
96
+	@Test
97
+	public void should_not_increase_the_quality_of_aged_brie_over_50() throws Exception {
98
+		Item agedBrie = new Item("Aged Brie", 10, 50);
99
+		
100
+		Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
101
+		
102
+		sut.updateQuality();
103
+		
104
+		
105
+		assertEquals(50, agedBrie.getQuality());
106
+	}
107
+	
108
+	@Test
109
+	public void should_lower_backstage_passes_to_zero_quality_once_concert_has_happened() throws Exception {
110
+		Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 20);
111
+		
112
+		Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
113
+		
114
+		sut.updateQuality();
115
+		
116
+		
117
+		assertEquals(0, backStagePass.getQuality());
118
+	}
119
+	
120
+	@Test
121
+	public void should_increase_backstage_passes_quality_by_1_when_the_concert_is_more_than_10_days_away() throws Exception {
122
+		Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 20);
123
+		
124
+		Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
125
+		
126
+		sut.updateQuality();
127
+		
128
+		
129
+		assertEquals(21, backStagePass.getQuality());
130
+	}
131
+	
132
+	@Test
133
+	public void should_increase_backstage_passes_quality_by_2_when_the_concert_is_10_days_or_less_away() throws Exception {
134
+		Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 10, 27);
135
+		
136
+		Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
137
+		
138
+		sut.updateQuality();
139
+		
140
+		
141
+		assertEquals(29, backStagePass.getQuality());
142
+	}
143
+	
144
+	@Test
145
+	public void should_increase_backstage_passes_quality_by_3_when_the_concert_is_5_days_or_less_away() throws Exception {
146
+		Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 44);
147
+		
148
+		Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
149
+		
150
+		sut.updateQuality();
151
+		
152
+		
153
+		assertEquals(47, backStagePass.getQuality());
154
+	}
155
+	
156
+	@Test
157
+	public void should_not_increase_backstage_passes_above_a_quality_of_50() throws Exception {
158
+		Item backStagePassMoreThan10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 15, 50);
159
+		
160
+		Item backStagePass10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49);
161
+		Item backStagePass5DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 48);
162
+		
163
+		Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePassMoreThan10DaysAway, backStagePass10DaysAway, backStagePass5DaysAway).toArray());
164
+		
165
+		sut.updateQuality();
166
+		
167
+		
168
+		assertEquals(50, backStagePassMoreThan10DaysAway.getQuality());
169
+		assertEquals(50, backStagePass10DaysAway.getQuality());
170
+		assertEquals(50, backStagePass5DaysAway.getQuality());
171
+	}
172
+	
173
+	
174
+	
175
+	
176
+	
177
+	
178
+	
179
+}

+ 36
- 0
Item.java 파일 보기

@@ -0,0 +1,36 @@
1
+public class Item {
2
+    private String name;
3
+    private int sellIn;
4
+    private int quality;
5
+
6
+    public Item(String name, int sellIn, int quality) {
7
+        super();
8
+        this.name = name;
9
+        this.sellIn = sellIn;
10
+        this.quality = quality;
11
+    }
12
+
13
+    public String getName() {
14
+        return name;
15
+    }
16
+
17
+    public void setName(String name) {
18
+        this.name = name;
19
+    }
20
+
21
+    public int getSellIn() {
22
+        return sellIn;
23
+    }
24
+
25
+    public void setSellIn(int sellIn) {
26
+        this.sellIn = sellIn;
27
+    }
28
+
29
+    public int getQuality() {
30
+        return quality;
31
+    }
32
+
33
+    public void setQuality(int quality) {
34
+        this.quality = quality;
35
+    }
36
+}

+ 12
- 0
README.MD 파일 보기

@@ -0,0 +1,12 @@
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:

+ 53
- 0
package.bluej 파일 보기

@@ -0,0 +1,53 @@
1
+#BlueJ package file
2
+dependency1.from=InventoryTest
3
+dependency1.to=Item
4
+dependency1.type=UsesDependency
5
+dependency2.from=InventoryTest
6
+dependency2.to=Inventory
7
+dependency2.type=UsesDependency
8
+editor.fx.0.height=722
9
+editor.fx.0.width=800
10
+editor.fx.0.x=320
11
+editor.fx.0.y=50
12
+objectbench.height=164
13
+objectbench.width=776
14
+package.divider.horizontal=0.6
15
+package.divider.vertical=0.6845018450184502
16
+package.editor.height=364
17
+package.editor.width=674
18
+package.editor.x=577
19
+package.editor.y=61
20
+package.frame.height=600
21
+package.frame.width=800
22
+package.numDependencies=2
23
+package.numTargets=3
24
+package.showExtends=true
25
+package.showUses=true
26
+project.charset=UTF-8
27
+readme.height=58
28
+readme.name=@README
29
+readme.width=47
30
+readme.x=10
31
+readme.y=10
32
+target1.height=50
33
+target1.name=Item
34
+target1.showInterface=false
35
+target1.type=ClassTarget
36
+target1.width=80
37
+target1.x=10
38
+target1.y=100
39
+target2.height=50
40
+target2.name=InventoryTest
41
+target2.showInterface=false
42
+target2.type=UnitTestTargetJunit4
43
+target2.width=80
44
+target2.x=40
45
+target2.y=160
46
+target3.association=InventoryTest
47
+target3.height=50
48
+target3.name=Inventory
49
+target3.showInterface=false
50
+target3.type=ClassTarget
51
+target3.width=80
52
+target3.x=10
53
+target3.y=190