Skip to content

Commit 3abb40e

Browse files
committed
Re-structure project to use maven
1 parent 08dc6ad commit 3abb40e

32 files changed

+418
-265
lines changed

.gitignore

+121-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,123 @@
1-
Java.iml
2-
.idea/*
1+
2+
# Created by https://www.gitignore.io/api/java,maven,intellij+all
3+
4+
### Intellij+all ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/**/usage.statistics.xml
12+
.idea/**/dictionaries
13+
.idea/**/shelf
14+
15+
# Generated files
16+
.idea/**/contentModel.xml
17+
18+
# Sensitive or high-churn files
19+
.idea/**/dataSources/
20+
.idea/**/dataSources.ids
21+
.idea/**/dataSources.local.xml
22+
.idea/**/sqlDataSources.xml
23+
.idea/**/dynamic.xml
24+
.idea/**/uiDesigner.xml
25+
.idea/**/dbnavigator.xml
26+
27+
# Gradle
28+
.idea/**/gradle.xml
29+
.idea/**/libraries
30+
31+
# Gradle and Maven with auto-import
32+
# When using Gradle or Maven with auto-import, you should exclude module files,
33+
# since they will be recreated, and may cause churn. Uncomment if using
34+
# auto-import.
35+
# .idea/modules.xml
36+
# .idea/*.iml
37+
# .idea/modules
38+
39+
# CMake
40+
cmake-build-*/
41+
42+
# Mongo Explorer plugin
43+
.idea/**/mongoSettings.xml
44+
45+
# File-based project format
46+
*.iws
47+
48+
# IntelliJ
349
out/
50+
51+
# mpeltonen/sbt-idea plugin
52+
.idea_modules/
53+
54+
# JIRA plugin
55+
atlassian-ide-plugin.xml
56+
57+
# Cursive Clojure plugin
58+
.idea/replstate.xml
59+
60+
# Crashlytics plugin (for Android Studio and IntelliJ)
61+
com_crashlytics_export_strings.xml
62+
crashlytics.properties
63+
crashlytics-build.properties
64+
fabric.properties
65+
66+
# Editor-based Rest Client
67+
.idea/httpRequests
68+
69+
# Android studio 3.1+ serialized cache file
70+
.idea/caches/build_file_checksums.ser
71+
72+
### Intellij+all Patch ###
73+
# Ignores the whole .idea folder and all .iml files
74+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
75+
76+
.idea/
77+
78+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
79+
480
*.iml
81+
modules.xml
82+
.idea/misc.xml
83+
*.ipr
84+
85+
### Java ###
86+
# Compiled class file
87+
*.class
88+
89+
# Log file
90+
*.log
91+
92+
# BlueJ files
93+
*.ctxt
94+
95+
# Mobile Tools for Java (J2ME)
96+
.mtj.tmp/
97+
98+
# Package Files #
99+
*.jar
100+
*.war
101+
*.nar
102+
*.ear
103+
*.zip
104+
*.tar.gz
105+
*.rar
106+
107+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
108+
hs_err_pid*
109+
110+
### Maven ###
111+
target/
112+
pom.xml.tag
113+
pom.xml.releaseBackup
114+
pom.xml.versionsBackup
115+
pom.xml.next
116+
release.properties
117+
dependency-reduced-pom.xml
118+
buildNumber.properties
119+
.mvn/timing.properties
120+
.mvn/wrapper/maven-wrapper.jar
121+
122+
123+
# End of https://www.gitignore.io/api/java,maven,intellij+all

pom.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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</groupId>
8+
<artifactId>algorithms</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<java.version>1.8</java.version>
13+
14+
<!-- Test -->
15+
<junit.version>5.3.1</junit.version>
16+
</properties>
17+
18+
<dependencies>
19+
<!-- Test -->
20+
<dependency>
21+
<groupId>org.junit.jupiter</groupId>
22+
<artifactId>junit-jupiter-api</artifactId>
23+
<version>${junit.version}</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<configuration>
34+
<source>${java.version}</source>
35+
<target>${java.version}</target>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
41+
</project>

src/main/java/com/conversions/AnyBaseToDecimal.java src/main/java/com/algorithms/conversions/AnyBaseToDecimal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.conversions;
1+
package com.algorithms.conversions;
22

33
public class AnyBaseToDecimal {
44
/**

src/main/java/com/conversions/DecimalToAnyBase.java src/main/java/com/algorithms/conversions/DecimalToAnyBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.conversions;
1+
package com.algorithms.conversions;
22

33
import java.util.ArrayList;
44

src/main/java/com/search/BinarySearch.java src/main/java/com/algorithms/search/BinarySearch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.search;
1+
package com.algorithms.search;
22

33
/**
44
* Binary search is an algorithm which finds the position of a target value within a sorted array

src/main/java/com/sorts/BubbleSort.java src/main/java/com/algorithms/sorts/BubbleSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

33
public class BubbleSort {
44
/**

src/main/java/com/sorts/HeapSort.java src/main/java/com/algorithms/sorts/HeapSort.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.List;
66

7-
import static src.main.java.com.sorts.SortUtils.less;
8-
import static src.main.java.com.sorts.SortUtils.swap;
7+
import static com.algorithms.sorts.SortUtils.less;
8+
import static com.algorithms.sorts.SortUtils.swap;
99

1010
public class HeapSort {
1111

src/main/java/com/sorts/InsertionSort.java src/main/java/com/algorithms/sorts/InsertionSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

33
public class InsertionSort {
44

src/main/java/com/sorts/MergeSort.java src/main/java/com/algorithms/sorts/MergeSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

33
public class MergeSort {
44

src/main/java/com/sorts/QuickSort.java src/main/java/com/algorithms/sorts/QuickSort.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

3-
import static src.main.java.com.sorts.SortUtils.less;
4-
import static src.main.java.com.sorts.SortUtils.swap;
3+
import static com.algorithms.sorts.SortUtils.less;
4+
import static com.algorithms.sorts.SortUtils.swap;
55

66
public class QuickSort {
77

src/main/java/com/sorts/SelectionSort.java src/main/java/com/algorithms/sorts/SelectionSort.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

3-
import static src.main.java.com.sorts.SortUtils.less;
4-
import static src.main.java.com.sorts.SortUtils.swap;
3+
import static com.algorithms.sorts.SortUtils.less;
4+
import static com.algorithms.sorts.SortUtils.swap;
55

66
public class SelectionSort {
77

src/main/java/com/sorts/ShellSort.java src/main/java/com/algorithms/sorts/ShellSort.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

3-
import static src.main.java.com.sorts.SortUtils.less;
4-
import static src.main.java.com.sorts.SortUtils.swap;
3+
import static com.algorithms.sorts.SortUtils.less;
4+
import static com.algorithms.sorts.SortUtils.swap;
55

66
public class ShellSort {
77

src/main/java/com/sorts/SortUtils.java src/main/java/com/algorithms/sorts/SortUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package src.main.java.com.sorts;
1+
package com.algorithms.sorts;
22

33
final class SortUtils {
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.algorithms.conversions;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class AnyBaseToDecimalTest {
8+
9+
@Test
10+
void testAnyBaseToDecimal() {
11+
AnyBaseToDecimal anyBaseToDecimal = new AnyBaseToDecimal();
12+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("2", 2));
13+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("3", 2));
14+
assertEquals("3", anyBaseToDecimal.convertToDecimal("11", 2));
15+
assertEquals("4", anyBaseToDecimal.convertToDecimal("100", 2));
16+
assertEquals("5", anyBaseToDecimal.convertToDecimal("101", 2));
17+
assertEquals("10", anyBaseToDecimal.convertToDecimal("1010", 2));
18+
assertEquals("1024", anyBaseToDecimal.convertToDecimal("10000000000", 2));
19+
20+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("8", 8));
21+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("9", 8));
22+
assertEquals("7", anyBaseToDecimal.convertToDecimal("7", 8));
23+
assertEquals("8", anyBaseToDecimal.convertToDecimal("10", 8));
24+
assertEquals("9", anyBaseToDecimal.convertToDecimal("11", 8));
25+
assertEquals("10", anyBaseToDecimal.convertToDecimal("12", 8));
26+
assertEquals("1024", anyBaseToDecimal.convertToDecimal("2000", 8));
27+
28+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("A", 10));
29+
assertEquals("10", anyBaseToDecimal.convertToDecimal("10", 10));
30+
assertEquals("1024", anyBaseToDecimal.convertToDecimal("1024", 10));
31+
32+
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("G", 16));
33+
assertEquals("16", anyBaseToDecimal.convertToDecimal("10", 16));
34+
assertEquals("17", anyBaseToDecimal.convertToDecimal("11", 16));
35+
assertEquals("100", anyBaseToDecimal.convertToDecimal("64", 16));
36+
assertEquals("225", anyBaseToDecimal.convertToDecimal("E1", 16));
37+
assertEquals("1024", anyBaseToDecimal.convertToDecimal("400", 16));
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.algorithms.conversions;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class DecimalToAnyBaseTest {
8+
9+
@Test
10+
void testDecimalToAnyBase() {
11+
DecimalToAnyBase decimalToAnyBase = new DecimalToAnyBase();
12+
assertEquals("100", decimalToAnyBase.convertToAnyBase(4, 2));
13+
assertEquals("11", decimalToAnyBase.convertToAnyBase(4, 3));
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.algorithms.search;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class BinarySearchTest {
8+
9+
@Test
10+
void testBinarySearch() {
11+
BinarySearch binarySearch = new BinarySearch();
12+
13+
Integer[] arr1 = {1, 2, 3, 4, 5};
14+
assertEquals(2, binarySearch.findIndex(arr1, 3));
15+
assertEquals(0, binarySearch.findIndex(arr1, 1));
16+
assertEquals(-1, binarySearch.findIndex(arr1, 8));
17+
assertEquals(-1, binarySearch.findIndex(arr1, -2));
18+
19+
String[] arr2 = {"A", "B", "C", "D"};
20+
assertEquals(2, binarySearch.findIndex(arr2, "C"));
21+
assertEquals(1, binarySearch.findIndex(arr2, "B"));
22+
assertEquals(-1, binarySearch.findIndex(arr2, "F"));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.algorithms.sorts;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
6+
7+
class BubbleSortTest {
8+
9+
@Test
10+
void bubbleSortTest() {
11+
BubbleSort bubbleSort = new BubbleSort();
12+
13+
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
14+
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
15+
assertArrayEquals(sortedInt, bubbleSort.sort(unsortedInt));
16+
17+
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
18+
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
19+
assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar));
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.algorithms.sorts;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
6+
7+
class HeapSortTest {
8+
9+
@Test
10+
void heapSortTest() {
11+
HeapSort heapSort = new HeapSort();
12+
13+
Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
14+
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
15+
assertArrayEquals(sortedInt, heapSort.sort(unsortedInt));
16+
17+
Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
18+
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
19+
assertArrayEquals(sortedChar, heapSort.sort(unsortedChar));
20+
}
21+
}

0 commit comments

Comments
 (0)