Nhu Nguyen 6 anni fa
commit
87b9f740e2
9 ha cambiato i file con 583 aggiunte e 0 eliminazioni
  1. 179
    0
      .gitignore
  2. 22
    0
      Bonus.java
  3. 140
    0
      BonusTest.java
  4. 15
    0
      MathUtilities.java
  5. 65
    0
      MathUtilitiesTest.java
  6. 12
    0
      README.TXT
  7. 13
    0
      StringUtilities.java
  8. 94
    0
      StringUtilitiesTest.java
  9. 43
    0
      package.bluej

+ 179
- 0
.gitignore Vedi File

@@ -0,0 +1,179 @@
1
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
2
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3
+
4
+# User-specific stuff:
5
+.idea/**/workspace.xml
6
+.idea/**/tasks.xml
7
+.idea/dictionaries
8
+
9
+# Sensitive or high-churn files:
10
+.idea/**/dataSources/
11
+.idea/**/dataSources.ids
12
+.idea/**/dataSources.xml
13
+.idea/**/dataSources.local.xml
14
+.idea/**/sqlDataSources.xml
15
+.idea/**/dynamic.xml
16
+.idea/**/uiDesigner.xml
17
+
18
+# Gradle:
19
+.idea/**/gradle.xml
20
+.idea/**/libraries
21
+
22
+# CMake
23
+cmake-build-debug/
24
+
25
+# Mongo Explorer plugin:
26
+.idea/**/mongoSettings.xml
27
+
28
+## File-based project format:
29
+*.iws
30
+
31
+## Plugin-specific files:
32
+
33
+# IntelliJ
34
+/out/
35
+
36
+# mpeltonen/sbt-idea plugin
37
+.idea_modules/
38
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
39
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
40
+
41
+# User-specific stuff:
42
+*.iml
43
+.idea/**
44
+.idea/**/workspace.xml
45
+.idea/**/tasks.xml
46
+.idea/dictionaries
47
+
48
+# Sensitive or high-churn files:
49
+.idea/**/dataSources/
50
+.idea/**/dataSources.ids
51
+.idea/**/dataSources.xml
52
+.idea/**/dataSources.local.xml
53
+.idea/**/sqlDataSources.xml
54
+.idea/**/dynamic.xml
55
+.idea/**/uiDesigner.xml
56
+
57
+# Gradle:
58
+.idea/**/gradle.xml
59
+.idea/**/libraries
60
+
61
+# CMake
62
+cmake-build-debug/
63
+
64
+# Mongo Explorer plugin:
65
+.idea/**/mongoSettings.xml
66
+
67
+## File-based project format:
68
+*.iws
69
+
70
+## Plugin-specific files:
71
+
72
+# IntelliJ
73
+/out/
74
+
75
+# mpeltonen/sbt-idea plugin
76
+.idea_modules/
77
+
78
+# JIRA plugin
79
+atlassian-ide-plugin.xml
80
+
81
+# Cursive Clojure plugin
82
+.idea/replstate.xml
83
+
84
+# Crashlytics plugin (for Android Studio and IntelliJ)
85
+com_crashlytics_export_strings.xml
86
+crashlytics.properties
87
+crashlytics-build.properties
88
+fabric.properties# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
89
+                 # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
90
+
91
+                 # User-specific stuff:
92
+                 .idea/**/workspace.xml
93
+                 .idea/**/tasks.xml
94
+                 .idea/dictionaries
95
+
96
+                 # Sensitive or high-churn files:
97
+                 .idea/**/dataSources/
98
+                 .idea/**/dataSources.ids
99
+                 .idea/**/dataSources.xml
100
+                 .idea/**/dataSources.local.xml
101
+                 .idea/**/sqlDataSources.xml
102
+                 .idea/**/dynamic.xml
103
+                 .idea/**/uiDesigner.xml
104
+
105
+                 # Gradle:
106
+                 .idea/**/gradle.xml
107
+                 .idea/**/libraries
108
+
109
+                 # CMake
110
+                 cmake-build-debug/
111
+
112
+                 # Mongo Explorer plugin:
113
+                 .idea/**/mongoSettings.xml
114
+
115
+                 ## File-based project format:
116
+                 *.iws
117
+
118
+                 ## Plugin-specific files:
119
+
120
+                 # IntelliJ
121
+                 /out/
122
+
123
+                 # mpeltonen/sbt-idea plugin
124
+                 .idea_modules/
125
+
126
+                 # JIRA plugin
127
+                 atlassian-ide-plugin.xml
128
+
129
+                 # Cursive Clojure plugin
130
+                 .idea/replstate.xml
131
+
132
+                 # Crashlytics plugin (for Android Studio and IntelliJ)
133
+                 com_crashlytics_export_strings.xml
134
+                 crashlytics.properties
135
+                 crashlytics-build.properties
136
+                 fabric.properties
137
+# JIRA plugin
138
+atlassian-ide-plugin.xml
139
+
140
+# Cursive Clojure plugin
141
+.idea/replstate.xml
142
+
143
+# Crashlytics plugin (for Android Studio and IntelliJ)
144
+com_crashlytics_export_strings.xml
145
+crashlytics.properties
146
+crashlytics-build.properties
147
+fabric.properties
148
+
149
+.project
150
+.classpath
151
+.settings
152
+
153
+
154
+#maven build target
155
+target/
156
+
157
+# ---> Java
158
+# Compiled class file
159
+*.class
160
+
161
+# Log file
162
+*.log
163
+
164
+# BlueJ files
165
+*.ctxt
166
+
167
+# Mobile Tools for Java (J2ME)
168
+.mtj.tmp/
169
+
170
+# Package Files #
171
+*.jar
172
+*.war
173
+*.ear
174
+*.zip
175
+*.tar.gz
176
+*.rar
177
+
178
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
179
+hs_err_pid*

+ 22
- 0
Bonus.java Vedi File

@@ -0,0 +1,22 @@
1
+
2
+/**
3
+ * Write a description of class Bonus here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Bonus
9
+{
10
+    public String acronym(String phrase) {
11
+        return null;
12
+    }
13
+    
14
+    public String encrypt(String word) {
15
+        return null;
16
+    }
17
+   
18
+    
19
+    public int factorial(int number){
20
+        return -1;
21
+    }
22
+}

+ 140
- 0
BonusTest.java Vedi File

@@ -0,0 +1,140 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class BonusTest
9
+{
10
+    private Bonus bonus;
11
+    
12
+    @Before
13
+    public void setUp(){
14
+        bonus = new Bonus();
15
+    }
16
+    
17
+    @Test
18
+    public void testAcronymBasic() {
19
+        //Given
20
+        String phrase = "Portable Network Graphics";
21
+        String expected = "PNG";
22
+        
23
+        //When
24
+        String actual = bonus.acronym(phrase);
25
+        
26
+        //Then
27
+        assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void testAcronymBasicLowercaseWords() {
32
+        //Given
33
+        String phrase = "Ruby on Rails";
34
+        String expected = "ROR";
35
+        
36
+        //When
37
+        String actual = bonus.acronym(phrase);
38
+        
39
+        //Then
40
+        assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void testAcronymBasicPunctuation() {
45
+        //Given
46
+        String phrase = "First In, First Out";
47
+        String expected = "FIFO";
48
+        
49
+        //When
50
+        String actual = bonus.acronym(phrase);
51
+        
52
+        //Then
53
+        assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void testAcronymBasicNonAcronymAllCapsWord() {
58
+        //Given
59
+        String phrase = "GNU Image Manipulation Program";
60
+        String expected = "GIMP";
61
+        
62
+        //When
63
+        String actual = bonus.acronym(phrase);
64
+        
65
+        //Then
66
+        assertEquals(expected, actual);
67
+    }
68
+    
69
+    
70
+    
71
+    
72
+    @Test
73
+    public void testEncryptWithTheFirstAlphabet(){
74
+        //Given
75
+        String word = "apple";
76
+        String expected = "dssoh";
77
+        
78
+        //When
79
+        String actual = bonus.encrypt(word);
80
+        
81
+        //Then
82
+        assertEquals(expected, actual);
83
+    }
84
+    
85
+    @Test
86
+    public void testEncryptWithTheLastLetters(){
87
+        //Given
88
+        String word = "wxyz";
89
+        String expected = "zabc";
90
+        
91
+        //When
92
+        String actual = bonus.encrypt(word);
93
+        
94
+        //Then
95
+        assertEquals(expected, actual);
96
+    }
97
+    
98
+    
99
+    @Test
100
+    public void testFactorialOf1(){
101
+        //Given
102
+        int number = 1;
103
+        int expected = 1;
104
+        
105
+        //When
106
+        int actual = bonus.factorial(number);
107
+        
108
+        //Then
109
+        assertEquals(expected, actual);
110
+        
111
+    }
112
+        
113
+    @Test
114
+    public void testFactorialOfSmallNumber(){
115
+        //Given
116
+        int number = 3;
117
+        int expected = 6;
118
+        
119
+        //When
120
+        int actual = bonus.factorial(number);
121
+        
122
+        //Then
123
+        assertEquals(expected, actual);
124
+        
125
+    }
126
+    
127
+    @Test
128
+    public void testFactorialOfBigNumber(){
129
+        //Given
130
+        int number = 6;
131
+        int expected = 720;
132
+        
133
+        //When
134
+        int actual = bonus.factorial(number);
135
+        
136
+        //Then
137
+        assertEquals(expected, actual);
138
+        
139
+    }
140
+}

+ 15
- 0
MathUtilities.java Vedi File

@@ -0,0 +1,15 @@
1
+public class MathUtilities{
2
+    
3
+    public int add(int num1, int num2){
4
+        return -1;
5
+    }
6
+    
7
+    public double add(double num1, double num2){
8
+        return -1;
9
+    }
10
+    
11
+    public double half(int number) {
12
+        return -1;
13
+    }
14
+
15
+}

+ 65
- 0
MathUtilitiesTest.java Vedi File

@@ -0,0 +1,65 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class MathUtilitiesTest
9
+{
10
+    private MathUtilities utilities;
11
+    private static final double DELTA = 0.009;
12
+
13
+    @Before
14
+    public void setup(){
15
+        utilities = new MathUtilities();
16
+    }
17
+    
18
+    @Test
19
+    public void testAddInteger(){
20
+        //Given
21
+        int expected = 15;
22
+        
23
+        //When
24
+        int actual = utilities.add(7, 8);
25
+        
26
+        //Then
27
+        assertEquals(expected, actual);
28
+    }
29
+    
30
+    @Test
31
+    public void testAddDouble(){
32
+        //Given
33
+        double expected = 11.22;
34
+        
35
+        //When
36
+        double actual = utilities.add(10, 1.22);
37
+        
38
+        //Then
39
+        assertEquals(expected, actual, DELTA);
40
+    }
41
+    
42
+    @Test
43
+    public void testHalfForEven(){
44
+        //Given
45
+        double expected = 2.0;
46
+        
47
+        //When
48
+        double actual = utilities.half(4);
49
+        
50
+        //Then
51
+        assertEquals(expected, actual, DELTA);
52
+    }
53
+    
54
+    @Test
55
+    public void testHalfForOdd(){
56
+        //Given
57
+        double expected = 12.5;
58
+        
59
+        //When
60
+        double actual = utilities.half(25);
61
+        
62
+        //Then
63
+        assertEquals(expected, actual, DELTA);
64
+    }
65
+}

+ 12
- 0
README.TXT Vedi File

@@ -0,0 +1,12 @@
1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

+ 13
- 0
StringUtilities.java Vedi File

@@ -0,0 +1,13 @@
1
+public class StringUtilities {
2
+   public Character getMiddleCharacter(String word){
3
+       return null;
4
+   }
5
+   
6
+   public String removeCharacter(String value, char charToRemove){
7
+     return null;  
8
+   }
9
+   
10
+   public String getLastWord(String value) {
11
+       return null;
12
+   }
13
+}

+ 94
- 0
StringUtilitiesTest.java Vedi File

@@ -0,0 +1,94 @@
1
+import static org.junit.Assert.*;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class StringUtilitiesTest {
7
+
8
+    private StringUtilities utilities;
9
+
10
+    @Before
11
+    public void setUp() {
12
+        utilities = new StringUtilities();
13
+    }
14
+    
15
+    @Test
16
+    public void testGetMiddleCharacter_ForOddWord(){
17
+        //Given
18
+        String word = "bokeh";
19
+        char expected = 'k';
20
+        
21
+        //When
22
+        char actual = utilities.getMiddleCharacter(word);
23
+        
24
+        //Then
25
+        assertEquals(expected, actual);
26
+    }
27
+    
28
+    @Test
29
+    public void testGetMiddleCharacter_ForEvenWord(){
30
+        //Given
31
+        String word = "dogs";
32
+        char expected = 'g';
33
+        
34
+        //When
35
+        char actual = utilities.getMiddleCharacter(word);
36
+        
37
+        //Then
38
+        assertEquals(expected, actual);
39
+    }
40
+
41
+    
42
+    @Test
43
+    public void testRemoveCharacter(){
44
+        // Given
45
+        String word = "taradiddle";
46
+        String expected = "taraile";
47
+        
48
+        //When
49
+        String actual = utilities.removeCharacter(word, 'd');
50
+        
51
+        //Then
52
+        assertEquals(expected, actual);
53
+    }
54
+    
55
+    @Test
56
+    public void testRemoveCharacter_atTheEnd(){
57
+        // Given
58
+        String word = "taradiddle";
59
+        String expected = "taradiddl";
60
+        
61
+        //When
62
+        String actual = utilities.removeCharacter(word, 'e');
63
+        
64
+        //Then
65
+        assertEquals(expected, actual);
66
+    }
67
+    
68
+    @Test
69
+    public void testRemoveCharacter_thatIsNotInTheString(){
70
+        // Given
71
+        String word = "taradiddle";
72
+        String expected = "taradiddle";
73
+        
74
+        //When
75
+        String actual = utilities.removeCharacter(word, 'x');
76
+        
77
+        //Then
78
+        assertEquals(expected, actual);
79
+    }
80
+    
81
+    @Test
82
+    public void testGetLastWord(){
83
+        // Given
84
+        String sentence = "I'm sorry for what I said when I was hungry";
85
+        String expected = "hungry";
86
+        
87
+        // When
88
+        String actual = utilities.getLastWord(sentence);
89
+        
90
+        // Then
91
+        assertEquals(expected, actual);
92
+    }
93
+    
94
+}

+ 43
- 0
package.bluej Vedi File

@@ -0,0 +1,43 @@
1
+#BlueJ package file
2
+dependency1.from=StringUtilitiesTest
3
+dependency1.to=StringUtilities
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=722
6
+editor.fx.0.width=800
7
+editor.fx.0.x=166
8
+editor.fx.0.y=127
9
+objectbench.height=164
10
+objectbench.width=776
11
+package.divider.horizontal=0.6
12
+package.divider.vertical=0.6845018450184502
13
+package.editor.height=364
14
+package.editor.width=674
15
+package.editor.x=557
16
+package.editor.y=43
17
+package.frame.height=600
18
+package.frame.width=800
19
+package.numDependencies=1
20
+package.numTargets=2
21
+package.showExtends=true
22
+package.showUses=true
23
+project.charset=UTF-8
24
+readme.height=58
25
+readme.name=@README
26
+readme.width=47
27
+readme.x=10
28
+readme.y=10
29
+target1.height=50
30
+target1.name=StringUtilitiesTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=110
34
+target1.x=100
35
+target1.y=-20
36
+target2.association=StringUtilitiesTest
37
+target2.height=50
38
+target2.name=StringUtilities
39
+target2.showInterface=false
40
+target2.type=ClassTarget
41
+target2.width=110
42
+target2.x=70
43
+target2.y=10