Explorar el Código

first commit finally

April Rivera hace 6 años
padre
commit
dc946fb481

+ 6
- 0
ChapterOneMicro.iml Ver fichero

@@ -12,5 +12,11 @@
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" />
17
+    <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.1.0-RC1" level="project" />
18
+    <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
19
+    <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.0.0" level="project" />
20
+    <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.1.0-RC1" level="project" />
15 21
   </component>
16 22
 </module>

+ 5
- 0
pom.xml Ver fichero

@@ -15,6 +15,11 @@
15 15
             <version>4.12</version>
16 16
             <scope>test</scope>
17 17
         </dependency>
18
+        <dependency>
19
+            <groupId>org.junit.jupiter</groupId>
20
+            <artifactId>junit-jupiter-api</artifactId>
21
+            <version>RELEASE</version>
22
+        </dependency>
18 23
     </dependencies>
19 24
 
20 25
     <build>

+ 31
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Ver fichero

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

+ 4
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Ver fichero

@@ -10,7 +10,7 @@ public class PredicateUtilities {
10 10
      * @return true if `x` is greater than `y`
11 11
      */
12 12
     public Boolean isGreaterThan(int x, int y) {
13
-        return null;
13
+        return x > y;
14 14
     }
15 15
 
16 16
     /**
@@ -19,7 +19,7 @@ public class PredicateUtilities {
19 19
      * @return true if `x` is less than `y`
20 20
      */
21 21
     public Boolean isLessThan(int x, int y) {
22
-        return null;
22
+        return x < y;
23 23
     }
24 24
 
25 25
     /**
@@ -28,7 +28,7 @@ public class PredicateUtilities {
28 28
      * @return true if `x` is greater than or equal to `y`
29 29
      */
30 30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
31
+        return x >= y;
32 32
     }
33 33
 
34 34
     /**
@@ -37,6 +37,6 @@ public class PredicateUtilities {
37 37
      * @return true if `x` is less than or equal to `y`
38 38
      */
39 39
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
40
+        return x <= y;
41 41
     }
42 42
 }

+ 17
- 11
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Ver fichero

@@ -8,16 +8,16 @@ public class StringUtilities {
8 8
      * @return `Hello World` as a string
9 9
      */
10 10
     public static String getHelloWorld() {
11
-        return null;
11
+        return "Hello World";
12 12
     }
13
-
14 13
     /**
15 14
      * @param firstSegment a string to be added to
16 15
      * @param secondSegment a string to add
17 16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 17
      */
19 18
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
19
+         String newstring = firstSegment.concat(secondSegment);
20
+         return newstring;
21 21
     }
22 22
 
23 23
     /**
@@ -26,7 +26,8 @@ public class StringUtilities {
26 26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 27
      */
28 28
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
29
+        String newthing = firstSegment + secondSegment;
30
+        return newthing;
30 31
     }
31 32
 
32 33
     /**
@@ -34,7 +35,7 @@ public class StringUtilities {
34 35
      * @return the first 3 characters of `input`
35 36
      */
36 37
     public static String getPrefix(String input){
37
-        return null;
38
+        return input.substring(0, 3);
38 39
     }
39 40
 
40 41
     /**
@@ -42,7 +43,7 @@ public class StringUtilities {
42 43
      * @return the last 3 characters of `input`
43 44
      */
44 45
     public static String getSuffix(String input){
45
-        return null;
46
+        return input.substring(input.length() - 3);
46 47
     }
47 48
 
48 49
     /**
@@ -51,7 +52,7 @@ public class StringUtilities {
51 52
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 53
      */
53 54
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
55
+       return inputValue.equals(comparableValue);
55 56
     }
56 57
 
57 58
     /**
@@ -59,7 +60,10 @@ public class StringUtilities {
59 60
      * @return the middle character of `inputValue`
60 61
      */
61 62
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
63
+        int mid = (int) Math.floor(inputValue.length() / 2);
64
+
65
+        if(mid % 2 == 0) mid = (int) Math.floor(inputValue.length() / 2 - 1);
66
+        return inputValue.charAt(mid);
63 67
     }
64 68
 
65 69
     /**
@@ -67,7 +71,8 @@ public class StringUtilities {
67 71
      * @return the first sequence of characters
68 72
      */
69 73
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
74
+        String firstw = spaceDelimitedString.split(" ", 2)[0];
75
+        return firstw;
71 76
     }
72 77
 
73 78
     /**
@@ -75,7 +80,8 @@ public class StringUtilities {
75 80
      * @return the second word of a string delimited by spaces.
76 81
      */
77 82
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
83
+        String secondw = spaceDelimitedString.split(" ")[1];
84
+        return secondw;
79 85
     }
80 86
 
81 87
     /**
@@ -83,6 +89,6 @@ public class StringUtilities {
83 89
      * @return an identical string with characters in reverse order.
84 90
      */
85 91
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
92
+       return new StringBuilder(stringToReverse).reverse().toString();
87 93
     }
88 94
 }

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.java Ver fichero

@@ -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
@@ -146,7 +146,7 @@ public class TestMathUtilities {
146 146
         // : When
147 147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148 148
         // : Then
149
-        assertEquals(expectedFloat,actualFloat, 0);
149
+        assertEquals(expectedFloat,actualFloat, 0.003);
150 150
     }
151 151
     @Test
152 152
     public void testSubtractions5() {
@@ -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 Ver fichero

@@ -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
 }

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Ver fichero

@@ -8,7 +8,7 @@ import static org.junit.Assert.*;
8 8
  * Created by dan on 6/14/17.
9 9
  */
10 10
 public class TestStringUtilities {
11
-    @Test
11
+    @org.junit.jupiter.api.Test
12 12
     public void getHelloWorldTest() {
13 13
         // : Given
14 14
         String expected = "Hello World";
@@ -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);

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class Ver fichero


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Ver fichero


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Ver fichero


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class Ver fichero


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Ver fichero


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Ver fichero