Browse Source

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

vvmk 6 years ago
parent
commit
0cbad3622e

BIN
.DS_Store View File


+ 1
- 1
.idea/misc.xml View File

23
       </profile-state>
23
       </profile-state>
24
     </entry>
24
     </entry>
25
   </component>
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
     <output url="file://$PROJECT_DIR$/classes" />
27
     <output url="file://$PROJECT_DIR$/classes" />
28
   </component>
28
   </component>
29
   <component name="masterDetails">
29
   <component name="masterDetails">

+ 2
- 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" />
15
   </component>
17
   </component>
16
 </module>
18
 </module>

BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File


BIN
src/main/java/com/.DS_Store View File


BIN
src/main/java/com/zipcodewilmington/.DS_Store View File


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

+ 28
- 11
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

4
  * Created by dan on 6/14/17.
4
  * Created by dan on 6/14/17.
5
  */
5
  */
6
 public class StringUtilities {
6
 public class StringUtilities {
7
+    public static void main(String[] args) {
8
+
9
+    }
10
+
7
     /**
11
     /**
8
      * @return `Hello World` as a string
12
      * @return `Hello World` as a string
9
      */
13
      */
10
     public static String getHelloWorld() {
14
     public static String getHelloWorld() {
11
-        return null;
15
+        return "Hello World";
12
     }
16
     }
13
 
17
 
14
     /**
18
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
21
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
22
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
23
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
24
+        return firstSegment + secondSegment;
21
     }
25
     }
22
 
26
 
23
     /**
27
     /**
26
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
30
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
27
      */
31
      */
28
     public static String concatenation(int firstSegment, String secondSegment){
32
     public static String concatenation(int firstSegment, String secondSegment){
29
-        return null;
33
+        return firstSegment + secondSegment;
30
     }
34
     }
31
 
35
 
32
     /**
36
     /**
34
      * @return the first 3 characters of `input`
38
      * @return the first 3 characters of `input`
35
      */
39
      */
36
     public static String getPrefix(String input){
40
     public static String getPrefix(String input){
37
-        return null;
41
+        return input.substring(0, 3);
38
     }
42
     }
39
 
43
 
40
     /**
44
     /**
41
      * @param input a string to be manipulated
45
      * @param input a string to be manipulated
42
      * @return the last 3 characters of `input`
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
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
61
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
52
      */
62
      */
53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
63
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
54
-        return null;
64
+       return inputValue.equals(comparableValue);
55
     }
65
     }
56
 
66
 
57
     /**
67
     /**
59
      * @return the middle character of `inputValue`
69
      * @return the middle character of `inputValue`
60
      */
70
      */
61
     public static Character getMiddleCharacter(String inputValue){
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
      * @return the first sequence of characters
80
      * @return the first sequence of characters
68
      */
81
      */
69
     public static String getFirstWord(String spaceDelimitedString){
82
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
83
+        return spaceDelimitedString.split(" ")[0];
71
     }
84
     }
72
 
85
 
73
     /**
86
     /**
75
      * @return the second word of a string delimited by spaces.
88
      * @return the second word of a string delimited by spaces.
76
      */
89
      */
77
     public static String getSecondWord(String spaceDelimitedString){
90
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
91
+        return spaceDelimitedString.split(" ")[1];
79
     }
92
     }
80
 
93
 
81
     /**
94
     /**
83
      * @return an identical string with characters in reverse order.
96
      * @return an identical string with characters in reverse order.
84
      */
97
      */
85
     public static String reverseTheTwo(String stringToReverse){
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 View File

5
  */
5
  */
6
 public class ZipcodeRocks {
6
 public class ZipcodeRocks {
7
     public static void main(String[] args) {
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 View File

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

+ 2
- 2
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java View File

59
         String expected = "olleH";
59
         String expected = "olleH";
60
 
60
 
61
         // : When
61
         // : When
62
-        String actual = StringUtilities.getPrefix(input);
62
+        String actual = StringUtilities.reverseTheTwo(input);
63
 
63
 
64
         // : Then
64
         // : Then
65
         assertEquals(expected, actual);
65
         assertEquals(expected, actual);
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/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.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