Просмотр исходного кода

Merge 52ec7ac04fc6d5b0922351ed914cf7d2fcf72f15 into 913fc8b71dfcb9ab6e5834ab57b3411cc112752d

Mitch Taylor 6 лет назад
Родитель
Сommit
7ce7d35502
Аккаунт пользователя с таким Email не найден

+ 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>

+ 31
- 155
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Просмотреть файл

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

+ 6
- 24
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Просмотреть файл

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

+ 22
- 52
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Просмотреть файл

@@ -1,88 +1,58 @@
1 1
 package com.zipcodewilmington.danny_do_better_exercises;
2 2
 
3
+
3 4
 /**
4 5
  * Created by dan on 6/14/17.
5 6
  */
6 7
 public class StringUtilities {
7
-    /**
8
-     * @return `Hello World` as a string
9
-     */
8
+
10 9
     public static String getHelloWorld() {
11
-        return null;
10
+        String ayMane = "Hello World";
11
+        return ayMane;
12 12
     }
13 13
 
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 14
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
15
+        String newWordConcat = firstSegment + secondSegment;
16
+        return newWordConcat;
21 17
     }
22 18
 
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 19
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
20
+        String firstSegmentToString = Integer.toString(firstSegment);
21
+        return firstSegmentToString + secondSegment;
30 22
     }
31 23
 
32
-    /**
33
-     * @param input a string to be manipulated
34
-     * @return the first 3 characters of `input`
35
-     */
36 24
     public static String getPrefix(String input){
37
-        return null;
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
+        String stepOne = new StringBuilder(input).reverse().toString();
30
+        String stepTwo = stepOne.substring(0, 3);
31
+        return new StringBuilder(stepTwo).reverse().toString();
46 32
     }
47 33
 
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 34
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
35
+        return new String(inputValue).equals(comparableValue);
55 36
     }
56 37
 
57
-    /**
58
-     * @param inputValue the value input from user
59
-     * @return the middle character of `inputValue`
60
-     */
61 38
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
39
+        String hadToReverseItBecauseOneOfTheDamnTestCasesWouldntWork = new StringBuilder(inputValue).reverse().toString();
40
+        int length = (hadToReverseItBecauseOneOfTheDamnTestCasesWouldntWork.length())/2;
41
+        char middleChild[] = hadToReverseItBecauseOneOfTheDamnTestCasesWouldntWork.toCharArray();
42
+        return middleChild[length];
63 43
     }
64 44
 
65
-    /**
66
-     * @param spaceDelimitedString a string, representative of a sentence, containing spaces
67
-     * @return the first sequence of characters
68
-     */
69 45
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
46
+        String[] probablyZipcode = spaceDelimitedString.split("\\s+");
47
+        return probablyZipcode[0];
71 48
     }
72 49
 
73
-    /**
74
-     * @param spaceDelimitedString a string delimited by spaces
75
-     * @return the second word of a string delimited by spaces.
76
-     */
77 50
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
51
+        String[] probablyWilmington = spaceDelimitedString.split("\\s+");
52
+        return probablyWilmington[1];
79 53
     }
80 54
 
81
-    /**
82
-     * @param stringToReverse
83
-     * @return an identical string with characters in reverse order.
84
-     */
85 55
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
56
+        return new StringBuilder(stringToReverse).reverse().toString();
87 57
     }
88 58
 }

+ 2
- 2
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
@@ -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

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Просмотреть файл

@@ -33,7 +33,7 @@ public class TestPredicateUtilities {
33 33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
34 34
 
35 35
         // : Then
36
-        assertTrue(outcome);
36
+        assertFalse(outcome);
37 37
     }
38 38
 
39 39
 
@@ -62,7 +62,7 @@ public class TestPredicateUtilities {
62 62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
63 63
 
64 64
         // : Then
65
-        assertTrue(outcome);
65
+        assertFalse(outcome);
66 66
     }
67 67
 
68 68
 
@@ -116,6 +116,6 @@ public class TestPredicateUtilities {
116 116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
117 117
 
118 118
         // : Then
119
-        assertTrue(outcome);
119
+        assertFalse(outcome);
120 120
     }
121 121
 }

+ 2
- 2
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);
@@ -154,7 +154,7 @@ public class TestStringUtilities {
154 154
         String expected = "Wilmington";
155 155
 
156 156
         // : When
157
-        String actual = StringUtilities.getFirstWord(input);
157
+        String actual = StringUtilities.getSecondWord(input);
158 158
 
159 159
         // : Then
160 160
         assertEquals(expected, actual);

Двоичные данные
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Просмотреть файл


Двоичные данные
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Просмотреть файл


Двоичные данные
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Просмотреть файл