From 360b1beaecac567af0a838a3666a4507f018ebaf Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Mon, 13 Jun 2022 16:26:56 +0200 Subject: [PATCH] Commit des derniers TPs --- APL2.1/TP16/Couleurs/Couleurs.class | Bin 2601 -> 2737 bytes APL2.1/TP16/Couleurs/Couleurs.java | 6 ++++ APL2.1/TP16/Couleurs/Listener.java | 4 +-- DEV 2.3/Sorting/Sorting.class | Bin 0 -> 577 bytes DEV 2.3/Sorting/Sorting.java | 35 ++++++++++++++++++++++ DEV 2.3/Sorting/Tests.class | Bin 0 -> 1438 bytes DEV 2.3/Sorting/Tests.java | 45 ++++++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 DEV 2.3/Sorting/Sorting.class create mode 100644 DEV 2.3/Sorting/Sorting.java create mode 100644 DEV 2.3/Sorting/Tests.class create mode 100644 DEV 2.3/Sorting/Tests.java diff --git a/APL2.1/TP16/Couleurs/Couleurs.class b/APL2.1/TP16/Couleurs/Couleurs.class index dece8b56e1708461dbe9c78e929f880f081a30e8..17f10d9f068a59ffb432134e77a5a9f4b9a09ebb 100644 GIT binary patch delta 260 zcmZ1}vQd=l)W2Q(7#J9A8Fp^uQe%_iV(4L5%fqmaVLc-QS4vT0d2mTlW?niYgZM;8 z;mJB|r`b0!Y-C_$*fjYcn%|OzMfp79NPEDAJe)W2Q(7#J9A8MbcZQe&H($ab844Z~UnMuv5h_1Qfc*H5lw*JoU}c_lkL zBapL^Bb{->WJyjd;f)NNK#G7`KQXW|FaznOlhZggIcv4HFlaN)XDFRKgR_WtBT$@) lVLg!4V&Iw_$E7K?0m$ZNVEV(L#Lm$3o1qbC$Y!vjEdaf&B?tfj diff --git a/APL2.1/TP16/Couleurs/Couleurs.java b/APL2.1/TP16/Couleurs/Couleurs.java index d1551fb..8768993 100644 --- a/APL2.1/TP16/Couleurs/Couleurs.java +++ b/APL2.1/TP16/Couleurs/Couleurs.java @@ -65,6 +65,12 @@ public class Couleurs extends JPanel { newG.setColor(colorList[index2]); 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); } } } diff --git a/APL2.1/TP16/Couleurs/Listener.java b/APL2.1/TP16/Couleurs/Listener.java index 662ceaa..320c391 100644 --- a/APL2.1/TP16/Couleurs/Listener.java +++ b/APL2.1/TP16/Couleurs/Listener.java @@ -1,3 +1,3 @@ -public class Listener extends MouseListener { +/*public class Listener extends MouseListener { -} +}*/ diff --git a/DEV 2.3/Sorting/Sorting.class b/DEV 2.3/Sorting/Sorting.class new file mode 100644 index 0000000000000000000000000000000000000000..3ca8c76968f7e1c859b7131b287cd1096e9ec635 GIT binary patch literal 577 zcmZWnO)mpc6g{_{=`f}(s`WLLNTf3og0S(i(TGTusMMmXX*-c&Oc^tNf&XA zMMS#iZ}<~7Rd+@g!du*TKh8b(yqov__0j~eh7lPNL?s9cM8pWa$Ht{GXB*DZ+-~*Q zta*gks^wVTIw6|V$}+mpEkRb$1BK8R!hO%OJMara!Zpu*%QcG)r|8=@VLDg%%etcd zPf17+q*BB6Ea!+IY&7a7Az82-v*@2zP4~d4+ME$i4a*^9a+O~kCC}xq6|Kzm3#MS% zxk_HEP?}3izQv1-&U8!w0MJYJuM3LdF}cJshPC+6YXD#?Ys5|$J+i?gznmJGY>pI5{g@Z z!hVY94DhQmEN~DihA_brr!ay=jPgHFv4JeMxK`xXr++%)EyN^bsD(t7vY(Jy^iW7V F{0*A3Zn^*f literal 0 HcmV?d00001 diff --git a/DEV 2.3/Sorting/Sorting.java b/DEV 2.3/Sorting/Sorting.java new file mode 100644 index 0000000..8f8c1f1 --- /dev/null +++ b/DEV 2.3/Sorting/Sorting.java @@ -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; + } +} \ No newline at end of file diff --git a/DEV 2.3/Sorting/Tests.class b/DEV 2.3/Sorting/Tests.class new file mode 100644 index 0000000000000000000000000000000000000000..0209c0be40a4b26659963fa3ed49ccc76ce9f1ea GIT binary patch literal 1438 zcmZuxO>7%Q6#m9u?>e^gN1U`t9onX}acUEjru>vNbWIXU!Lh^IBsk`>u_xB1_O4m) zqDJC?5O6}O5C_z9<3~9nI6#D|3iVita}QjQkdQcX03oCTZ^lkSN=Nd}+nG1-`+4iR z`}cRZ0nDQkK>$GwN(>>W3grX6hqZN z*So>hg;_Dw=ihtlocH0|KdAZ{xwEN$e_`|njhhj~F|1)Eh9fx2pcNh0v+O#9(x!+Y zl9k1&%3=g#IHn;H!#Ex#E{foZma`dsZWpbzO72%@Fn+%9YASgrrUx>1Jo0YCMIfH9Ql; z1w6|z^bj2KrzKDuHW5kwzr@t4AaXHA-J_ zJ^A~c>#9Dow^iSX%(p(fr{N`rP>Huas-P@5HL|roXW2aOH#fLjGB+Bu67?vd;MTay zYYe?b&#YcuHd}I6!wN&7vdA!M__k*?`Kr~n=vdaa9nbVE$EMN)xr1H`v^i>}C@MY# zQS*p+S?8`(u=!GhH@WR~u?NLYwm}W3ZSQ6GinYAoXmoSJ{921XRZ-}~fBX^|D-Joy z-KA?)-V$5{aMAJIDu2Ne(jp}))t(k@z)4)8KZCRmjsN{IHuLc((3Bl0!Cj2L8(=&C{478N5_E(BfGE=F#d-AMMVj*%pdZi= zd0dh_DM_A^Bu`6{lSb}P2Cb5eNtr>} zB;%B^{57W1yU2WlCn-vip3Y0U6V8!_1IxyU0_ZN7z%Ul+F3963Dj3Bkjy*uOv`==H z$O@x}g10oPzNQGy{ld7lgTj5%_2bly6L^Fgd06?Y`^EB9Otg5qtLu_fo|U>5q^>2Y z>#~tcJxo9c=QIg8Ls!V;130VuI1@x!kXG4Yp5nFzQp6%H&qgWBpx;^*uhCSd%>dT_ E1q+chJpcdz literal 0 HcmV?d00001 diff --git a/DEV 2.3/Sorting/Tests.java b/DEV 2.3/Sorting/Tests.java new file mode 100644 index 0000000..9a5d117 --- /dev/null +++ b/DEV 2.3/Sorting/Tests.java @@ -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); + } +}