Commit des derniers TPs
This commit is contained in:
parent
e7f9cf7b1f
commit
360b1beaec
Binary file not shown.
@ -65,6 +65,12 @@ public class Couleurs extends JPanel {
|
|||||||
|
|
||||||
newG.setColor(colorList[index2]);
|
newG.setColor(colorList[index2]);
|
||||||
newG.fillPolygon(new int[] {0, this.getWidth(), this.getWidth()}, new int[] {0, 0, this.getHeight()}, 3);
|
newG.fillPolygon(new int[] {0, this.getWidth(), this.getWidth()}, new int[] {0, 0, this.getHeight()}, 3);
|
||||||
|
|
||||||
|
newG.setColor(colorList[index1]);
|
||||||
|
newG.drawString(nameList[index2], this.getWidth() - 150, 20);
|
||||||
|
|
||||||
|
newG.setColor(colorList[index2]);
|
||||||
|
newG.drawString(nameList[index1], 20, this.getHeight() - 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
public class Listener extends MouseListener {
|
/*public class Listener extends MouseListener {
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
BIN
DEV 2.3/Sorting/Sorting.class
Normal file
BIN
DEV 2.3/Sorting/Sorting.class
Normal file
Binary file not shown.
35
DEV 2.3/Sorting/Sorting.java
Normal file
35
DEV 2.3/Sorting/Sorting.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorting
|
||||||
|
*/
|
||||||
|
public class Sorting {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prend en entrée un tableau de double et renvoie le même tableau avec ses données triées.
|
||||||
|
* @param table Le tableau de doubles
|
||||||
|
* @throws NullPointerException Le tableau donné est nul
|
||||||
|
* @return Le même tableau trié
|
||||||
|
*/
|
||||||
|
public static double[] sort(double[] table) {
|
||||||
|
Objects.requireNonNull(table);
|
||||||
|
if (table.length < 2) return table;
|
||||||
|
|
||||||
|
double[] sortedArray = new double[table.length];
|
||||||
|
for (int i = 1; i < table.length-1; i++) {
|
||||||
|
double x = table[i];
|
||||||
|
int j = i;
|
||||||
|
while (j > 0 && table[j-1] > x) {
|
||||||
|
sortedArray[j] = table[j - 1];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
|
||||||
|
sortedArray[j] = x;
|
||||||
|
}
|
||||||
|
return sortedArray;
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV 2.3/Sorting/Tests.class
Normal file
BIN
DEV 2.3/Sorting/Tests.class
Normal file
Binary file not shown.
45
DEV 2.3/Sorting/Tests.java
Normal file
45
DEV 2.3/Sorting/Tests.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import org.junit.Test;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Tests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrdered() {
|
||||||
|
double[] arr = Sorting.sort(new double[] {5.225, 2592.2 ,218.1, 2952895828528.1, 11.2, -25.1});
|
||||||
|
|
||||||
|
for (int i = 1; i < arr.length; i++) {
|
||||||
|
assertTrue(arr[i] >= arr[i-1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSorted() {
|
||||||
|
double[] arr = new double[] {3.2, 589.2, 28582.1, 4.285824, 6.5282};
|
||||||
|
double[] sortedArr = new double[] {3.2, 4.285824, 6.5282, 589.2, 28582.1};
|
||||||
|
|
||||||
|
System.out.println(Arrays.toString(sortedArr));
|
||||||
|
System.out.println(Arrays.toString(Sorting.sort(arr)));
|
||||||
|
assertTrue(Arrays.equals(sortedArr, Sorting.sort(arr)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testZeroOneElementTable() {
|
||||||
|
Sorting.sort(new double[] {});
|
||||||
|
Sorting.sort(new double[] {1});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlreadySorted() {
|
||||||
|
double[] arr = new double[] {1.5, 2.7, 3.82, 5.5, 189.22};
|
||||||
|
assertTrue(Arrays.equals(arr, Sorting.sort(arr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NullPointerException.class)
|
||||||
|
public void testNullTable() {
|
||||||
|
Sorting.sort(null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user