Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork312
Add Repo#48
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
trunglc378 wants to merge1 commit intorampatra:masterChoose a base branch fromtrunglc378:ASM3_Trungdqfx03377
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Add Repo#48
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
157 changes: 106 additions & 51 deletionspom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletionssrc/main/test/Trung/BubbleSort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/main/test/java/TestSort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.