From 580ebb3d14524f2785913ba2ee382e38c0be8709 Mon Sep 17 00:00:00 2001 From: Raphael LACOTE Date: Tue, 28 Feb 2023 11:42:58 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A9criture=20des=20Tests=20unitaire=20et=20r?= =?UTF-8?q?ectification=20d'un=20bug=20de=20la=20fonction=20isHyperset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/Console.html | 5 ++-- src/Console/main.js | 4 +-- src/Console/test.js | 61 ++++++++++++++++++++++++++++++++++++++++ src/Model/Const.js | 4 +-- src/algo.js | 11 +++++--- test/testsIsHyperset.js | 61 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 src/Console/test.js create mode 100644 test/testsIsHyperset.js diff --git a/src/Console/Console.html b/src/Console/Console.html index 23876d4..b772f30 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -11,7 +11,6 @@

Console - test

-
@@ -25,7 +24,9 @@ - + + + \ No newline at end of file diff --git a/src/Console/main.js b/src/Console/main.js index fc99f74..68242e4 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -2,7 +2,7 @@ //import('../Model/Card5'); //import {Card} from '../Model/Card'; -/*console.log("~#Test#~"); +console.log("~#Test#~"); let card4 = new Card4WithoutOutline('red','2','losange','full'); console.group('Carte 4 attributes'); console.log(`carte de 4 elements : ${card4.color}`); @@ -110,7 +110,7 @@ for (let i=0; i<26;i++){ console.log(e.getAttributes()); }); } -deck.checkSet(customCard);*/ +deck.checkSet(customCard); // CREATE HYPERSET diff --git a/src/Console/test.js b/src/Console/test.js new file mode 100644 index 0000000..87d1816 --- /dev/null +++ b/src/Console/test.js @@ -0,0 +1,61 @@ +let card1 = new Card4WithoutOutline('red', 3, 'wave', 'full'); +let card2 = new Card4WithoutOutline('red', 3, 'oval', 'empty'); +let card3 = new Card4WithoutOutline('blue', 2, 'oval', 'full'); +let card4 = new Card4WithoutOutline('green', 1, 'wave', 'pointed'); +let card5 = new Card4WithoutOutline('green', 1, 'wave', 'full'); + +deckA = []; +deckB = []; +deckC = []; + +deckA.push(card1, card2); +deckB.push(card3, card4); +deckC.push(card3, card5); + +console.assert(isHyperset(deckA, deckB) == true); +console.assert(isHyperset(deckA, deckC) == false); + +let BcardG1 = new Card5('red', 4, 'oval', 'empty', 'fullO'); +let BcardG2 = new Card5('red', 3, 'oval', 'full', 'fullO'); +let BcardG3 = new Card5('red', 2, 'oval', 'squared', 'fullO'); +let BcardG4 = new Card5('red', 1, 'oval', 'pointed', 'fullO'); + +let BcardD1 = new Card5('green', 3, 'oval', 'pointed', 'cloudy'); +let BcardD2 = new Card5('blue', 2, 'oval', 'squared', 'sharpy'); +let BcardD3 = new Card5('purple', 4, 'oval', 'full', 'hyphen'); +let BcardD4 = new Card5('orange', 1, 'oval', 'empty', 'dotted'); +let BcardD5 = new Card5('purple', 4, 'oval', 'stripped', 'hyphen'); + +BdeckA = []; +BdeckB = []; +BdeckC = []; +BdeckD = []; +BdeckE = []; + + +BdeckA.push(BcardG1, BcardG2, BcardG3); +BdeckB.push(BcardD1, BcardD2, BcardD3); +BdeckC.push(BcardD1, BcardD2, BcardD5); +BdeckD.push(BcardG1, BcardG2, BcardG3,BcardG4); +BdeckE.push(BcardD1, BcardD2, BcardD3,BcardD4); + +console.assert(isHyperset(BdeckA, BdeckB) == true); +console.assert(isHyperset(BdeckA, BdeckC) == false); +console.assert(isHyperset(BdeckD, BdeckE) == true); + + +let Ccard1 = new Card4WithoutShape('blue', 3, 'empty', 'cloudy'); +let Ccard2 = new Card4WithoutShape('red', 3, 'empty', 'cloudy'); +let Ccard3 = new Card4WithoutShape('green', 3, 'empty', 'cloudy'); +let Ccard4 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard5 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard6 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); + +CdeckA = []; +CdeckB = []; + +CdeckA.push(Ccard1, Ccard2, Ccard3); +CdeckB.push(Ccard4, Ccard5, Ccard6); + +console.assert(isHyperset(CdeckA, CdeckB) == false); + diff --git a/src/Model/Const.js b/src/Model/Const.js index 3cab74b..801313e 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -2,7 +2,7 @@ const tabColor = ['red','purple','green','blue','orange']; const tabNumber = [1,2,3,4,5]; const tabShape = ['diamond','oval','wave','star','triangle']; const tabFilling = ['empty','stripped','full','pointed','squared']; -const tabOutline = ['fullO','dotted ','hyphen','cloudy','sharpy']; +const tabOutline = ['fullO','dotted','hyphen','cloudy','sharpy']; const ATTRIBUTES = [tabColor, tabNumber, tabShape, tabFilling, tabOutline] -//Rename tabOutline \ No newline at end of file +//Rename tabOutline first attributs \ No newline at end of file diff --git a/src/algo.js b/src/algo.js index 19b7650..b739892 100644 --- a/src/algo.js +++ b/src/algo.js @@ -203,7 +203,9 @@ function createCard(cards) { //S'ils sont tous égaux if (listeInter.every(element => element === listeInter[0])) { - carteFinale.push(listeInter[0]); + l = [] + l.push(listeInter[0]) + carteFinale.push(l); } else { //S'ils sont tous différents @@ -226,10 +228,11 @@ function isHyperset(cardsLeft, cardsRight) { right = createCard(cardsRight) let verif; - for (let i = 0; i < left[0].length; i++) { + for (let i = 0; i < left.length; i++) { + verif = false; - left.forEach(elementG => { - right.forEach(elementD => { + left[i].forEach(elementG => { + right[i].forEach(elementD => { if (elementD == elementG) { verif=true } diff --git a/test/testsIsHyperset.js b/test/testsIsHyperset.js new file mode 100644 index 0000000..9c4d9ca --- /dev/null +++ b/test/testsIsHyperset.js @@ -0,0 +1,61 @@ +let card1 = new Card4WithoutOutline('red', 3, 'wave', 'full'); +let card2 = new Card4WithoutOutline('red', 3, 'oval', 'empty'); +let card3 = new Card4WithoutOutline('blue', 2, 'oval', 'full'); +let card4 = new Card4WithoutOutline('green', 1, 'wave', 'pointed'); +let card5 = new Card4WithoutOutline('green', 1, 'wave', 'full'); + +deckA = []; +deckB = []; +deckC = []; + +deckA.push(card1, card2); +deckB.push(card3, card4); +deckC.push(card3, card5); + +console.assert(isHyperset(deckA, deckB) == true); +console.assert(isHyperset(deckA, deckC) == false); + +let BcardG1 = new Card5('red', 4, 'oval', 'empty', 'fullO'); +let BcardG2 = new Card5('red', 3, 'oval', 'full', 'fullO'); +let BcardG3 = new Card5('red', 2, 'oval', 'squared', 'fullO'); +let BcardG4 = new Card5('red', 1, 'oval', 'pointed', 'fullO'); + +let BcardD1 = new Card5('green', 3, 'oval', 'pointed', 'cloudy'); +let BcardD2 = new Card5('blue', 2, 'oval', 'squared', 'sharpy'); +let BcardD3 = new Card5('purple', 4, 'oval', 'full', 'hyphen'); +let BcardD4 = new Card5('orange', 1, 'oval', 'empty', 'dotted'); +let BcardD5 = new Card5('purple', 4, 'oval', 'stripped', 'hyphen'); + +BdeckA = []; +BdeckB = []; +BdeckC = []; +BdeckD = []; +BdeckE = []; + + +BdeckA.push(BcardG1, BcardG2, BcardG3); +BdeckB.push(BcardD1, BcardD2, BcardD3); +BdeckC.push(BcardD1, BcardD2, BcardD5); +BdeckD.push(BcardG1, BcardG2, BcardG3, BcardG4); +BdeckE.push(BcardD1, BcardD2, BcardD3, BcardD4); + +console.assert(isHyperset(BdeckA, BdeckB) == true); +console.assert(isHyperset(BdeckA, BdeckC) == false); +console.assert(isHyperset(BdeckD, BdeckE) == true); + + +let Ccard1 = new Card4WithoutShape('blue', 3, 'empty', 'cloudy'); +let Ccard2 = new Card4WithoutShape('red', 3, 'empty', 'cloudy'); +let Ccard3 = new Card4WithoutShape('green', 3, 'empty', 'cloudy'); +let Ccard4 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard5 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard6 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); + +CdeckA = []; +CdeckB = []; + +CdeckA.push(Ccard1, Ccard2, Ccard3); +CdeckB.push(Ccard4, Ccard5, Ccard6); + +console.assert(isHyperset(CdeckA, CdeckB) == false); +