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

Add Repo #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
157 changes: 106 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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.rampatra.adsj</groupId>
Expand Down Expand Up @@ -31,7 +32,8 @@
<scm>
<url>https://github.com/rampatra/Algorithms-and-Data-Structures-in-Java</url>
<connection>scm:git:git://github.com/rampatra/Algorithms-and-Data-Structures-in-Java.git</connection>
<developerConnection>scm:git:ssh://git@github.com/rampatra/Algorithms-and-Data-Structures-in-Java.git</developerConnection>
<developerConnection>scm:git:ssh://git@github.com/rampatra/Algorithms-and-Data-Structures-in-Java.git
</developerConnection>
<tag>HEAD</tag>
</scm>

Expand Down Expand Up @@ -60,57 +62,110 @@
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>16</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>compile</scope>
</dependency>

</dependencies>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- <profiles>-->
<!-- <profile>-->
<!-- <id>release</id>-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-source-plugin</artifactId>-->
<!-- <version>2.2.1</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>attach-sources</id>-->
<!-- <goals>-->
<!-- <goal>jar-no-fork</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
<!-- <version>2.9.1</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>attach-javadocs</id>-->
<!-- <goals>-->
<!-- <goal>jar</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>1.5</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- </profile>-->
<!-- </profiles>-->

<build>
<plugins>
Expand Down
50 changes: 50 additions & 0 deletions src/main/test/Trung/BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.Arrays;


/**
* @author rpatra16
* @since 03/11/2018
*/
public class BubbleSort {

/**
* In bubble sort, we start at the beginning of the array and swap
* the first two elements if the first is greater than the second.
* Then, we go to the next pair, and so on, continuously making sweeps
* of the array until it is sorted. In doing so, the smaller items
* slowly "bubble" up to the beginning of the list and in each inner
* iteration the largest element is sorted. Ergo, the inner loop runs
* until {@code length - i - 1} times. Time complexity: O(n^2). Space
* complexity: O(1), in place. To learn more: {@see https://youtu.be/6Gv8vg0kcHc}
*
* @param ar to be sorted
*/
public static void bubbleSort(int[] ar) {
for (int i = 0; i < ar.length - 1; i++) {
for (int j = 0; j < ar.length - i - 1; j++) {
if (ar[j] > ar[j + 1]) {
swap(ar, j, j + 1);
}
}
}
}

public static void swap(int[] ar, int i, int j) {
int temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}

public static void main(String[] args) {
int[] ar = {2, 5, 1, 7, 8};
System.out.println(Arrays.toString(ar));
bubbleSort(ar);
System.out.println(Arrays.toString(ar));
ar = new int[]{7, 5, 1, 7, 8, 0, 23};
System.out.println(Arrays.toString(ar));
bubbleSort(ar);
System.out.println(Arrays.toString(ar));
}
}


75 changes: 75 additions & 0 deletions src/main/test/java/TestSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import org.junit.jupiter.api.*;

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

public class TestSort {
@BeforeAll
public static void BeforeAll() {
System.out.println("Start All Test");
}

@AfterAll
public static void AfterAll() {
System.out.println("End All Test");
}

@BeforeEach
public void BeforeEach() {
System.out.println("Begin Test");
}

@AfterEach
public void AfterEach() {
System.out.println("After Test");
}

@Test
@DisplayName("Default Test")
void testArray() {
int[] ar = {2, 5, 1, 7, 8};
BubbleSort.bubbleSort(ar);
int[] expected = {1, 2, 5, 7, 8};
assertArrayEquals(expected, ar);
}

@Test
@Tag("Array")
@DisplayName("Test With Empty Array")
public void testEmptyArray() {
int[] ar = {};
BubbleSort.bubbleSort(ar);
int[] expected = {};
assertArrayEquals(expected, ar);
}

@Test
@Tag("Array")
@DisplayName("Test With Duplicate Element")
public void testDuplicateParameter() {
int[] ar = {9, 5, 6, 0, 5, 6, 11, 2, 4};
BubbleSort.bubbleSort(ar);
int[] expected = {0, 2, 4, 5, 5, 6, 6, 9, 11};
assertArrayEquals(expected, ar);
}

@Test
@Tag("Array")
@DisplayName("Test With Negative Integer Element")
public void testSameArray() {
int[] ar = {-1, -2, 5, 7, -8};
BubbleSort.bubbleSort(ar);
int[] expected = {-8, -2, -1, 5, 7};
Assertions.assertArrayEquals(expected, ar);
}

@Test
@Tag("Array")
@DisplayName("Test With Array Reverse")
public void testReverseArray() {
int[] ar = {8, 7, 5, 2, 1};
BubbleSort.bubbleSort(ar);
int[] expected = {1, 2, 5, 7, 8};
assertArrayEquals(expected, ar);
}
}