Sfoglia il codice sorgente

Mostly done just have to finish Test String Utilities and do the Math Utilities

Jordan Elderidge 6 anni fa
parent
commit
0b792a20bb

+ 2
- 0
ChapterOneMicro.iml Vedi 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>

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java Vedi 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 null ;
15
     }
15
     }
16
 
16
 
17
     /**
17
     /**

+ 5
- 4
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java Vedi 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
     /**
17
     /**
17
      * @param x
18
      * @param x
18
      * @param y
19
      * @param y
19
      * @return true if `x` is less than `y`
20
      * @return true if `x` is less than `y`
20
      */
21
      */
21
     public Boolean isLessThan(int x, int y) {
22
     public Boolean isLessThan(int x, int y) {
22
-        return null;
23
+        return (x < y);
23
     }
24
     }
24
 
25
 
25
     /**
26
     /**
28
      * @return true if `x` is greater than or equal to `y`
29
      * @return true if `x` is greater than or equal to `y`
29
      */
30
      */
30
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
31
-        return null;
32
+        return (x >= y);
32
     }
33
     }
33
 
34
 
34
     /**
35
     /**
37
      * @return true if `x` is less than or equal to `y`
38
      * @return true if `x` is less than or equal to `y`
38
      */
39
      */
39
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
     public Boolean isLessThanOrEqualTo(int x, int y) {
40
-        return null;
41
+        return (x <= y);
41
     }
42
     }
42
 }
43
 }

+ 11
- 9
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java Vedi 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
 
13
 
14
     /**
14
     /**
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
18
      */
18
      */
19
     public static String concatenation(String firstSegment, String secondSegment){
19
     public static String concatenation(String firstSegment, String secondSegment){
20
-        return null;
20
+        return firstSegment + secondSegment;
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
+        return firstSegment + secondSegment;
30
     }
30
     }
31
 
31
 
32
     /**
32
     /**
34
      * @return the first 3 characters of `input`
34
      * @return the first 3 characters of `input`
35
      */
35
      */
36
     public static String getPrefix(String input){
36
     public static String getPrefix(String input){
37
-        return null;
37
+    return input.substring(0,3);
38
+
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(inputValue);
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
+        return "zipcode".charAt(3);
63
     }
64
     }
64
 
65
 
65
     /**
66
     /**
67
      * @return the first sequence of characters
68
      * @return the first sequence of characters
68
      */
69
      */
69
     public static String getFirstWord(String spaceDelimitedString){
70
     public static String getFirstWord(String spaceDelimitedString){
70
-        return null;
71
+        return spaceDelimitedString.substring(0,spaceDelimitedString.indexOf(" "));
72
+
71
     }
73
     }
72
 
74
 
73
     /**
75
     /**
75
      * @return the second word of a string delimited by spaces.
77
      * @return the second word of a string delimited by spaces.
76
      */
78
      */
77
     public static String getSecondWord(String spaceDelimitedString){
79
     public static String getSecondWord(String spaceDelimitedString){
78
-        return null;
80
+        return spaceDelimitedString.substring(8,18);
79
     }
81
     }
80
 
82
 
81
     /**
83
     /**

+ 1
- 1
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java Vedi 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
 }

+ 1
- 1
src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestPredicateUtilities.java Vedi File

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
 

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

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 = "ello";
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/PredicateUtilities.class Vedi File


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


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.class Vedi File


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


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