Leon пре 6 година
комит
71ca17f393

+ 155
- 0
.gitignore Прегледај датотеку

@@ -0,0 +1,155 @@
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/

+ 27
- 0
pom.xml Прегледај датотеку

@@ -0,0 +1,27 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington</groupId>
8
+    <artifactId>arrayutility</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+
12
+    <properties>
13
+        <maven.compiler.source>1.8</maven.compiler.source>
14
+        <maven.compiler.target>1.8</maven.compiler.target>
15
+    </properties>
16
+
17
+
18
+    <dependencies>
19
+        <dependency>
20
+            <groupId>junit</groupId>
21
+            <artifactId>junit</artifactId>
22
+            <version>4.12</version>
23
+        </dependency>
24
+    </dependencies>
25
+
26
+
27
+</project>

+ 7
- 0
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Прегледај датотеку

@@ -0,0 +1,7 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+/**
4
+ * Created by leon on 3/6/18.
5
+ */
6
+public class ArrayUtility {
7
+}

+ 19
- 0
src/test/java/com/zipcodewilmington/arrayutility/ArrayUtilityTestSuite.java Прегледај датотеку

@@ -0,0 +1,19 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import org.junit.runner.RunWith;
4
+import org.junit.runners.Suite;
5
+
6
+/**
7
+ * Created by leon on 3/1/18.
8
+ * The purpose of this class is to test all classes within this package
9
+ */
10
+@RunWith(Suite.class)
11
+
12
+@Suite.SuiteClasses({
13
+        CountDuplicatesInMergeTest.class,
14
+        GetMostCommonFromMergeTest.class,
15
+        GetNumberOfOccurrencesTest.class,
16
+        RemoveValueTest.class
17
+})
18
+public class ArrayUtilityTestSuite {
19
+}

+ 76
- 0
src/test/java/com/zipcodewilmington/arrayutility/CountDuplicatesInMergeTest.java Прегледај датотеку

@@ -0,0 +1,76 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 3/1/18.
8
+ * The purpose of this class is to thoroughly test the method countDuplicatesInMerge()
9
+ */
10
+public class CountDuplicatesInMergeTest {
11
+    @Test
12
+    public void integerTest() {
13
+        // Given
14
+        Integer valueToEvaluate = 7;
15
+        Integer expected = 5;
16
+        Integer[] inputArray = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8, valueToEvaluate};
17
+        Integer[] arrayToMerge = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8};
18
+        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
19
+
20
+        // When
21
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
22
+
23
+        // Then
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void longTest() {
29
+        // Given
30
+        Long valueToEvaluate = 7L;
31
+        Integer expected = 6;
32
+        Long[] inputArray = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
33
+        Long[] arrayToMerge = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate};
34
+        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
35
+
36
+        // When
37
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
38
+
39
+        // Then
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void stringTest() {
45
+        // Given
46
+        String valueToEvaluate = "a";
47
+        Integer expected = 7;
48
+        String[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
49
+        String[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate};
50
+
51
+        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
52
+
53
+        // When
54
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
55
+
56
+        // Then
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+    @Test
61
+    public void objectTest() {
62
+        // Given
63
+        Object valueToEvaluate = "a";
64
+        Integer expected = 8;
65
+        Object[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate};
66
+        Object[] arrayToMerge = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8", valueToEvaluate, valueToEvaluate, valueToEvaluate};
67
+
68
+        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
69
+
70
+        // When
71
+        Integer actual = arrayUtility.countDuplicatesInMerge(arrayToMerge, valueToEvaluate);
72
+
73
+        // Then
74
+        Assert.assertEquals(expected, actual);
75
+    }
76
+}

+ 72
- 0
src/test/java/com/zipcodewilmington/arrayutility/GetMostCommonFromMergeTest.java Прегледај датотеку

@@ -0,0 +1,72 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 3/1/18.
8
+ * The purpose of this class is to thoroughly test the method getMostCommonFromMerge()
9
+ */
10
+public class GetMostCommonFromMergeTest {
11
+    @Test
12
+    public void integerTest() {
13
+        // Given
14
+        Integer expected = 7;
15
+        Integer[] inputArray = {1, 2, expected, 8, 4, 5, expected, 0, 9, 8, expected};
16
+        Integer[] arrayToMerge = {1, 2, expected, 8, 4, 5, expected, 0, 9, 8};
17
+        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
18
+
19
+        // When
20
+        Integer actual = arrayUtility.getMostCommonFromMerge(arrayToMerge);
21
+
22
+        // Then
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void longTest() {
28
+        // Given
29
+        Long expected = 8L;
30
+        Long[] inputArray = {1L, 2L, expected, 8L, 4L, 5L, expected, 0L, 9L, 8L, expected};
31
+        Long[] arrayToMerge = {1L, 2L, expected, 8L, 4L, 5L, expected, 0L, 9L, 8L, expected};
32
+        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
33
+
34
+        // When
35
+        Long actual = arrayUtility.getMostCommonFromMerge(arrayToMerge);
36
+
37
+        // Then
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void stringTest() {
43
+        // Given
44
+        String expected = "a";
45
+        String[] inputArray = {"1", "2", expected, "8", "4", "5", expected, "0", "9", "8", expected};
46
+        String[] arrayToMerge = {"1", "2", expected, "8", "4", "5", expected, "0", "9", "8", expected, expected};
47
+
48
+        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
49
+
50
+        // When
51
+        String actual = arrayUtility.getMostCommonFromMerge(arrayToMerge);
52
+
53
+        // Then
54
+        Assert.assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void objectTest() {
59
+        // Given
60
+        Object expected = "a";
61
+        Object[] inputArray = {"1", "2", expected, "8", "4", "5", expected, "0", "9", "8", expected};
62
+        Object[] arrayToMerge = {"1", "2", expected, "8", "4", "5", expected, "0", "9", "8", expected, expected, expected};
63
+
64
+        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
65
+
66
+        // When
67
+        Object actual = arrayUtility.getMostCommonFromMerge(arrayToMerge);
68
+
69
+        // Then
70
+        Assert.assertEquals(expected, actual);
71
+    }
72
+}

+ 70
- 0
src/test/java/com/zipcodewilmington/arrayutility/GetNumberOfOccurrencesTest.java Прегледај датотеку

@@ -0,0 +1,70 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 3/1/18.
8
+ * The purpose of this class is to thoroughly test the method getNumberOfOccurrences()
9
+ */
10
+public class GetNumberOfOccurrencesTest {
11
+    @Test
12
+    public void integerTest() {
13
+        // Given
14
+        Integer valueToEvaluate = 7;
15
+        Integer expected = 3;
16
+        Integer[] inputArray = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8, valueToEvaluate};
17
+        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
18
+
19
+        // When
20
+        Integer actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
21
+
22
+        // Then
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void longTest() {
28
+        // Given
29
+        Long valueToEvaluate = 7L;
30
+        Integer expected = 4;
31
+        Long[] inputArray = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate, valueToEvaluate};
32
+        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
33
+
34
+        // When
35
+        Integer actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
36
+
37
+        // Then
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void stringTest() {
43
+        // Given
44
+        String valueToEvaluate = "a";
45
+        Integer expected = 2;
46
+        String[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8"};
47
+        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
48
+
49
+        // When
50
+        Integer actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
51
+
52
+        // Then
53
+        Assert.assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void objectTest() {
58
+        // Given
59
+        Object valueToEvaluate = new Object();
60
+        Integer expected = 1;
61
+        Object[] inputArray = {"1", "2", "8", "4", "5", "0", "9", "8", valueToEvaluate};
62
+        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
63
+
64
+        // When
65
+        Integer actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
66
+
67
+        // Then
68
+        Assert.assertEquals(expected, actual);
69
+    }
70
+}

+ 78
- 0
src/test/java/com/zipcodewilmington/arrayutility/RemoveValueTest.java Прегледај датотеку

@@ -0,0 +1,78 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import com.zipcodewilmington.UnitTestingUtils;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 3/1/18.
8
+ * The purpose of this class is to thoroughly test the method removeValue()
9
+ */
10
+public class RemoveValueTest {
11
+    @Test
12
+    public void integerTest() {
13
+        // Given
14
+        Integer valueToRemove = 7;
15
+        Integer[] expected = {11, 2, 8, 4, 5, 0, 9, 8};
16
+        Integer[] inputArray = {11, 2, valueToRemove, 8, 4, 5, valueToRemove, 0, 9, 8, valueToRemove};
17
+        ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
18
+
19
+
20
+        // When
21
+        Integer[] actual = arrayUtility.removeValue(valueToRemove);
22
+
23
+        // Then
24
+        UnitTestingUtils.assertArrayEquality(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void longTest() {
29
+        // Given
30
+        Long valueToRemove = 7L;
31
+        Long[] expected = {12L, 2L, 8L, 4L, 5L, 0L, 9L, 8L};
32
+        Long[] inputArray = {12L, 2L, valueToRemove, 8L, 4L, 5L, valueToRemove, 0L, 9L, 8L, valueToRemove};
33
+        ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
34
+
35
+
36
+        // When
37
+        Long[] actual = arrayUtility.removeValue(valueToRemove);
38
+
39
+        // Then
40
+        UnitTestingUtils.assertArrayEquality(expected, actual);
41
+    }
42
+
43
+
44
+    @Test
45
+    public void stringTest() {
46
+        // Given
47
+        String valueToRemove = "7";
48
+        String[] expected = {"13", "2", "8", "4", "5", "0", "9", "8"};
49
+        String[] inputArray = {"13", "2", valueToRemove, "8", "4", "5", valueToRemove, "0", "9", "8", valueToRemove};
50
+        ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
51
+
52
+
53
+        // When
54
+        String[] actual = arrayUtility.removeValue(valueToRemove);
55
+
56
+        // Then
57
+        UnitTestingUtils.assertArrayEquality(expected, actual);
58
+    }
59
+
60
+
61
+
62
+    @Test
63
+    public void objectTest() {
64
+        // Given
65
+        Object valueToRemove = "7";
66
+        Object[] expected = {"41", "2", "8", "4", "5", "0", "9", "8"};
67
+        Object[] inputArray = {"41", "2", valueToRemove, "8", "4", "5", valueToRemove, "0", "9", "8", valueToRemove};
68
+        ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
69
+
70
+
71
+        // When
72
+        Object[] actual = arrayUtility.removeValue(valueToRemove);
73
+
74
+        // Then
75
+        UnitTestingUtils.assertArrayEquality(expected, actual);
76
+    }
77
+
78
+}

+ 26
- 0
src/test/java/com/zipcodewilmington/arrayutility/UnitTestingUtils.java Прегледај датотеку

@@ -0,0 +1,26 @@
1
+package com.zipcodewilmington.arrayutility;
2
+
3
+import org.junit.Assert;
4
+
5
+import java.util.Arrays;
6
+
7
+/**
8
+ * Created by leon on 1/28/18.
9
+ *
10
+ * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
11
+ */
12
+public class UnitTestingUtils {
13
+    public synchronized static <T, E> void assertArrayEquality(T[] expected, E[] actual) {
14
+        Arrays.sort(expected);
15
+        Arrays.sort(actual);
16
+        String expectedString = Arrays.toString(expected);
17
+        String actualString = Arrays.toString(actual);
18
+        boolean equality = expectedString.equals(actualString);
19
+
20
+        System.out.println("\n\nExpected:\n\t" + expectedString);
21
+        System.out.println("\nActual:\n\t" + actualString);
22
+        System.out.println("\nEquivalence:\n\t" + equality);
23
+
24
+        Assert.assertArrayEquals(expected, actual);
25
+    }
26
+}