Nathan Hall 6 years ago
parent
commit
d0c2344cc1
3 changed files with 111 additions and 43 deletions
  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 View File

2
 <project version="4">
2
 <project version="4">
3
   <component name="ChangeListManager">
3
   <component name="ChangeListManager">
4
     <list default="true" id="81f99a04-35ff-49d0-a7a5-4ed795a161d6" name="Default Changelist" comment="">
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
       <change beforePath="$PROJECT_DIR$/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Arraz.java" afterDir="false" />
5
       <change beforePath="$PROJECT_DIR$/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Arraz.java" afterDir="false" />
12
       <change beforePath="$PROJECT_DIR$/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ArrazTest.java" afterDir="false" />
6
       <change beforePath="$PROJECT_DIR$/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ArrazTest.java" afterDir="false" />
13
     </list>
7
     </list>
33
       </usages-collector>
27
       </usages-collector>
34
       <usages-collector id="statistics.file.types.edit">
28
       <usages-collector id="statistics.file.types.edit">
35
         <counts>
29
         <counts>
36
-          <entry key="JAVA" value="417" />
30
+          <entry key="JAVA" value="639" />
37
         </counts>
31
         </counts>
38
       </usages-collector>
32
       </usages-collector>
39
     </session>
33
     </session>
45
           <file pinned="false" current-in-tab="true">
39
           <file pinned="false" current-in-tab="true">
46
             <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
40
             <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
47
               <provider selected="true" editor-type-id="text-editor">
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
                 </state>
44
                 </state>
51
               </provider>
45
               </provider>
52
             </entry>
46
             </entry>
58
           <file pinned="false" current-in-tab="true">
52
           <file pinned="false" current-in-tab="true">
59
             <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
53
             <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
60
               <provider selected="true" editor-type-id="text-editor">
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
                   <folding>
57
                   <folding>
64
                     <element signature="imports" expanded="true" />
58
                     <element signature="imports" expanded="true" />
65
                   </folding>
59
                   </folding>
77
   <component name="IdeDocumentHistory">
71
   <component name="IdeDocumentHistory">
78
     <option name="CHANGED_PATHS">
72
     <option name="CHANGED_PATHS">
79
       <list>
73
       <list>
80
-        <option value="$PROJECT_DIR$/src/test/java/ArrazTest.java" />
81
         <option value="$PROJECT_DIR$/src/main/java/Arraz.java" />
74
         <option value="$PROJECT_DIR$/src/main/java/Arraz.java" />
75
+        <option value="$PROJECT_DIR$/src/test/java/ArrazTest.java" />
82
       </list>
76
       </list>
83
     </option>
77
     </option>
84
   </component>
78
   </component>
149
   <component name="PropertiesComponent">
143
   <component name="PropertiesComponent">
150
     <property name="WebServerToolWindowFactoryState" value="false" />
144
     <property name="WebServerToolWindowFactoryState" value="false" />
151
     <property name="aspect.path.notification.shown" value="true" />
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
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
147
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
154
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
148
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
155
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
149
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
166
       </list>
160
       </list>
167
     </option>
161
     </option>
168
   </component>
162
   </component>
169
-  <component name="RunManager" selected="JUnit.ArrazTest.test2DoublesOfArray">
163
+  <component name="RunManager" selected="JUnit.ArrazTest.test1DoubleAverageOfArray">
170
     <configuration name="ArrazTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
164
     <configuration name="ArrazTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
171
       <module name="arraz" />
165
       <module name="arraz" />
172
       <option name="PACKAGE_NAME" value="" />
166
       <option name="PACKAGE_NAME" value="" />
175
         <option name="Make" enabled="true" />
169
         <option name="Make" enabled="true" />
176
       </method>
170
       </method>
177
     </configuration>
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
       <module name="arraz" />
173
       <module name="arraz" />
180
       <option name="PACKAGE_NAME" value="" />
174
       <option name="PACKAGE_NAME" value="" />
181
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
175
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
182
-      <option name="METHOD_NAME" value="test1sumValuesOfArray" />
176
+      <option name="METHOD_NAME" value="test1AverageOfArray" />
183
       <option name="TEST_OBJECT" value="method" />
177
       <option name="TEST_OBJECT" value="method" />
184
       <method v="2">
178
       <method v="2">
185
         <option name="Make" enabled="true" />
179
         <option name="Make" enabled="true" />
186
       </method>
180
       </method>
187
     </configuration>
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
       <module name="arraz" />
183
       <module name="arraz" />
190
       <option name="PACKAGE_NAME" value="" />
184
       <option name="PACKAGE_NAME" value="" />
191
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
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
       <option name="TEST_OBJECT" value="method" />
197
       <option name="TEST_OBJECT" value="method" />
194
       <method v="2">
198
       <method v="2">
195
         <option name="Make" enabled="true" />
199
         <option name="Make" enabled="true" />
196
       </method>
200
       </method>
197
     </configuration>
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
       <module name="arraz" />
203
       <module name="arraz" />
200
       <option name="PACKAGE_NAME" value="" />
204
       <option name="PACKAGE_NAME" value="" />
201
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
205
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
202
-      <option name="METHOD_NAME" value="test2sumValuesOfArray" />
206
+      <option name="METHOD_NAME" value="test2DoublesOfArray" />
203
       <option name="TEST_OBJECT" value="method" />
207
       <option name="TEST_OBJECT" value="method" />
204
       <method v="2">
208
       <method v="2">
205
         <option name="Make" enabled="true" />
209
         <option name="Make" enabled="true" />
206
       </method>
210
       </method>
207
     </configuration>
211
     </configuration>
208
     <list>
212
     <list>
209
-      <item itemvalue="JUnit.ArrazTest.test1sumValuesOfArray" />
210
       <item itemvalue="JUnit.ArrazTest" />
213
       <item itemvalue="JUnit.ArrazTest" />
211
-      <item itemvalue="JUnit.ArrazTest.test2sumValuesOfArray" />
212
       <item itemvalue="JUnit.ArrazTest.test2DoublesOfArray" />
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
     </list>
218
     </list>
214
     <recent_temporary>
219
     <recent_temporary>
215
       <list>
220
       <list>
221
+        <item itemvalue="JUnit.ArrazTest.test1DoubleAverageOfArray" />
222
+        <item itemvalue="JUnit.ArrazTest.test2AverageOfArray" />
223
+        <item itemvalue="JUnit.ArrazTest.test1AverageOfArray" />
216
         <item itemvalue="JUnit.ArrazTest.test2DoublesOfArray" />
224
         <item itemvalue="JUnit.ArrazTest.test2DoublesOfArray" />
217
         <item itemvalue="JUnit.ArrazTest" />
225
         <item itemvalue="JUnit.ArrazTest" />
218
-        <item itemvalue="JUnit.ArrazTest.test2sumValuesOfArray" />
219
-        <item itemvalue="JUnit.ArrazTest.test1sumValuesOfArray" />
220
       </list>
226
       </list>
221
     </recent_temporary>
227
     </recent_temporary>
222
   </component>
228
   </component>
230
       <option name="number" value="Default" />
236
       <option name="number" value="Default" />
231
       <option name="presentableId" value="Default" />
237
       <option name="presentableId" value="Default" />
232
       <updated>1544046001151</updated>
238
       <updated>1544046001151</updated>
233
-      <workItem from="1544046022231" duration="1271000" />
239
+      <workItem from="1544046022231" duration="1600000" />
234
     </task>
240
     </task>
235
     <servers />
241
     <servers />
236
   </component>
242
   </component>
267
     </history-entry>
273
     </history-entry>
268
   </component>
274
   </component>
269
   <component name="TimeTrackingManager">
275
   <component name="TimeTrackingManager">
270
-    <option name="totallyTimeSpent" value="1271000" />
276
+    <option name="totallyTimeSpent" value="1600000" />
271
   </component>
277
   </component>
272
   <component name="ToolWindowManager">
278
   <component name="ToolWindowManager">
273
     <frame x="-236" y="-893" width="1781" height="817" extended-state="0" />
279
     <frame x="-236" y="-893" width="1781" height="817" extended-state="0" />
283
       <window_info anchor="bottom" id="Messages" weight="0.32905984" />
289
       <window_info anchor="bottom" id="Messages" weight="0.32905984" />
284
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
290
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
285
       <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
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
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
293
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
288
       <window_info anchor="bottom" id="Message" order="0" />
294
       <window_info anchor="bottom" id="Message" order="0" />
289
       <window_info anchor="bottom" id="Find" order="1" />
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
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
297
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
292
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
298
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
293
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
299
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
310
     <option name="myLimit" value="2678400000" />
316
     <option name="myLimit" value="2678400000" />
311
   </component>
317
   </component>
312
   <component name="editorHistoryManager">
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
       <provider selected="true" editor-type-id="text-editor">
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
         </state>
323
         </state>
321
       </provider>
324
       </provider>
322
     </entry>
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
       <provider selected="true" editor-type-id="text-editor">
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
         </state>
333
         </state>
328
       </provider>
334
       </provider>
329
     </entry>
335
     </entry>

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

3
     public int sumValuesOfArray(int[] arr) {
3
     public int sumValuesOfArray(int[] arr) {
4
         int sum = 0;
4
         int sum = 0;
5
 
5
 
6
-        for (int i : arr){
6
+        for (int i : arr) {
7
             sum += i;
7
             sum += i;
8
         }
8
         }
9
 
9
 
14
     public double sumDoublesOfArray(double[] arr) {
14
     public double sumDoublesOfArray(double[] arr) {
15
         double sum = 0;
15
         double sum = 0;
16
 
16
 
17
-        for (double d : arr){
17
+        for (double d : arr) {
18
             sum += d;
18
             sum += d;
19
         }
19
         }
20
 
20
 
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 View File

5
 
5
 
6
 public class ArrazTest {
6
 public class ArrazTest {
7
 
7
 
8
+    Arraz arraz = new Arraz();
9
+
8
     int[] arr = {2,2,2,2,2};
10
     int[] arr = {2,2,2,2,2};
9
     int[] arr2 = {1,2,3,4,5};
11
     int[] arr2 = {1,2,3,4,5};
10
 
12
 
11
     @Test
13
     @Test
12
     public void test1sumValuesOfArray(){
14
     public void test1sumValuesOfArray(){
13
-        Arraz arraz = new Arraz();
14
 
15
 
15
         int expected = 10;
16
         int expected = 10;
16
         int actual = arraz.sumValuesOfArray(arr);
17
         int actual = arraz.sumValuesOfArray(arr);
21
 
22
 
22
     @Test
23
     @Test
23
     public void test2sumValuesOfArray(){
24
     public void test2sumValuesOfArray(){
24
-        Arraz arraz = new Arraz();
25
 
25
 
26
         int expected = 15;
26
         int expected = 15;
27
         int actual = arraz.sumValuesOfArray(arr2);
27
         int actual = arraz.sumValuesOfArray(arr2);
34
 
34
 
35
     @Test
35
     @Test
36
     public void test1DoublesOfArray(){
36
     public void test1DoublesOfArray(){
37
-        Arraz arraz = new Arraz();
38
 
37
 
39
         double expected = 10.0;
38
         double expected = 10.0;
40
         double actual = arraz.sumDoublesOfArray(arr3);
39
         double actual = arraz.sumDoublesOfArray(arr3);
46
 
45
 
47
     @Test
46
     @Test
48
     public void test2DoublesOfArray(){
47
     public void test2DoublesOfArray(){
49
-        Arraz arraz = new Arraz();
50
 
48
 
51
         double expected = 17.0;
49
         double expected = 17.0;
52
         double actual = arraz.sumDoublesOfArray(arr4);
50
         double actual = arraz.sumDoublesOfArray(arr4);
54
         Assert.assertEquals(expected, actual);
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
 }