diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..2f44ced
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,29 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Test Case Report
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up JDK 11 Amazon Corretto
+ uses: actions/setup-java@v3
+ with:
+ java-version: '11'
+ distribution: 'corretto'
+ cache: maven
+ - name: Build with Maven
+ run: mvn -B package --file pom.xml
+ - name: Test with Maven
+ run: mvn -B test --file pom.xml
+
diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml
new file mode 100644
index 0000000..bd14a83
--- /dev/null
+++ b/.github/workflows/super-linter.yml
@@ -0,0 +1,29 @@
+# This workflow executes several linters on changed files based on languages used in your code base whenever
+# you push a code or open a pull request.
+#
+# You can adjust the behavior by modifying this file.
+# For more information, see:
+# https://github.com/github/super-linter
+name: Lint Code Base
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+jobs:
+ run-lint:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v3
+ with:
+ # Full git history is needed to get a proper list of changed files within `super-linter`
+ fetch-depth: 0
+
+ - name: Lint Code Base
+ uses: github/super-linter@v4
+ env:
+ VALIDATE_ALL_CODEBASE: false
+ DEFAULT_BRANCH: main
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 5ff6309..e9ddf70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ target/
!**/src/test/**/target/
### IntelliJ IDEA ###
+.idea/
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
@@ -35,4 +36,8 @@ build/
.vscode/
### Mac OS ###
-.DS_Store
\ No newline at end of file
+.DS_Store
+
+### SonarLint ###
+
+!/.idea/sonarlint/
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4258c62..0bc224b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/sonarlint/issuestore/8/6/863e0292fd7e9b3e74dafd6cc01f73ba76346482 b/.idea/sonarlint/issuestore/8/6/863e0292fd7e9b3e74dafd6cc01f73ba76346482
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 76e3a07..4e9c26f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,7 @@
-
-
-
+
@@ -24,6 +22,7 @@
+
@@ -40,17 +39,29 @@
- {
+ "keyToString": {
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SONARLINT_PRECOMMIT_ANALYSIS": "true",
+ "com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary": "JUnit5",
+ "com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.JUnit5": "",
+ "full.screen.before.presentation.mode": "false",
+ "last_opened_file_path": "C:/Users/divya/Exercism/java/need-for-speed",
+ "project.structure.last.edited": "Project",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.0",
+ "settings.editor.selected.configurable": "preferences.pluginManager"
+ },
+ "keyToStringList": {
+ "DatabaseDriversLRU": [
+ "mysql"
+ ],
+ "com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
+ "Markdown"
+ ]
}
-}]]>
+}
@@ -59,7 +70,7 @@
-
+
@@ -75,7 +86,7 @@
-
+
@@ -85,7 +96,7 @@
-
+
@@ -107,7 +118,7 @@
-
+
@@ -117,7 +128,7 @@
-
+
@@ -132,11 +143,11 @@
-
+
+
-
-
+
@@ -148,7 +159,12 @@
1652464472009
-
+
+
+
+
+
+
1652464516513
@@ -234,7 +250,63 @@
1652467935271
-
+
+ 1652468435970
+
+
+
+ 1652468435970
+
+
+ 1652551923621
+
+
+
+ 1652551923621
+
+
+ 1652552720625
+
+
+
+ 1652552720625
+
+
+ 1652553063899
+
+
+
+ 1652553063899
+
+
+ 1652633662838
+
+
+
+ 1652633662838
+
+
+ 1652816083393
+
+
+
+ 1652816083393
+
+
+ 1652819174296
+
+
+
+ 1652819174296
+
+
+ 1652819472258
+
+
+
+ 1652819472258
+
+
@@ -262,7 +334,15 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..742effe
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 Divyansh Bhardwaj
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 4d7bda0..454aed7 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
+[](https://github.com/dbc2201/JavaCodingProblem1/actions/workflows/maven.yml)
# Java Coding Problems
## Chapter 1: Strings, Numbers, and Math
---
-### Problem Statement
+### Problem Statement : Counting Duplicate Characters
Write a program that counts duplicate characters from a given `String`.
@@ -28,5 +29,13 @@ Write a program that counts duplicate characters from a given `String`.
---
> Question taken from the book
-> ["Java Coding Problems"](https://www.packtpub.com/product/java-coding-problems/9781789801415) by Anghel Leonard.
-> Formatted and uploaded by [dbc2201](https://github.com/dbc2201)
\ No newline at end of file
+> ["Java Coding Problems"](https://www.packtpub.com/product/java-coding-problems/9781789801415) by
+> [Anghel Leonard](https://github.com/AnghelLeonard).
+> Formatted and uploaded by [dbc2201](https://github.com/dbc2201)
+
+---
+
+**Suggested Reading:**
+
+1. [HashMap (Java SE 18 & JDK 18)](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/HashMap.html)
+2. [Managing the Content of a Map (dev.java)](https://dev.java/learn/managing-the-content-of-a-map/)
diff --git a/pom.xml b/pom.xml
index 1149d30..629d57c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,8 +17,31 @@
- 18
- 18
+ UTF-8
+ 11
+ 11
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.9.0
+
+ 11
+ 11
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/github/dbc/DuplicateCharactersCounter.java b/src/main/java/io/github/dbc/DuplicateCharactersCounter.java
index 9020649..49cee5a 100644
--- a/src/main/java/io/github/dbc/DuplicateCharactersCounter.java
+++ b/src/main/java/io/github/dbc/DuplicateCharactersCounter.java
@@ -8,6 +8,7 @@ public class DuplicateCharactersCounter {
*
* @param string String to count duplicate characters.
* @return Map with characters and their count.
+ * @throws IllegalArgumentException if the input is null or empty.
*/
public Map countDuplicateCharacters(String string) {
return Map.of();
diff --git a/src/test/java/io/github/dbc/DuplicateCharactersCounterTest.java b/src/test/java/io/github/dbc/DuplicateCharactersCounterTest.java
index a884fe7..537d1df 100644
--- a/src/test/java/io/github/dbc/DuplicateCharactersCounterTest.java
+++ b/src/test/java/io/github/dbc/DuplicateCharactersCounterTest.java
@@ -4,6 +4,8 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EmptySource;
+import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -17,15 +19,14 @@ void setUp() {
counter = new DuplicateCharactersCounter();
}
- @ParameterizedTest
+ @ParameterizedTest(name = "countDuplicateCharacters(\"{arguments}\")")
@ValueSource(strings = {"abcdefghijklmnopqrstuvwxyz", "dbc", "A", "1234567890", " "})
@DisplayName("should return map of correct size")
void shouldReturnMapOfCorrectSize(String input) {
// Act
var characterIntegerMap = counter.countDuplicateCharacters(input);
// Assert
- assertEquals(input.length(), characterIntegerMap.size(),
- "the map should have the same size as the input string");
+ assertEquals(input.length(), characterIntegerMap.size(), "the map should have the same size as the input string");
}
@Test
@@ -41,17 +42,17 @@ void shouldReturnCount1ForNonDuplicateCharacters() {
assertEquals(1, count, "the count value for all non duplicate characters should be 1");
}
- @Test
+ @ParameterizedTest(name = "countDuplicateCharacters({arguments})")
+ @NullSource
@DisplayName("should throw an IllegalArgumentException for null input")
- void shouldThrowAnIllegalArgumentExceptionForNullInput() {
- assertThrows(IllegalArgumentException.class, () -> counter.countDuplicateCharacters(null));
+ void shouldThrowAnIllegalArgumentExceptionForNullInput(String input) {
+ assertThrows(IllegalArgumentException.class, () -> counter.countDuplicateCharacters(input));
}
- @Test
+ @ParameterizedTest(name = "countDuplicateCharacters(\"{arguments}\")")
+ @EmptySource
@DisplayName("should return empty map for empty input")
- void shouldReturnEmptyMapForEmptyInput() {
- // Arrange
- String input = "";
+ void shouldReturnEmptyMapForEmptyInput(String input) {
// Act
var characterIntegerMap = counter.countDuplicateCharacters(input);
// Assert