Nathan Hall 6 anni fa
parent
commit
d0c2344cc1
3 ha cambiato i file con 111 aggiunte e 43 eliminazioni
  1. 43
    37
      arraz/.idea/workspace.xml
  2. 26
    2
      arraz/src/main/java/Arraz.java
  3. 42
    4
      arraz/src/test/java/ArrazTest.java

+ 43
- 37
arraz/.idea/workspace.xml Vedi File

@@ -2,12 +2,6 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="81f99a04-35ff-49d0-a7a5-4ed795a161d6" name="Default Changelist" comment="">
5
-      <change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__junit_junit_4_0.xml" afterDir="false" />
7
-      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
8
-      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
9
-      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
10
-      <change beforePath="$PROJECT_DIR$/arraz.iml" beforeDir="false" afterPath="$PROJECT_DIR$/arraz.iml" afterDir="false" />
11 5
       <change beforePath="$PROJECT_DIR$/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Arraz.java" afterDir="false" />
12 6
       <change beforePath="$PROJECT_DIR$/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ArrazTest.java" afterDir="false" />
13 7
     </list>
@@ -33,7 +27,7 @@
33 27
       </usages-collector>
34 28
       <usages-collector id="statistics.file.types.edit">
35 29
         <counts>
36
-          <entry key="JAVA" value="417" />
30
+          <entry key="JAVA" value="639" />
37 31
         </counts>
38 32
       </usages-collector>
39 33
     </session>
@@ -45,8 +39,8 @@
45 39
           <file pinned="false" current-in-tab="true">
46 40
             <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
47 41
               <provider selected="true" editor-type-id="text-editor">
48
-                <state relative-caret-position="255">
49
-                  <caret line="17" column="21" selection-start-line="17" selection-start-column="21" selection-end-line="17" selection-end-column="21" />
42
+                <state relative-caret-position="394">
43
+                  <caret line="32" column="32" selection-start-line="32" selection-start-column="32" selection-end-line="32" selection-end-column="32" />
50 44
                 </state>
51 45
               </provider>
52 46
             </entry>
@@ -58,8 +52,8 @@
58 52
           <file pinned="false" current-in-tab="true">
59 53
             <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
60 54
               <provider selected="true" editor-type-id="text-editor">
61
-                <state relative-caret-position="385">
62
-                  <caret line="44" column="24" lean-forward="true" selection-start-line="44" selection-start-column="24" selection-end-line="44" selection-end-column="24" />
55
+                <state relative-caret-position="244">
56
+                  <caret line="68" column="46" selection-start-line="68" selection-start-column="46" selection-end-line="68" selection-end-column="46" />
63 57
                   <folding>
64 58
                     <element signature="imports" expanded="true" />
65 59
                   </folding>
@@ -77,8 +71,8 @@
77 71
   <component name="IdeDocumentHistory">
78 72
     <option name="CHANGED_PATHS">
79 73
       <list>
80
-        <option value="$PROJECT_DIR$/src/test/java/ArrazTest.java" />
81 74
         <option value="$PROJECT_DIR$/src/main/java/Arraz.java" />
75
+        <option value="$PROJECT_DIR$/src/test/java/ArrazTest.java" />
82 76
       </list>
83 77
     </option>
84 78
   </component>
@@ -149,7 +143,7 @@
149 143
   <component name="PropertiesComponent">
150 144
     <property name="WebServerToolWindowFactoryState" value="false" />
151 145
     <property name="aspect.path.notification.shown" value="true" />
152
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544047288090" />
146
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544047793848" />
153 147
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
154 148
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
155 149
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
@@ -166,7 +160,7 @@
166 160
       </list>
167 161
     </option>
168 162
   </component>
169
-  <component name="RunManager" selected="JUnit.ArrazTest.test2DoublesOfArray">
163
+  <component name="RunManager" selected="JUnit.ArrazTest.test1DoubleAverageOfArray">
170 164
     <configuration name="ArrazTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
171 165
       <module name="arraz" />
172 166
       <option name="PACKAGE_NAME" value="" />
@@ -175,48 +169,60 @@
175 169
         <option name="Make" enabled="true" />
176 170
       </method>
177 171
     </configuration>
178
-    <configuration name="ArrazTest.test1sumValuesOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
172
+    <configuration name="ArrazTest.test1AverageOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
179 173
       <module name="arraz" />
180 174
       <option name="PACKAGE_NAME" value="" />
181 175
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
182
-      <option name="METHOD_NAME" value="test1sumValuesOfArray" />
176
+      <option name="METHOD_NAME" value="test1AverageOfArray" />
183 177
       <option name="TEST_OBJECT" value="method" />
184 178
       <method v="2">
185 179
         <option name="Make" enabled="true" />
186 180
       </method>
187 181
     </configuration>
188
-    <configuration name="ArrazTest.test2DoublesOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
182
+    <configuration name="ArrazTest.test1DoubleAverageOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
189 183
       <module name="arraz" />
190 184
       <option name="PACKAGE_NAME" value="" />
191 185
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
192
-      <option name="METHOD_NAME" value="test2DoublesOfArray" />
186
+      <option name="METHOD_NAME" value="test1DoubleAverageOfArray" />
187
+      <option name="TEST_OBJECT" value="method" />
188
+      <method v="2">
189
+        <option name="Make" enabled="true" />
190
+      </method>
191
+    </configuration>
192
+    <configuration name="ArrazTest.test2AverageOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
193
+      <module name="arraz" />
194
+      <option name="PACKAGE_NAME" value="" />
195
+      <option name="MAIN_CLASS_NAME" value="ArrazTest" />
196
+      <option name="METHOD_NAME" value="test2AverageOfArray" />
193 197
       <option name="TEST_OBJECT" value="method" />
194 198
       <method v="2">
195 199
         <option name="Make" enabled="true" />
196 200
       </method>
197 201
     </configuration>
198
-    <configuration name="ArrazTest.test2sumValuesOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
202
+    <configuration name="ArrazTest.test2DoublesOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
199 203
       <module name="arraz" />
200 204
       <option name="PACKAGE_NAME" value="" />
201 205
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
202
-      <option name="METHOD_NAME" value="test2sumValuesOfArray" />
206
+      <option name="METHOD_NAME" value="test2DoublesOfArray" />
203 207
       <option name="TEST_OBJECT" value="method" />
204 208
       <method v="2">
205 209
         <option name="Make" enabled="true" />
206 210
       </method>
207 211
     </configuration>
208 212
     <list>
209
-      <item itemvalue="JUnit.ArrazTest.test1sumValuesOfArray" />
210 213
       <item itemvalue="JUnit.ArrazTest" />
211
-      <item itemvalue="JUnit.ArrazTest.test2sumValuesOfArray" />
212 214
       <item itemvalue="JUnit.ArrazTest.test2DoublesOfArray" />
215
+      <item itemvalue="JUnit.ArrazTest.test1AverageOfArray" />
216
+      <item itemvalue="JUnit.ArrazTest.test2AverageOfArray" />
217
+      <item itemvalue="JUnit.ArrazTest.test1DoubleAverageOfArray" />
213 218
     </list>
214 219
     <recent_temporary>
215 220
       <list>
221
+        <item itemvalue="JUnit.ArrazTest.test1DoubleAverageOfArray" />
222
+        <item itemvalue="JUnit.ArrazTest.test2AverageOfArray" />
223
+        <item itemvalue="JUnit.ArrazTest.test1AverageOfArray" />
216 224
         <item itemvalue="JUnit.ArrazTest.test2DoublesOfArray" />
217 225
         <item itemvalue="JUnit.ArrazTest" />
218
-        <item itemvalue="JUnit.ArrazTest.test2sumValuesOfArray" />
219
-        <item itemvalue="JUnit.ArrazTest.test1sumValuesOfArray" />
220 226
       </list>
221 227
     </recent_temporary>
222 228
   </component>
@@ -230,7 +236,7 @@
230 236
       <option name="number" value="Default" />
231 237
       <option name="presentableId" value="Default" />
232 238
       <updated>1544046001151</updated>
233
-      <workItem from="1544046022231" duration="1271000" />
239
+      <workItem from="1544046022231" duration="1600000" />
234 240
     </task>
235 241
     <servers />
236 242
   </component>
@@ -267,7 +273,7 @@
267 273
     </history-entry>
268 274
   </component>
269 275
   <component name="TimeTrackingManager">
270
-    <option name="totallyTimeSpent" value="1271000" />
276
+    <option name="totallyTimeSpent" value="1600000" />
271 277
   </component>
272 278
   <component name="ToolWindowManager">
273 279
     <frame x="-236" y="-893" width="1781" height="817" extended-state="0" />
@@ -283,11 +289,11 @@
283 289
       <window_info anchor="bottom" id="Messages" weight="0.32905984" />
284 290
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
285 291
       <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
286
-      <window_info anchor="bottom" id="Terminal" />
292
+      <window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.32905984" />
287 293
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
288 294
       <window_info anchor="bottom" id="Message" order="0" />
289 295
       <window_info anchor="bottom" id="Find" order="1" />
290
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32905984" />
296
+      <window_info anchor="bottom" id="Run" order="2" weight="0.32905984" />
291 297
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
292 298
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
293 299
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -310,20 +316,20 @@
310 316
     <option name="myLimit" value="2678400000" />
311 317
   </component>
312 318
   <component name="editorHistoryManager">
313
-    <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
319
+    <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
314 320
       <provider selected="true" editor-type-id="text-editor">
315
-        <state relative-caret-position="385">
316
-          <caret line="44" column="24" lean-forward="true" selection-start-line="44" selection-start-column="24" selection-end-line="44" selection-end-column="24" />
317
-          <folding>
318
-            <element signature="imports" expanded="true" />
319
-          </folding>
321
+        <state relative-caret-position="394">
322
+          <caret line="32" column="32" selection-start-line="32" selection-start-column="32" selection-end-line="32" selection-end-column="32" />
320 323
         </state>
321 324
       </provider>
322 325
     </entry>
323
-    <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
326
+    <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
324 327
       <provider selected="true" editor-type-id="text-editor">
325
-        <state relative-caret-position="255">
326
-          <caret line="17" column="21" selection-start-line="17" selection-start-column="21" selection-end-line="17" selection-end-column="21" />
328
+        <state relative-caret-position="244">
329
+          <caret line="68" column="46" selection-start-line="68" selection-start-column="46" selection-end-line="68" selection-end-column="46" />
330
+          <folding>
331
+            <element signature="imports" expanded="true" />
332
+          </folding>
327 333
         </state>
328 334
       </provider>
329 335
     </entry>

+ 26
- 2
arraz/src/main/java/Arraz.java Vedi File

@@ -3,7 +3,7 @@ public class Arraz {
3 3
     public int sumValuesOfArray(int[] arr) {
4 4
         int sum = 0;
5 5
 
6
-        for (int i : arr){
6
+        for (int i : arr) {
7 7
             sum += i;
8 8
         }
9 9
 
@@ -14,7 +14,7 @@ public class Arraz {
14 14
     public double sumDoublesOfArray(double[] arr) {
15 15
         double sum = 0;
16 16
 
17
-        for (double d : arr){
17
+        for (double d : arr) {
18 18
             sum += d;
19 19
         }
20 20
 
@@ -23,4 +23,28 @@ public class Arraz {
23 23
     }
24 24
 
25 25
 
26
+    public int averageOfArray(int[] arr) {
27
+        int sum = 0;
28
+
29
+        for (int i : arr) {
30
+            sum += i;
31
+        }
32
+
33
+        return (sum / arr.length);
34
+    }
35
+
36
+
37
+    public double doubleAverageOfArray(double[] arr3) {
38
+
39
+        double sum = 0;
40
+
41
+        for (double i : arr3) {
42
+            sum += i;
43
+        }
44
+
45
+        return (sum / arr3.length);
46
+
47
+    }
48
+
49
+
26 50
 }

+ 42
- 4
arraz/src/test/java/ArrazTest.java Vedi File

@@ -5,12 +5,13 @@ import static org.junit.Assert.*;
5 5
 
6 6
 public class ArrazTest {
7 7
 
8
+    Arraz arraz = new Arraz();
9
+
8 10
     int[] arr = {2,2,2,2,2};
9 11
     int[] arr2 = {1,2,3,4,5};
10 12
 
11 13
     @Test
12 14
     public void test1sumValuesOfArray(){
13
-        Arraz arraz = new Arraz();
14 15
 
15 16
         int expected = 10;
16 17
         int actual = arraz.sumValuesOfArray(arr);
@@ -21,7 +22,6 @@ public class ArrazTest {
21 22
 
22 23
     @Test
23 24
     public void test2sumValuesOfArray(){
24
-        Arraz arraz = new Arraz();
25 25
 
26 26
         int expected = 15;
27 27
         int actual = arraz.sumValuesOfArray(arr2);
@@ -34,7 +34,6 @@ public class ArrazTest {
34 34
 
35 35
     @Test
36 36
     public void test1DoublesOfArray(){
37
-        Arraz arraz = new Arraz();
38 37
 
39 38
         double expected = 10.0;
40 39
         double actual = arraz.sumDoublesOfArray(arr3);
@@ -46,7 +45,6 @@ public class ArrazTest {
46 45
 
47 46
     @Test
48 47
     public void test2DoublesOfArray(){
49
-        Arraz arraz = new Arraz();
50 48
 
51 49
         double expected = 17.0;
52 50
         double actual = arraz.sumDoublesOfArray(arr4);
@@ -54,4 +52,44 @@ public class ArrazTest {
54 52
         Assert.assertEquals(expected, actual);
55 53
     }
56 54
 
55
+    @Test
56
+    public void test1AverageOfArray(){
57
+
58
+        int expected = 2;
59
+        int actual = arraz.averageOfArray(arr);
60
+
61
+        Assert.assertEquals(expected, actual);
62
+
63
+    }
64
+
65
+    @Test
66
+    public void test2AverageOfArray(){
67
+
68
+        int expected = 3;
69
+        int actual = arraz.averageOfArray(arr2);
70
+
71
+        Assert.assertEquals(expected, actual);
72
+
73
+    }
74
+
75
+    @Test
76
+    public void test1DoubleAverageOfArray(){
77
+
78
+        double expected = 2.0;
79
+        double actual = arraz.doubleAverageOfArray(arr3);
80
+
81
+        Assert.assertEquals(expected, actual);
82
+
83
+    }
84
+
85
+    @Test
86
+    public void test2DoubleAverageOfArray(){
87
+
88
+        double expected = (17 / 5);
89
+        double actual = arraz.doubleAverageOfArray(arr4);
90
+
91
+        Assert.assertEquals(expected, actual);
92
+
93
+    }
94
+
57 95
 }