Quellcode durchsuchen

predicate and string tests pass, math utils unfinished. sleepy.

vvmk vor 6 Jahren
Ursprung
Commit
0cbad3622e

BIN
.DS_Store Datei anzeigen


+ 1
- 1
.idea/misc.xml Datei anzeigen

@@ -23,7 +23,7 @@
23 23
       </profile-state>
24 24
     </entry>
25 25
   </component>
26
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
26
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="9.0" project-jdk-type="JavaSDK">
27 27
     <output url="file://$PROJECT_DIR$/classes" />
28 28
   </component>
29 29
   <component name="masterDetails">

+ 2
- 0
ChapterOneMicro.iml Datei anzeigen

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

BIN
src/.DS_Store Datei anzeigen


BIN
src/main/.DS_Store Datei anzeigen


BIN
src/main/java/.DS_Store Datei anzeigen


BIN
src/main/java/com/.DS_Store Datei anzeigen


BIN
src/main/java/com/zipcodewilmington/.DS_Store Datei anzeigen


+ 14
- 14
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Datei anzeigen

@@ -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,7 @@ 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
     /**
@@ -29,7 +29,7 @@ public class MathUtilities {
29 29
      * @return sum of `baseValue` and `difference`
30 30
      */
31 31
     public Short add(short baseValue, short difference) {
32
-        return null;
32
+        return (short)(baseValue + difference); // I'm not sure I like that.
33 33
     }
34 34
 
35 35
     /**
@@ -38,7 +38,7 @@ public class MathUtilities {
38 38
      * @return sum of `baseValue` and `difference`
39 39
      */
40 40
     public Byte add(byte baseValue, byte difference) {
41
-        return null;
41
+        return (byte)(baseValue + difference);
42 42
     }
43 43
 
44 44
     /**
@@ -47,7 +47,7 @@ public class MathUtilities {
47 47
      * @return sum of `baseValue` and `difference`
48 48
      */
49 49
     public Float add(float baseValue, float difference) {
50
-        return null;
50
+        return baseValue + difference;
51 51
     }
52 52
 
53 53
     /**
@@ -56,7 +56,7 @@ public class MathUtilities {
56 56
      * @return sum of `baseValue` and `difference`
57 57
      */
58 58
     public Double add(double baseValue, double difference) {
59
-        return null;
59
+        return baseValue + difference;
60 60
     }
61 61
 
62 62
     /**
@@ -65,7 +65,7 @@ public class MathUtilities {
65 65
      * @return difference between `baseValue` and `difference`
66 66
      */
67 67
     public Integer subtract(int baseValue, int difference) {
68
-        return null;
68
+        return baseValue - difference;
69 69
     }
70 70
 
71 71
     /**
@@ -74,7 +74,7 @@ public class MathUtilities {
74 74
      * @return difference between `baseValue` and `difference`
75 75
      */
76 76
     public Long subtract(long baseValue, long difference) {
77
-        return null;
77
+        return baseValue - difference;
78 78
     }
79 79
 
80 80
     /**
@@ -83,7 +83,7 @@ public class MathUtilities {
83 83
      * @return difference between `baseValue` and `difference`
84 84
      */
85 85
     public Short subtract(short baseValue, short difference) {
86
-        return null;
86
+        return (short)(baseValue - difference);
87 87
     }
88 88
 
89 89
     /**
@@ -92,7 +92,7 @@ public class MathUtilities {
92 92
      * @return difference between `baseValue` and `difference`
93 93
      */
94 94
     public Byte subtract(byte baseValue, byte difference) {
95
-        return null;
95
+        return (byte)(baseValue - difference);
96 96
     }
97 97
 
98 98
     /**
@@ -101,7 +101,7 @@ public class MathUtilities {
101 101
      * @return difference between `baseValue` and `difference`
102 102
      */
103 103
     public Float subtract(float baseValue, float difference) {
104
-        return null;
104
+        return baseValue - difference;
105 105
     }
106 106
 
107 107
     /**
@@ -110,7 +110,7 @@ public class MathUtilities {
110 110
      * @return difference between `baseValue` and `difference`
111 111
      */
112 112
     public Double subtract(double baseValue, double difference) {
113
-        return null;
113
+        return baseValue - difference;
114 114
     }
115 115
 
116 116
 
@@ -227,14 +227,14 @@ public class MathUtilities {
227 227
       * @return true
228 228
      */
229 229
     public Boolean returnTrue() {
230
-        return null;
230
+        return true;
231 231
     }
232 232
 
233 233
     /**
234 234
      * @return false
235 235
      */
236 236
     public Boolean returnFalse() {
237
-        return null;
237
+        return false;
238 238
     }
239 239
 
240 240
 }

+ 4
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Datei anzeigen

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

+ 28
- 11
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Datei anzeigen

@@ -4,11 +4,15 @@ package com.zipcodewilmington.danny_do_better_exercises;
4 4
  * Created by dan on 6/14/17.
5 5
  */
6 6
 public class StringUtilities {
7
+    public static void main(String[] args) {
8
+
9
+    }
10
+
7 11
     /**
8 12
      * @return `Hello World` as a string
9 13
      */
10 14
     public static String getHelloWorld() {
11
-        return null;
15
+        return "Hello World";
12 16
     }
13 17
 
14 18
     /**
@@ -17,7 +21,7 @@ public class StringUtilities {
17 21
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18 22
      */
19 23
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
24
+        return firstSegment + secondSegment;
21 25
     }
22 26
 
23 27
     /**
@@ -26,7 +30,7 @@ public class StringUtilities {
26 30
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27 31
      */
28 32
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
33
+        return firstSegment + secondSegment;
30 34
     }
31 35
 
32 36
     /**
@@ -34,15 +38,21 @@ public class StringUtilities {
34 38
      * @return the first 3 characters of `input`
35 39
      */
36 40
     public static String getPrefix(String input){
37
-        return null;
41
+        return input.substring(0, 3);
38 42
     }
39 43
 
40 44
     /**
41 45
      * @param input a string to be manipulated
42 46
      * @return the last 3 characters of `input`
43 47
      */
44
-    public static String getSuffix(String input){
45
-        return null;
48
+    public static String getSuffix(String input) {
49
+        int l = input.length();
50
+
51
+        if (l <= 3) //just return the input string if not enough characters
52
+            return input;
53
+
54
+        int startIndex = l - 3;
55
+        return input.substring(startIndex);
46 56
     }
47 57
 
48 58
     /**
@@ -51,7 +61,7 @@ public class StringUtilities {
51 61
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52 62
      */
53 63
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
64
+       return inputValue.equals(comparableValue);
55 65
     }
56 66
 
57 67
     /**
@@ -59,7 +69,10 @@ public class StringUtilities {
59 69
      * @return the middle character of `inputValue`
60 70
      */
61 71
     public static Character getMiddleCharacter(String inputValue){
62
-        return null;
72
+        int l = inputValue.length();
73
+        int m = (l + (l % 2)) / 2; //if length is even, should just add 0, if odd, add 1 first.
74
+        //lmao that worked
75
+        return Character.valueOf(inputValue.charAt(m-1));
63 76
     }
64 77
 
65 78
     /**
@@ -67,7 +80,7 @@ public class StringUtilities {
67 80
      * @return the first sequence of characters
68 81
      */
69 82
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
83
+        return spaceDelimitedString.split(" ")[0];
71 84
     }
72 85
 
73 86
     /**
@@ -75,7 +88,7 @@ public class StringUtilities {
75 88
      * @return the second word of a string delimited by spaces.
76 89
      */
77 90
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
91
+        return spaceDelimitedString.split(" ")[1];
79 92
     }
80 93
 
81 94
     /**
@@ -83,6 +96,10 @@ public class StringUtilities {
83 96
      * @return an identical string with characters in reverse order.
84 97
      */
85 98
     public static String reverseTheTwo(String stringToReverse){
86
-        return null;
99
+        StringBuilder sb = new StringBuilder();
100
+        for (int i = stringToReverse.length()-1; i >= 0; i--) {
101
+            sb.append(stringToReverse.charAt(i));
102
+        }
103
+        return sb.toString();
87 104
     }
88 105
 }

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Datei anzeigen

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

+ 4
- 3
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Datei anzeigen

@@ -26,13 +26,14 @@ public class TestPredicateUtilities {
26 26
     @Test
27 27
     public void testGreaterThanFalse(){
28 28
         // : Given
29
-        int greaterValue = 350;
29
+        int greaterValue = 450;
30 30
         int lesserValue = 350;
31 31
 
32 32
         // : When
33 33
         boolean outcome = math.isGreaterThan(greaterValue, lesserValue);
34 34
 
35 35
         // : Then
36
+
36 37
         assertTrue(outcome);
37 38
     }
38 39
 
@@ -59,7 +60,7 @@ public class TestPredicateUtilities {
59 60
         int lesserValue = 350;
60 61
 
61 62
         // : When
62
-        boolean outcome = math.isLessThan(greaterValue, lesserValue);
63
+        boolean outcome = math.isLessThan(lesserValue, greaterValue);
63 64
 
64 65
         // : Then
65 66
         assertTrue(outcome);
@@ -109,7 +110,7 @@ public class TestPredicateUtilities {
109 110
     @Test
110 111
     public void testGreaterOrEqual2(){
111 112
         // : Given
112
-        int greaterValue = 8;
113
+        int greaterValue = 18;
113 114
         int lesserValue = 15;
114 115
 
115 116
         // : When

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java Datei anzeigen

@@ -59,7 +59,7 @@ public class TestStringUtilities {
59 59
         String expected = "olleH";
60 60
 
61 61
         // : When
62
-        String actual = StringUtilities.getPrefix(input);
62
+        String actual = StringUtilities.reverseTheTwo(input);
63 63
 
64 64
         // : Then
65 65
         assertEquals(expected, actual);
@@ -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 Datei anzeigen


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class Datei anzeigen


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class Datei anzeigen


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Datei anzeigen


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.class Datei anzeigen


BIN
target/test-classes/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.class Datei anzeigen