Sfoglia il codice sorgente

commit 1 after doubleAverageOfArray

Nick Satinover 6 anni fa
parent
commit
725d98ec70

+ 16
- 0
arraz/.idea/compiler.xml Vedi File

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="arraz" />
10
+      </profile>
11
+    </annotationProcessing>
12
+    <bytecodeTargetLevel>
13
+      <module name="arraz" target="1.5" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
arraz/.idea/libraries/Maven__junit_junit_4_0.xml Vedi File

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.0">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
arraz/.idea/misc.xml Vedi File

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
arraz/.idea/modules.xml Vedi File

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/arraz.iml" filepath="$PROJECT_DIR$/arraz.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
arraz/.idea/vcs.xml Vedi File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+  </component>
6
+</project>

+ 1
- 2
arraz/arraz.iml Vedi File

@@ -5,11 +5,10 @@
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
7 7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9 8
       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10 9
       <excludeFolder url="file://$MODULE_DIR$/target" />
11 10
     </content>
12
-    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
11
+    <orderEntry type="inheritedJdk" />
13 12
     <orderEntry type="sourceFolder" forTests="false" />
14 13
     <orderEntry type="library" name="Maven: junit:junit:4.0" level="project" />
15 14
   </component>

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

@@ -1,2 +1,28 @@
1 1
 public class Arraz {
2
+
3
+    public int sumValuesOfArray(int[] intArr){
4
+        int sum = 0;
5
+        for (int i:intArr) {
6
+            sum += i;
7
+        }
8
+        return sum;
9
+    }
10
+
11
+    public double sumDoublesOfArray(double[] doublesArr){
12
+        double sum = 0;
13
+        for (double i:doublesArr) {
14
+            sum += i;
15
+        }
16
+        return sum;
17
+    }
18
+
19
+    public int averageOfArray(int[] intArr){
20
+        int sum = sumValuesOfArray(intArr);
21
+        return sum / intArr.length;
22
+    }
23
+
24
+    public double doubleAverageOfArray(double[] doublesArr){
25
+        double sum = sumDoublesOfArray(doublesArr);
26
+        return sum / doublesArr.length;
27
+    }
2 28
 }

+ 113
- 0
arraz/src/test/java/ArrazTest.java Vedi File

@@ -1,5 +1,118 @@
1
+import org.junit.Assert;
2
+import org.junit.Before;
3
+import org.junit.Test;
4
+
1 5
 import static org.junit.Assert.*;
2 6
 
3 7
 public class ArrazTest {
8
+    Arraz arraz = new Arraz();
9
+
10
+    @Before
11
+    public void setUp(){
12
+
13
+    }
14
+
15
+    @Test
16
+    public void test1sumValuesOfArray(){
17
+        //GIVEN
18
+        int[] arr = {1, 2, 3, 4, 5};
19
+
20
+        //WHEN
21
+        int expected = 15;
22
+        int actual = arraz.sumValuesOfArray(arr);
23
+
24
+        //THEN
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void test2sumValuesOfArray(){
30
+        //GIVEN
31
+        int[] arr = {1, 2, 3, 4, 5, 100};
32
+
33
+        //WHEN
34
+        int expected = 115;
35
+        int actual = arraz.sumValuesOfArray(arr);
36
+
37
+        //THEN
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void test1sumDoublesOfArray(){
43
+        //GIVEN
44
+        double[] arr = {1, 2, 3, 4, 5.5};
45
+
46
+        //WHEN
47
+        double expected = 15.5;
48
+        double actual = arraz.sumDoublesOfArray(arr);
49
+
50
+        //THEN
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void test2sumDoublesOfArray(){
56
+        //GIVEN
57
+        double[] arr = {1.999, 2, 3, 4, 5, 100};
58
+
59
+        //WHEN
60
+        double expected = 115.999;
61
+        double actual = arraz.sumDoublesOfArray(arr);
62
+
63
+        //THEN
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void test1averageOfArray(){
69
+        //GIVEN
70
+        int[] arr = {1, 2, 3, 4, 5};
71
+
72
+        //WHEN
73
+        int expected = 3;
74
+        int actual = arraz.averageOfArray(arr);
75
+
76
+        //THEN
77
+        Assert.assertEquals(expected, actual);
78
+    }
79
+
80
+    @Test
81
+    public void test2averageOfArray(){
82
+        //GIVEN
83
+        int[] arr = {1, 2, 3, 4, 5, 6};
84
+
85
+        //WHEN
86
+        int expected = 3;
87
+        int actual = arraz.averageOfArray(arr);
88
+
89
+        //THEN
90
+        Assert.assertEquals(expected, actual);
91
+    }
92
+
93
+    @Test
94
+    public void test1doubleAverageOfArray(){
95
+        //GIVEN
96
+        double[] arr = {.75, 2, 3, 4, 5.25};
97
+
98
+        //WHEN
99
+        double expected = 3;
100
+        double actual = arraz.doubleAverageOfArray(arr);
101
+
102
+        //THEN
103
+        Assert.assertEquals(expected, actual);
104
+    }
105
+
106
+    @Test
107
+    public void test2doubleAverageOfArray(){
108
+        //GIVEN
109
+        double[] arr = {.001, 2, 3.141, 4, 5, 6.999};
110
+
111
+        //WHEN
112
+        double expected = 3.5235;
113
+        double actual = arraz.doubleAverageOfArray(arr);
4 114
 
115
+        //THEN
116
+        Assert.assertEquals(expected, actual);
117
+    }
5 118
 }