Skip to content
Snippets Groups Projects
Commit 70c22aa6 authored by FOURNEL Alexandre's avatar FOURNEL Alexandre
Browse files

question 2.5

parent 3a1535ed
No related branches found
No related tags found
No related merge requests found
......@@ -12,15 +12,7 @@ public class SortableIntList {
}
public int compare(int index1, int index2) {
if (IntList.get(index1) > IntList.get(index2)){
return 1;
}
else if (IntList.get(index1) < IntList.get(index2)) {
return -1;
}
else {
return 0;
}
return IntList.get(index1).compareTo(IntList.get(index2));
}
......@@ -31,14 +23,14 @@ public class SortableIntList {
public int get(int index) {
return IntList.get(index);
}
public void sort() {
for (int i = 0; i < IntList.size() - 1; i++)
{
for (int i = 0; i < IntList.size() - 1; i++) {
for (int j = i + 1; j < IntList.size(); j++) {
if (compare(IntList.get(j), IntList.get(i)) < 0) {
swap(IntList.get(i), IntList.get(j));
}
}
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package fr.univamu.sorting;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.*;
import static fr.univamu.sorting.IntLists.*;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -12,6 +12,25 @@ class ListSortTest {
@Test
void testSort() {
ArrayList<Integer> TestList = new ArrayList<Integer>(8);
TestList.add(1);
TestList.add(8);
TestList.add(9);
TestList.add(5);
TestList.add(4);
TestList.add(3);
TestList.add(2);
TestList.add(4);
ArrayList<Integer> TestList2 = new ArrayList<Integer>(8);
TestList.add(1);
TestList.add(2);
TestList.add(3);
TestList.add(4);
TestList.add(4);
TestList.add(5);
TestList.add(8);
TestList.add(9);
assertThat(TestList.sort()).isEqualTo(TestList2);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment