diff --git a/TD5 Test/Exercice.test.ts b/TD5 Test/Exercice.test.ts index 7a49112ab52da11f80cdde3056fcdce6d879ca7c..d582e9178b0161ddbfa63ad6ac77a47bde4e4aac 100644 --- a/TD5 Test/Exercice.test.ts +++ b/TD5 Test/Exercice.test.ts @@ -11,3 +11,6 @@ Deno.test("multiplication par 0", () => { Deno.test("multiplication par un nombre négatif", () => { assertEquals(multAdd(3, -8), -24); }); +Deno.test("multiplication par 2 nombre négatif", () => { + assertEquals(multAdd(-8, -8), 64); + }); diff --git a/TD5 Test/MesMaths.ts b/TD5 Test/MesMaths.ts index b29286f916fae5be9f1a4b0fa68be8084291995d..fccd14857920e2f2671a307f9e13b1033468d34b 100644 --- a/TD5 Test/MesMaths.ts +++ b/TD5 Test/MesMaths.ts @@ -1,7 +1,15 @@ export function multAdd(x: number, y: number): number { let resultat = 0; + let inf = 0; + if (y < 0){ + y = -y + inf = 1 ; + } for (let i = 0; i < y; i++) { resultat += x; } - return resultat; - } \ No newline at end of file + + if (inf === 1 ) return -resultat ; + else return resultat; + } +