Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-structure project to use Maven #529

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 121 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,123 @@
Java.iml
.idea/*

# Created by https://www.gitignore.io/api/java,maven,intellij+all

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar


# End of https://www.gitignore.io/api/java,maven,intellij+all
41 changes: 41 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com</groupId>
<artifactId>algorithms</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>

<!-- Test -->
<junit.version>5.3.1</junit.version>
</properties>

<dependencies>
<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.conversions;
package com.algorithms.conversions;

public class AnyBaseToDecimal {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.conversions;
package com.algorithms.conversions;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.search;
package com.algorithms.search;

/**
* Binary search is an algorithm which finds the position of a target value within a sorted array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

public class BubbleSort {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.algorithms.sorts.SortUtils.less;
import static com.algorithms.sorts.SortUtils.swap;

public class HeapSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

public class InsertionSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

public class MergeSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.algorithms.sorts.SortUtils.less;
import static com.algorithms.sorts.SortUtils.swap;

public class QuickSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.algorithms.sorts.SortUtils.less;
import static com.algorithms.sorts.SortUtils.swap;

public class SelectionSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

import static src.main.java.com.sorts.SortUtils.less;
import static src.main.java.com.sorts.SortUtils.swap;
import static com.algorithms.sorts.SortUtils.less;
import static com.algorithms.sorts.SortUtils.swap;

public class ShellSort {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src.main.java.com.sorts;
package com.algorithms.sorts;

final class SortUtils {

Expand Down
39 changes: 39 additions & 0 deletions src/test/java/com/algorithms/conversions/AnyBaseToDecimalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.algorithms.conversions;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AnyBaseToDecimalTest {

@Test
void testAnyBaseToDecimal() {
AnyBaseToDecimal anyBaseToDecimal = new AnyBaseToDecimal();
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("2", 2));
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("3", 2));
assertEquals("3", anyBaseToDecimal.convertToDecimal("11", 2));
assertEquals("4", anyBaseToDecimal.convertToDecimal("100", 2));
assertEquals("5", anyBaseToDecimal.convertToDecimal("101", 2));
assertEquals("10", anyBaseToDecimal.convertToDecimal("1010", 2));
assertEquals("1024", anyBaseToDecimal.convertToDecimal("10000000000", 2));

assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("8", 8));
assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("9", 8));
assertEquals("7", anyBaseToDecimal.convertToDecimal("7", 8));
assertEquals("8", anyBaseToDecimal.convertToDecimal("10", 8));
assertEquals("9", anyBaseToDecimal.convertToDecimal("11", 8));
assertEquals("10", anyBaseToDecimal.convertToDecimal("12", 8));
assertEquals("1024", anyBaseToDecimal.convertToDecimal("2000", 8));

assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("A", 10));
assertEquals("10", anyBaseToDecimal.convertToDecimal("10", 10));
assertEquals("1024", anyBaseToDecimal.convertToDecimal("1024", 10));

assertEquals("Invalid Number", anyBaseToDecimal.convertToDecimal("G", 16));
assertEquals("16", anyBaseToDecimal.convertToDecimal("10", 16));
assertEquals("17", anyBaseToDecimal.convertToDecimal("11", 16));
assertEquals("100", anyBaseToDecimal.convertToDecimal("64", 16));
assertEquals("225", anyBaseToDecimal.convertToDecimal("E1", 16));
assertEquals("1024", anyBaseToDecimal.convertToDecimal("400", 16));
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/algorithms/conversions/DecimalToAnyBaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.algorithms.conversions;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class DecimalToAnyBaseTest {

@Test
void testDecimalToAnyBase() {
DecimalToAnyBase decimalToAnyBase = new DecimalToAnyBase();
assertEquals("100", decimalToAnyBase.convertToAnyBase(4, 2));
assertEquals("11", decimalToAnyBase.convertToAnyBase(4, 3));
}
}
24 changes: 24 additions & 0 deletions src/test/java/com/algorithms/search/BinarySearchTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.algorithms.search;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class BinarySearchTest {

@Test
void testBinarySearch() {
BinarySearch binarySearch = new BinarySearch();

Integer[] arr1 = {1, 2, 3, 4, 5};
assertEquals(2, binarySearch.findIndex(arr1, 3));
assertEquals(0, binarySearch.findIndex(arr1, 1));
assertEquals(-1, binarySearch.findIndex(arr1, 8));
assertEquals(-1, binarySearch.findIndex(arr1, -2));

String[] arr2 = {"A", "B", "C", "D"};
assertEquals(2, binarySearch.findIndex(arr2, "C"));
assertEquals(1, binarySearch.findIndex(arr2, "B"));
assertEquals(-1, binarySearch.findIndex(arr2, "F"));
}
}
22 changes: 22 additions & 0 deletions src/test/java/com/algorithms/sorts/BubbleSortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.algorithms.sorts;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class BubbleSortTest {

@Test
void bubbleSortTest() {
BubbleSort bubbleSort = new BubbleSort();

Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
assertArrayEquals(sortedInt, bubbleSort.sort(unsortedInt));

Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar));
}

}
21 changes: 21 additions & 0 deletions src/test/java/com/algorithms/sorts/HeapSortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.algorithms.sorts;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class HeapSortTest {

@Test
void heapSortTest() {
HeapSort heapSort = new HeapSort();

Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7};
Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
assertArrayEquals(sortedInt, heapSort.sort(unsortedInt));

Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'};
Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
assertArrayEquals(sortedChar, heapSort.sort(unsortedChar));
}
}
Loading