Browse Source

first commit finally

April Rivera 6 years ago
parent
commit
dc946fb481

+ 6
- 0
ChapterOneMicro.iml View File

12
     <orderEntry type="sourceFolder" forTests="false" />
12
     <orderEntry type="sourceFolder" forTests="false" />
13
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
13
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
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
   </component>
21
   </component>
16
 </module>
22
 </module>

+ 5
- 0
pom.xml View File

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

+ 31
- 26
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java View File

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

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

8
      * @return `Hello World` as a string
8
      * @return `Hello World` as a string
9
      */
9
      */
10
     public static String getHelloWorld() {
10
     public static String getHelloWorld() {
11
-        return null;
11
+        return "Hello World";
12
     }
12
     }
13
-
14
     /**
13
     /**
15
      * @param firstSegment a string to be added to
14
      * @param firstSegment a string to be added to
16
      * @param secondSegment a string to add
15
      * @param secondSegment a string to add
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
17
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
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
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
27
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
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
      * @return the first 3 characters of `input`
35
      * @return the first 3 characters of `input`
35
      */
36
      */
36
     public static String getPrefix(String input){
37
     public static String getPrefix(String input){
37
-        return null;
38
+        return input.substring(0, 3);
38
     }
39
     }
39
 
40
 
40
     /**
41
     /**
42
      * @return the last 3 characters of `input`
43
      * @return the last 3 characters of `input`
43
      */
44
      */
44
     public static String getSuffix(String input){
45
     public static String getSuffix(String input){
45
-        return null;
46
+        return input.substring(input.length() - 3);
46
     }
47
     }
47
 
48
 
48
     /**
49
     /**
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
53
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
55
+       return inputValue.equals(comparableValue);
55
     }
56
     }
56
 
57
 
57
     /**
58
     /**
59
      * @return the middle character of `inputValue`
60
      * @return the middle character of `inputValue`
60
      */
61
      */
61
     public static Character getMiddleCharacter(String inputValue){
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
      * @return the first sequence of characters
71
      * @return the first sequence of characters
68
      */
72
      */
69
     public static String getFirstWord(String spaceDelimitedString){
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
      * @return the second word of a string delimited by spaces.
80
      * @return the second word of a string delimited by spaces.
76
      */
81
      */
77
     public static String getSecondWord(String spaceDelimitedString){
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
      * @return an identical string with characters in reverse order.
89
      * @return an identical string with characters in reverse order.
84
      */
90
      */
85
     public static String reverseTheTwo(String stringToReverse){
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 View File

36
         // : Given
36
         // : Given
37
         short baseValue = 16384;
37
         short baseValue = 16384;
38
         short addedValue = 7;
38
         short addedValue = 7;
39
-        short expected = 32767;
39
+        short expected = 16391;
40
         // : When
40
         // : When
41
         short actual = primativeTypes.add(baseValue, addedValue);
41
         short actual = primativeTypes.add(baseValue, addedValue);
42
         // : Then
42
         // : Then
146
         // : When
146
         // : When
147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
147
         float actualFloat = primativeTypes.subtract(baseValue,difference);
148
         // : Then
148
         // : Then
149
-        assertEquals(expectedFloat,actualFloat, 0);
149
+        assertEquals(expectedFloat,actualFloat, 0.003);
150
     }
150
     }
151
     @Test
151
     @Test
152
     public void testSubtractions5() {
152
     public void testSubtractions5() {
296
         // : Given
296
         // : Given
297
         byte multiplicand = 16;
297
         byte multiplicand = 16;
298
         byte multiplier = 14;
298
         byte multiplier = 14;
299
-        byte expectedByte = 64;
299
+        byte expectedByte = -32;
300
         // : When
300
         // : When
301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
301
         byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
302
         // : Then
302
         // : Then

+ 3
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java View File

33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
34
 
34
 
35
         // : Then
35
         // : Then
36
-        assertTrue(outcome);
36
+        assertFalse(outcome);
37
     }
37
     }
38
 
38
 
39
 
39
 
62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
62
         boolean outcome = math.isLessThan(greaterValue, lesserValue);
63
 
63
 
64
         // : Then
64
         // : Then
65
-        assertTrue(outcome);
65
+        assertFalse(outcome);
66
     }
66
     }
67
 
67
 
68
 
68
 
116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
116
         boolean outcome = math.isGreaterThanOrEqualTo(greaterValue, lesserValue);
117
 
117
 
118
         // : Then
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 View File

8
  * Created by dan on 6/14/17.
8
  * Created by dan on 6/14/17.
9
  */
9
  */
10
 public class TestStringUtilities {
10
 public class TestStringUtilities {
11
-    @Test
11
+    @org.junit.jupiter.api.Test
12
     public void getHelloWorldTest() {
12
     public void getHelloWorldTest() {
13
         // : Given
13
         // : Given
14
         String expected = "Hello World";
14
         String expected = "Hello World";
56
     public void substringBeginTest(){
56
     public void substringBeginTest(){
57
         // : Given
57
         // : Given
58
         String input = "Hello";
58
         String input = "Hello";
59
-        String expected = "olleH";
59
+        String expected = "Hel";
60
 
60
 
61
         // : When
61
         // : When
62
         String actual = StringUtilities.getPrefix(input);
62
         String actual = StringUtilities.getPrefix(input);
154
         String expected = "Wilmington";
154
         String expected = "Wilmington";
155
 
155
 
156
         // : When
156
         // : When
157
-        String actual = StringUtilities.getFirstWord(input);
157
+        String actual = StringUtilities.getSecondWord(input);
158
 
158
 
159
         // : Then
159
         // : Then
160
         assertEquals(expected, actual);
160
         assertEquals(expected, actual);

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class View File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class View File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class View File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestMathUtilities.class View File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class View File


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class View File