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

new Task059. #381

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
19 changes: 19 additions & 0 deletions src/main/java/com/epam/university/java/core/task059/Task059.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.university.java.core.task059;

/**
* Count sort.
*
* <p>
* Given a list of integers. Every number is > 0 and < 10.
* Need to sort the sequence. Algorithm complexity must be O(n).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please a test that checks the complexity?

* </p>
*/
public interface Task059 {
/**
* Returns sorted sequence.
*
* @param sequence array to sort
* @return sorted array
*/
int[] countSort(int[] sequence);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.epam.university.java.core.task059;

import com.epam.university.java.core.helper.TestHelper;
import com.epam.university.java.core.task056.Task056;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Task059Test {
private Task059 instance;

@Before
public void setUp() throws Exception {
instance = TestHelper.getInstance(Task059.class);
}

@Test(expected = IllegalArgumentException.class)
public void arrayIsNull() throws Exception {
instance.countSort(null);
}

@Test
public void first() throws Exception {
final int[] input = {1, 3, 2, 7, 2, 2, 2, 3};
final int[] target = {1, 2, 2, 2, 3, 3, 7};
final int[] actual = instance.countSort(input);
for (int i = 0; i < target.length; i++) {
assertEquals("Wrong result", target[i], actual[i]);
}
}

@Test
public void second() throws Exception {
final int[] input = {2, 1, 1, 1, 3, 2, 2, 2, 3, 2, 3, 2, 2, 1, 1};
final int[] target = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3};
final int[] actual = instance.countSort(input);
for (int i = 0; i < target.length; i++) {
assertEquals("Wrong result", target[i], actual[i]);
}
}
}