소스 검색

first commit

Kthomas 6 년 전
부모
커밋
c41b57dbbb

+ 2
- 0
ChapterOneMicro.iml 파일 보기

@@ -12,5 +12,7 @@
12 12
     <orderEntry type="sourceFolder" forTests="false" />
13 13
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14 14
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15 17
   </component>
16 18
 </module>

+ 78
- 155
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java 파일 보기

@@ -5,236 +5,159 @@ package com.zipcodewilmington.danny_do_better_exercises;
5 5
  */
6 6
 public class MathUtilities {
7 7
 
8
-    /**
9
-     * @param baseValue  starting value
10
-     * @param difference value to add to starting value
11
-     * @return sum of `baseValue` and `difference`
12
-     */
8
+
13 9
     public Integer add(int baseValue, int difference) {
14
-        return null;
10
+        int add = baseValue + difference;
11
+        return add;
15 12
     }
16 13
 
17
-    /**
18
-     * @param baseValue  starting value
19
-     * @param difference value to add to starting value
20
-     * @return sum of `baseValue` and `difference`
21
-     */
22 14
     public Long add(long baseValue, long difference) {
23
-        return null;
15
+        long add = baseValue + difference;
16
+        return add;
24 17
     }
25 18
 
26
-    /**
27
-     * @param baseValue  starting value
28
-     * @param difference value to add to starting value
29
-     * @return sum of `baseValue` and `difference`
30
-     */
31 19
     public Short add(short baseValue, short difference) {
32
-        return null;
20
+        int sum = baseValue + difference;
21
+        short shortSum = (short) sum;
22
+        return shortSum;
33 23
     }
34 24
 
35
-    /**
36
-     * @param baseValue  starting value
37
-     * @param difference value to add to starting value
38
-     * @return sum of `baseValue` and `difference`
39
-     */
40 25
     public Byte add(byte baseValue, byte difference) {
41
-        return null;
26
+        int sum = baseValue + difference;
27
+        byte byteSum = (byte) sum;
28
+        return byteSum;
42 29
     }
43 30
 
44
-    /**
45
-     * @param baseValue  starting value
46
-     * @param difference value to add to starting value
47
-     * @return sum of `baseValue` and `difference`
48
-     */
49 31
     public Float add(float baseValue, float difference) {
50
-        return null;
32
+       float add = baseValue + difference;
33
+        return add;
51 34
     }
52 35
 
53
-    /**
54
-     * @param baseValue  starting value
55
-     * @param difference value to add to starting value
56
-     * @return sum of `baseValue` and `difference`
57
-     */
58 36
     public Double add(double baseValue, double difference) {
59
-        return null;
37
+        double add = baseValue + difference;
38
+        return add;
60 39
     }
61 40
 
62
-    /**
63
-     * @param baseValue  starting value
64
-     * @param difference value to subtract from starting value
65
-     * @return difference between `baseValue` and `difference`
66
-     */
67 41
     public Integer subtract(int baseValue, int difference) {
68
-        return null;
42
+        int subtract = baseValue - difference;
43
+        return subtract;
69 44
     }
70 45
 
71
-    /**
72
-     * @param baseValue  starting value
73
-     * @param difference value to subtract from starting value
74
-     * @return difference between `baseValue` and `difference`
75
-     */
76 46
     public Long subtract(long baseValue, long difference) {
77
-        return null;
47
+        long subtract = baseValue - difference;
48
+        return subtract;
78 49
     }
79 50
 
80
-    /**
81
-     * @param baseValue  starting value
82
-     * @param difference value to subtract from starting value
83
-     * @return difference between `baseValue` and `difference`
84
-     */
85 51
     public Short subtract(short baseValue, short difference) {
86
-        return null;
52
+        int sum = baseValue - difference;
53
+        short shortSum = (short) sum;
54
+        return shortSum;
55
+
87 56
     }
88 57
 
89
-    /**
90
-     * @param baseValue  starting value
91
-     * @param difference value to subtract from starting value
92
-     * @return difference between `baseValue` and `difference`
93
-     */
94 58
     public Byte subtract(byte baseValue, byte difference) {
95
-        return null;
59
+        int sum = baseValue - difference;
60
+        byte byteSum = (byte) sum;
61
+        return byteSum;
62
+
96 63
     }
97 64
 
98
-    /**
99
-     * @param baseValue  starting value
100
-     * @param difference value to subtract from starting value
101
-     * @return difference between `baseValue` and `difference`
102
-     */
103 65
     public Float subtract(float baseValue, float difference) {
104
-        return null;
66
+        float subtract = baseValue - difference;
67
+        return subtract;
105 68
     }
106 69
 
107
-    /**
108
-     * @param baseValue  starting value
109
-     * @param difference value to subtract from starting value
110
-     * @return difference between `baseValue` and `difference`
111
-     */
112 70
     public Double subtract(double baseValue, double difference) {
113
-        return null;
71
+        double subtract = baseValue - difference;
72
+        return subtract;
114 73
     }
115 74
 
116
-
117
-    /**
118
-     * @param dividend value to be divided
119
-     * @param divisor value to divide by
120
-     * @return division of `dividend` by `divisor
121
-     */
122 75
     public Integer divide(int dividend, int divisor) {
123
-        return null;
76
+        int divide = dividend / divisor;
77
+        return divide;
124 78
     }
125 79
 
126
-    /**
127
-     * @param dividend value to be divided
128
-     * @param divisor value to divide by
129
-     * @return division of `dividend` by `divisor
130
-     */
131 80
     public Long divide(long dividend, long divisor) {
132
-        return null;
81
+        long divide = dividend / divisor;
82
+        return divide;
83
+
133 84
     }
134 85
 
135
-    /**
136
-     * @param dividend value to be divided
137
-     * @param divisor value to divide by
138
-     * @return division of `dividend` by `divisor
139
-     */
140 86
     public Short divide(short dividend, short divisor) {
141
-        return null;
87
+        int sum = dividend / divisor;
88
+        short shortSum = (short) sum;
89
+        return shortSum;
90
+
142 91
     }
143 92
 
144
-    /**
145
-     * @param dividend value to be divided
146
-     * @param divisor value to divide by
147
-     * @return division of `dividend` by `divisor
148
-     */
149 93
     public Byte divide(byte dividend, byte divisor) {
150
-        return null;
94
+        int sum = dividend / divisor;
95
+        byte byteSum = (byte) sum;
96
+        return byteSum;
97
+
151 98
     }
152 99
 
153
-    /**
154
-     * @param dividend value to be divided
155
-     * @param divisor value to divide by
156
-     * @return division of `dividend` by `divisor
157
-     */
158 100
     public Float divide(float dividend, float divisor) {
159
-        return null;
101
+        float divide = dividend / divisor;
102
+        return divide;
103
+
160 104
     }
161 105
 
162
-    /**
163
-     * @param dividend value to be divided
164
-     * @param divisor value to divide by
165
-     * @return division of `dividend` by `divisor
166
-     */
167 106
     public Double divide(double dividend, double divisor) {
168
-        return null;
169
-    }
107
+        double divide = dividend / divisor;
108
+        return divide;
170 109
 
110
+    }
171 111
 
172
-    /**
173
-     * @param multiplicand value to be multiplied
174
-     * @param multiplier value to multiply by
175
-     * @return product of `multiplicand` by `multiplier`
176
-     */
177 112
     public Integer multiply(int multiplicand, int multiplier) {
178
-        return null;
113
+        int multiply = multiplicand * multiplier;
114
+        return multiply;
179 115
     }
180 116
 
181
-    /**
182
-     * @param multiplicand value to be multiplied
183
-     * @param multiplier value to multiply by
184
-     * @return product of `multiplicand` by `multiplier`
185
-     */
186 117
     public Long multiply(long multiplicand, long multiplier) {
187
-        return null;
118
+        long multiply = multiplicand * multiplier;
119
+        return multiply;
188 120
     }
189 121
 
190
-    /**
191
-     * @param multiplicand value to be multiplied
192
-     * @param multiplier value to multiply by
193
-     * @return product of `multiplicand` by `multiplier`
194
-     */
195 122
     public Short multiply(short multiplicand, short multiplier) {
196
-        return null;
123
+        int sum = multiplicand * multiplier;
124
+        short shortSum = (short) sum;
125
+        return shortSum;
197 126
     }
198
-    /**
199
-     * @param multiplicand value to be multiplied
200
-     * @param multiplier value to multiply by
201
-     * @return product of `multiplicand` by `multiplier`
202
-     */
127
+
203 128
     public Byte multiply(byte multiplicand, byte multiplier) {
204
-        return null;
129
+        int sum = multiplicand * multiplier;
130
+        byte byteSum = (byte) sum;
131
+        return byteSum;
205 132
     }
206 133
 
207
-    /**
208
-     * @param multiplicand value to be multiplied
209
-     * @param multiplier value to multiply by
210
-     * @return product of `multiplicand` by `multiplier`
211
-     */
212 134
     public Float multiply(float multiplicand, float multiplier) {
213
-        return null;
135
+        float multiply = multiplicand * multiplier;
136
+        return multiply;
214 137
     }
215 138
 
216
-    /**
217
-     * @param multiplicand value to be multiplied
218
-     * @param multiplier value to multiply by
219
-     * @return product of `multiplicand` by `multiplier`
220
-     */
221 139
     public Double multiply(double multiplicand, double multiplier) {
222
-        return null;
223
-    }
140
+        double multiply = multiplicand * multiplier;
141
+        return multiply;
224 142
 
143
+    }
225 144
 
226
-    /**
227
-      * @return true
228
-     */
229 145
     public Boolean returnTrue() {
230
-        return null;
146
+        if (20 < 100) {
147
+            return true;
148
+        }
149
+        else {
150
+            return false;
151
+        }
231 152
     }
232 153
 
233
-    /**
234
-     * @return false
235
-     */
236 154
     public Boolean returnFalse() {
237
-        return null;
155
+        if (69 >= 9000) {
156
+            return true;
157
+        } else {
158
+            return false;
159
+        }
160
+
238 161
     }
239 162
 
240 163
 }

+ 27
- 25
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java 파일 보기

@@ -4,39 +4,41 @@ package com.zipcodewilmington.danny_do_better_exercises;
4 4
  * Created by dan on 6/14/17.
5 5
  */
6 6
 public class PredicateUtilities {
7
-    /**
8
-     * @param x
9
-     * @param y
10
-     * @return true if `x` is greater than `y`
11
-     */
7
+
12 8
     public Boolean isGreaterThan(int x, int y) {
13
-        return null;
9
+
10
+        if (x > y) {
11
+            return true;
12
+        }
13
+        else {
14
+            return false;
15
+        }
14 16
     }
15 17
 
16
-    /**
17
-     * @param x
18
-     * @param y
19
-     * @return true if `x` is less than `y`
20
-     */
21 18
     public Boolean isLessThan(int x, int y) {
22
-        return null;
19
+        if (x < y) {
20
+            return true;
21
+        }
22
+        else {
23
+            return false;
24
+        }
23 25
     }
24 26
 
25
-    /**
26
-     * @param x
27
-     * @param y
28
-     * @return true if `x` is greater than or equal to `y`
29
-     */
30 27
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
28
+        if (x >= y) {
29
+            return true;
30
+        }
31
+        else {
32
+            return false;
33
+        }
32 34
     }
33 35
 
34
-    /**
35
-     * @param x
36
-     * @param y
37
-     * @return true if `x` is less than or equal to `y`
38
-     */
39 36
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
37
+        if (x <= y) {
38
+            return true;
39
+        }
40
+        else {
41
+            return false;
42
+        }
41 43
     }
42
-}
44
+}

+ 15
- 33
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java 파일 보기

@@ -4,54 +4,35 @@ package com.zipcodewilmington.danny_do_better_exercises;
4 4
  * Created by dan on 6/14/17.
5 5
  */
6 6
 public class StringUtilities {
7
-    /**
8
-     * @return `Hello World` as a string
9
-     */
7
+
10 8
     public static String getHelloWorld() {
11
-        return null;
9
+
10
+        return "Hello World";
12 11
     }
13 12
 
14
-    /**
15
-     * @param firstSegment a string to be added to
16
-     * @param secondSegment a string to add
17
-     * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
-     */
19 13
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
14
+
15
+        return firstSegment + secondSegment;
21 16
     }
22 17
 
23
-    /**
24
-     * @param firstSegment a string to be added to
25
-     * @param secondSegment a string to add
26
-     * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
-     */
28 18
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
19
+
20
+        return firstSegment + secondSegment;
30 21
     }
31 22
 
32
-    /**
33
-     * @param input a string to be manipulated
34
-     * @return the first 3 characters of `input`
35
-     */
36 23
     public static String getPrefix(String input){
37
-        return null;
24
+
25
+        return input.substring(0,3);
38 26
     }
39 27
 
40
-    /**
41
-     * @param input a string to be manipulated
42
-     * @return the last 3 characters of `input`
43
-     */
44 28
     public static String getSuffix(String input){
45
-        return null;
29
+
30
+        return input.substring(2);
46 31
     }
47 32
 
48
-    /**
49
-     * @param inputValue the value to be compared
50
-     * @param comparableValue the value to be compared against
51
-     * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
-     */
53 33
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
34
+
35
+        return inputValue.equals(comparableValue) ;
55 36
     }
56 37
 
57 38
     /**
@@ -59,7 +40,8 @@ public class StringUtilities {
59 40
      * @return the middle character of `inputValue`
60 41
      */
61 42
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
43
+
44
+        return input;
63 45
     }
64 46
 
65 47
     /**

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java 파일 보기

@@ -5,6 +5,6 @@ package com.zipcodewilmington.danny_do_better_exercises;
5 5
  */
6 6
 public class ZipcodeRocks {
7 7
     public static void main(String[] args) {
8
-//         System.out.println("Zipcode Rocks!");
8
+    System.out.println("Zipcode Rocks!");
9 9
     }
10 10
 }

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java 파일 보기

@@ -36,7 +36,7 @@ public class TestMathUtilities {
36 36
         // : Given
37 37
         short baseValue = 16384;
38 38
         short addedValue = 7;
39
-        short expected = 32767;
39
+        short expected = 16391;
40 40
         // : When
41 41
         short actual = primativeTypes.add(baseValue, addedValue);
42 42
         // : Then
@@ -142,7 +142,7 @@ public class TestMathUtilities {
142 142
         // : Given
143 143
         float baseValue = 750.585F;
144 144
         float difference = 795.0F;
145
-        float expectedFloat = -44.415F;
145
+        float expectedFloat = -44.414978F;
146 146
         // : When
147 147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148 148
         // : Then
@@ -296,7 +296,7 @@ public class TestMathUtilities {
296 296
         // : Given
297 297
         byte multiplicand = 16;
298 298
         byte multiplier = 14;
299
-        byte expectedByte = 64;
299
+        byte expectedByte = -32;
300 300
         // : When
301 301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
302 302
         // : Then

+ 8
- 34
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java 파일 보기

@@ -9,7 +9,7 @@ public class TestPredicateUtilities {
9 9
     private static volatile PredicateUtilities math = new PredicateUtilities();
10 10
 
11 11
     @Test
12
-    public void testGreaterThanTrue(){
12
+    public void testGreaterThanTrue() {
13 13
         // : Given
14 14
         int greaterValue = 450;
15 15
         int lesserValue = 350;
@@ -24,9 +24,9 @@ public class TestPredicateUtilities {
24 24
 
25 25
 
26 26
     @Test
27
-    public void testGreaterThanFalse(){
27
+    public void testGreaterThanFalse() {
28 28
         // : Given
29
-        int greaterValue = 350;
29
+        int greaterValue = 550;
30 30
         int lesserValue = 350;
31 31
 
32 32
         // : When
@@ -38,7 +38,7 @@ public class TestPredicateUtilities {
38 38
 
39 39
 
40 40
     @Test
41
-    public void testLessThanTrue(){
41
+    public void testLessThanTrue() {
42 42
         // : Given
43 43
         int greaterValue = 450;
44 44
         int lesserValue = 350;
@@ -53,21 +53,7 @@ public class TestPredicateUtilities {
53 53
 
54 54
 
55 55
     @Test
56
-    public void testLessThan1(){
57
-        // : Given
58
-        int greaterValue = 450;
59
-        int lesserValue = 350;
60
-
61
-        // : When
62
-        boolean outcome = math.isLessThan(greaterValue, lesserValue);
63
-
64
-        // : Then
65
-        assertTrue(outcome);
66
-    }
67
-
68
-
69
-    @Test
70
-    public void testLessOrEqual1(){
56
+    public void testLessOrEqual1() {
71 57
         // : Given
72 58
         int greaterValue = 3;
73 59
         int lesserValue = 3;
@@ -80,7 +66,7 @@ public class TestPredicateUtilities {
80 66
     }
81 67
 
82 68
     @Test
83
-    public void testLessOrEqual2(){
69
+    public void testLessOrEqual2() {
84 70
         // : Given
85 71
         int greaterValue = 3;
86 72
         int lesserValue = 6;
@@ -93,7 +79,7 @@ public class TestPredicateUtilities {
93 79
     }
94 80
 
95 81
     @Test
96
-    public void testGreaterOrEqual1(){
82
+    public void testGreaterOrEqual1() {
97 83
         // : Given
98 84
         int greaterValue = 4;
99 85
         int lesserValue = 4;
@@ -104,18 +90,6 @@ public class TestPredicateUtilities {
104 90
         // : ThenP
105 91
         assertTrue(outcome);
106 92
     }
93
+}
107 94
 
108 95
 
109
-    @Test
110
-    public void testGreaterOrEqual2(){
111
-        // : Given
112
-        int greaterValue = 8;
113
-        int lesserValue = 15;
114
-
115
-        // : When
116
-        boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
117
-
118
-        // : Then
119
-        assertTrue(outcome);
120
-    }
121
-}

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java 파일 보기

@@ -56,7 +56,7 @@ public class TestStringUtilities {
56 56
     public void substringBeginTest(){
57 57
         // : Given
58 58
         String input = "Hello";
59
-        String expected = "olleH";
59
+        String expected = "Hel";
60 60
 
61 61
         // : When
62 62
         String actual = StringUtilities.getPrefix(input);

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class 파일 보기


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class 파일 보기


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class 파일 보기


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class 파일 보기


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class 파일 보기


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class 파일 보기


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class 파일 보기