Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add quick sort unit test#38

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
lainhathoang wants to merge1 commit intorampatra:master
base:master
Choose a base branch
Loading
fromlainhathoang:feature/unit-test_quick-sort
Open
Changes fromall 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
53 changes: 53 additions & 0 deletionssrc/main/java/com/rampatra/sorting/QuickSortTest.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
package com.rampatra.sorting;

import org.junit.jupiter.api.Test;

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

public class QuickSortTest {
@Test
public void testWithEmptyArray() {
int[] array = {};
int[] expectedArray = {};

QuickSort.quickSort(array);
assertArrayEquals(expectedArray, array);
}

@Test
public void testWithOneElementArray() {
int[] array = {9};
int[] expectedArray = {9};

QuickSort.quickSort(array);

assertArrayEquals(expectedArray, array);
}

@Test
public void testWithAnArray() {
int[] array = {897, 695, 101, 377, 859, 176, 515, 613, 154, 978, 797, 136, 575, 577, 232, 118, 301, 951, 679, 114};
int[] expectedArray = {101, 114, 118, 136, 154, 176, 232, 301, 377, 515, 575, 577, 613, 679, 695, 797, 859, 897, 951, 978};
QuickSort.quickSort(array);

assertArrayEquals(expectedArray, array);
}

@Test
public void testWithSortedArray() {
int[] array = {101, 114, 118, 136, 154, 176, 232, 301, 377, 515, 575, 577, 613, 679, 695, 797, 859, 897, 951, 978};
int[] expectedArray = {101, 114, 118, 136, 154, 176, 232, 301, 377, 515, 575, 577, 613, 679, 695, 797, 859, 897, 951, 978};
QuickSort.quickSort(array);

assertArrayEquals(expectedArray, array);
}

@Test
public void testWithSortedReverseArray() {
int[] array = {978, 951, 897, 859, 797, 695, 679, 613, 577, 575, 515, 377, 301, 232, 176, 154, 136, 118, 114, 101};
int[] expectedArray = {101, 114, 118, 136, 154, 176, 232, 301, 377, 515, 575, 577, 613, 679, 695, 797, 859, 897, 951, 978};
QuickSort.quickSort(array);

assertArrayEquals(expectedArray, array);
}
}

[8]ページ先頭

©2009-2025 Movatter.jp