From aa5674cf824d6ed4bacc0180e1b7403d2c4abc7e Mon Sep 17 00:00:00 2001 From: Mathilde Jean Date: Fri, 21 Oct 2022 16:01:45 +0200 Subject: [PATCH] trucs --- bob_party/src/core/conversation.test.ts | 71 +++++++++++++++-------- bob_party/src/core/conversation.ts | 36 ++++++------ bob_party/src/core/game.test.ts | 75 +++++++++++++++++++++++++ bob_party/src/core/gameMulti.test.ts | 44 +++++++++++++++ bob_party/src/core/gameMulti.ts | 2 +- bob_party/src/core/gameSolo.test.ts | 75 +++++++++++++++++++++++++ bob_party/src/core/gameSolo.ts | 4 +- bob_party/src/core/message.test.ts | 18 +++--- bob_party/src/core/skin.test.ts | 46 ++++++++++----- bob_party/src/core/users.test.ts | 30 ++++++---- 10 files changed, 324 insertions(+), 77 deletions(-) create mode 100644 bob_party/src/core/game.test.ts create mode 100644 bob_party/src/core/gameMulti.test.ts create mode 100644 bob_party/src/core/gameSolo.test.ts diff --git a/bob_party/src/core/conversation.test.ts b/bob_party/src/core/conversation.test.ts index 11a40a9..dec2b53 100644 --- a/bob_party/src/core/conversation.test.ts +++ b/bob_party/src/core/conversation.test.ts @@ -1,41 +1,68 @@ import { Conversation } from './Conversation'; import { Message } from './Message'; import { User } from './User'; +import { Skin } from './Skin'; -// Instance +// Instances +let conv:Conversation[] = []; +let tab:Skin[] = []; +let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/BobClassic.png'), 0); +let dateBirth = new Date(2010,0o3,0o7); +let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab, conv); +let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab, conv); +let theDate = new Date(2022,10,14); +let theDate2 = new Date(2022,10,13); +let theDate3 = new Date(2022,10,15); +let mess = new Message('Bob Party est le meilleur projet', usr, theDate2); +let tabU:User[] = [usr, usr2]; +let mess2 = new Message('Oui tout à fait', usr2, theDate); +let mess3 = new Message('Mais oui trop de ouf', usr, theDate3); +let tabM:Message[] = [mess, mess2]; +let convo = new Conversation(tabU, tabM, 'the conv'); +let usr3 = new User('00003', 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab, conv); - -// Tests des get -describe('Message get tests', () => { - it('should return Bob Party est le meilleur projet', () => { - expect(mess.getMessageContent()).toBe('Bob Party est le meilleur projet'); +// Get tests +describe('Conversation get tests', () => { + it('should return tabU [usr, usr2] (users)', () => { + expect(convo.getTabUser()).toBe(tabU); + }) + it('should return tabM [mess, mess2] (messages)', () => { + expect(convo.getTabMessage()).toBe(tabM); }) - it('should return usr', () => { - expect(mess.getMessageSender()).toBe(usr); + it('should return the conv', () => { + expect(convo.getName()).toBe('the conv'); }) - it('should return wouhou', () => { - expect(mess.getMessageDate()).toBe(theDate); + it('should return Oui tout à fait (mess2)', () => { + expect(convo.getLastMessage()).toBe('Oui tout à fait'); }) }) -// Set de nouvelles valeurs -mess.setMessageContent('Vive Bob Party'); -mess.setSMessageSender(usr2); -mess.setSMessageDate(theDate2); +// Setting new value +convo.setName('THE conv'); -// Tests de set -describe('Message set tests', () => { - it('should return Vive Bob Party', () => { - expect(mess.getMessageContent()).toBe('Vive Bob Party'); +// Set test +describe('Conversation set test', () => { + it('should return THE conv', () => { + expect(convo.setName).toBe('THE conv'); }) - it('should return usr2', () => { - expect(mess.getMessageSender()).toBe(usr2); +}) + + +// Adding new values +convo.ajouterUser(usr3); +convo.ajouterMessage(mess3); + + +// Add tests +describe('Add test', () => { + it('should return [usr, usr2, usr3] (users)', () => { + expect(convo.getTabUser).toBe([usr, usr2, usr3]); }) - it('should return theDate2', () => { - expect(mess.getMessageDate()).toBe(theDate2); + it('should return Mais oui trop de ouf (mess3)', () => { + expect(convo.getLastMessage()).toBe('Mais oui trop de ouf'); }) }) \ No newline at end of file diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index 76a49cc..856eb3d 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -3,58 +3,58 @@ import { User } from "./user"; export class Conversation{ - private TabUser: User[]; - private TabMessage: Message[]; - private Name: string; + private tabUser: User[]; + private tabMessage: Message[]; + private name: string; /* Constructor of the class */ constructor(tabUser: User[], tabMessage:Message[], name:string){ - this.TabUser=[...tabUser]; - this.TabMessage=[...tabMessage]; - this.Name=name; + this.tabUser=[...tabUser]; + this.tabMessage=[...tabMessage]; + this.name=name; } /* Brief : function returning the messages of a conversation */ - getTabMessage(){ + gettabMessage(){ this.sortMessageDesc(); - return this.TabMessage; + return this.tabMessage; } /* Brief : function returning the users of a conversation */ - getTabUser(){ - return this.TabUser; + gettabUser(){ + return this.tabUser; } /* Brief : function adding an user to a conversation */ ajouterUser(us:User){ - this.TabUser?.push(us); + this.tabUser?.push(us); } /* Brief : function adding a message to a conversation */ ajouterMessage(mess:Message){ - this.TabMessage?.push(mess); + this.tabMessage?.push(mess); this.sortMessageDesc(); } /* Brief : function returning the name to a conversation */ - getName(){ - return this.Name; + getname(){ + return this.name; } /* Brief : function setting the name to a conversation */ - setName(name:string){ - this.Name=name; + setname(name:string){ + this.name=name; } /* Brief : function returning the last message of a conversation */ getLastMessage(){ this.sortMessageDesc(); - return this.TabMessage[0].getMessageContent(); + return this.tabMessage[0].getMessageContent(); } /* Brief : function sorting the messages of a conversation to be in the discussion order */ sortMessageDesc(){ - this.TabMessage.sort( + this.tabMessage.sort( (objA, objB) => objB.getMessageDate().getTime() - objA.getMessageDate().getTime(), ); } diff --git a/bob_party/src/core/game.test.ts b/bob_party/src/core/game.test.ts new file mode 100644 index 0000000..a350c0e --- /dev/null +++ b/bob_party/src/core/game.test.ts @@ -0,0 +1,75 @@ +import { Game } from './Game'; +import { GameSolo } from './GameSolo'; +import { GameMulti } from './GameMulti'; +import { GameCasino } from './GameCasino'; + + +// Instances +let myMap = new Map([ + [50, 3], + [75, 4], + [100, 5], + [150, 6] +]); +let game=new GameSolo("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, myMap); + + +// Get tests +describe('Game get tests', () => { + it('should return bo jeu', () => { + expect(game.getName()).toBe('bo jeu'); + }) + it('should return require(blackjack.jpg)', () => { + expect(game.getImageSource()).toBe(require('bob_party/assets/ImagesJeux/blackjack.jpg')); + }) + it('should return super jeu', () => { + expect(game.getGameSource()).toBe('super jeu'); + }) + it('should return 1', () => { + expect(game.getNbPlayer()).toBe(1); + }) + it('should return myMap', () => { + expect(game.getSoloMap()).toBe(myMap); + }) +}) + + +// Setting new values +game.setGameSource('trop cool le jeu'); +game.setImageSource(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); +game.setName('beau jeu'); +game.setNbPlayer(2); + + +// Set tests +describe('Game set tests', () => { + it('should return beau jeu', () => { + expect(game.getName()).toBe('beau jeu'); + }) + it('should return require(JeuDeDame.jpg)', () => { + expect(game.getImageSource).toBe(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); + }) + it('should return trop cool le jeu', () => { + expect(game.getGameSource()).toBe('trop cool le jeu'); + }) + it('should return trop cool le jeu', () => { + expect(game.getNbPlayer()).toBe(2); + }) +}) + + +// CoinsWithPoints test +describe('CoinWithPoints tests', () => { + it('should return 3', () => { + expect(game.CoinsWithPoints(50)).toBe(3); + }) + it('should return 4', () => { + expect(game.CoinsWithPoints(75)).toBe(4); + }) + it('should return 5', () => { + expect(game.CoinsWithPoints(100)).toBe(5); + }) + it('should return 6', () => { + expect(game.CoinsWithPoints(150)).toBe(6); + }) +}) \ No newline at end of file diff --git a/bob_party/src/core/gameMulti.test.ts b/bob_party/src/core/gameMulti.test.ts new file mode 100644 index 0000000..53bd571 --- /dev/null +++ b/bob_party/src/core/gameMulti.test.ts @@ -0,0 +1,44 @@ +import { Game } from './Game'; +import { GameMulti } from './gameMulti'; + + +// Instances +let myMap = new Map([ + [50, 3], + [75, 4], + [100, 5], + [150, 6] +]); +let game = new GameMulti("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, myMap); + + +// Get tests +describe('Game get tests', () => { + it('should return myMap', () => { + expect(game.getMultiMap()).toBe(myMap); + }) +}) + + +// Setting new values +game.setGameSource('trop cool le jeu'); +game.setImageSource(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); +game.setName('beau jeu'); +game.setNbPlayer(2); + + +// Set tests +describe('Game set tests', () => { + it('should return beau jeu', () => { + expect(game.getName()).toBe('beau jeu'); + }) + it('should return require(JeuDeDame.jpg)', () => { + expect(game.getImageSource).toBe(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); + }) + it('should return trop cool le jeu', () => { + expect(game.getGameSource()).toBe('trop cool le jeu'); + }) + it('should return trop cool le jeu', () => { + expect(game.getNbPlayer()).toBe(2); + }) +}) \ No newline at end of file diff --git a/bob_party/src/core/gameMulti.ts b/bob_party/src/core/gameMulti.ts index 4555331..13a1ad6 100644 --- a/bob_party/src/core/gameMulti.ts +++ b/bob_party/src/core/gameMulti.ts @@ -19,7 +19,7 @@ export class GameMulti extends Game{ let coins; for (let key of this.RankToCoins.keys()){ coins = this.RankToCoins.get(key); - if (rank==key ){ + if (rank==key){ return coins; } } diff --git a/bob_party/src/core/gameSolo.test.ts b/bob_party/src/core/gameSolo.test.ts new file mode 100644 index 0000000..a350c0e --- /dev/null +++ b/bob_party/src/core/gameSolo.test.ts @@ -0,0 +1,75 @@ +import { Game } from './Game'; +import { GameSolo } from './GameSolo'; +import { GameMulti } from './GameMulti'; +import { GameCasino } from './GameCasino'; + + +// Instances +let myMap = new Map([ + [50, 3], + [75, 4], + [100, 5], + [150, 6] +]); +let game=new GameSolo("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, myMap); + + +// Get tests +describe('Game get tests', () => { + it('should return bo jeu', () => { + expect(game.getName()).toBe('bo jeu'); + }) + it('should return require(blackjack.jpg)', () => { + expect(game.getImageSource()).toBe(require('bob_party/assets/ImagesJeux/blackjack.jpg')); + }) + it('should return super jeu', () => { + expect(game.getGameSource()).toBe('super jeu'); + }) + it('should return 1', () => { + expect(game.getNbPlayer()).toBe(1); + }) + it('should return myMap', () => { + expect(game.getSoloMap()).toBe(myMap); + }) +}) + + +// Setting new values +game.setGameSource('trop cool le jeu'); +game.setImageSource(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); +game.setName('beau jeu'); +game.setNbPlayer(2); + + +// Set tests +describe('Game set tests', () => { + it('should return beau jeu', () => { + expect(game.getName()).toBe('beau jeu'); + }) + it('should return require(JeuDeDame.jpg)', () => { + expect(game.getImageSource).toBe(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); + }) + it('should return trop cool le jeu', () => { + expect(game.getGameSource()).toBe('trop cool le jeu'); + }) + it('should return trop cool le jeu', () => { + expect(game.getNbPlayer()).toBe(2); + }) +}) + + +// CoinsWithPoints test +describe('CoinWithPoints tests', () => { + it('should return 3', () => { + expect(game.CoinsWithPoints(50)).toBe(3); + }) + it('should return 4', () => { + expect(game.CoinsWithPoints(75)).toBe(4); + }) + it('should return 5', () => { + expect(game.CoinsWithPoints(100)).toBe(5); + }) + it('should return 6', () => { + expect(game.CoinsWithPoints(150)).toBe(6); + }) +}) \ No newline at end of file diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index 64cecdb..3d88006 100644 --- a/bob_party/src/core/gameSolo.ts +++ b/bob_party/src/core/gameSolo.ts @@ -14,12 +14,12 @@ export class GameSolo extends Game{ return this.PtsToCoins; } - //Returns the gained depending on the number of points + //Returns the gain depending on the number of points CoinsWithPoints(nbPoints:number){ let coins; for (let key of this.PtsToCoins.keys()){ coins = this.PtsToCoins.get(key); - if (nbPoints { it('should return Bob Party est le meilleur projet', () => { expect(mess.getMessageContent()).toBe('Bob Party est le meilleur projet'); @@ -29,13 +29,13 @@ describe('Message get tests', () => { }) -// Set de nouvelles valeurs +// Setting new values mess.setMessageContent('Vive Bob Party'); -mess.setSMessageSender(usr2); -mess.setSMessageDate(theDate2); +mess.setMessageSender(usr2); +mess.setMessageDate(theDate2); -// Tests de set +// Set tests describe('Message set tests', () => { it('should return Vive Bob Party', () => { expect(mess.getMessageContent()).toBe('Vive Bob Party'); diff --git a/bob_party/src/core/skin.test.ts b/bob_party/src/core/skin.test.ts index bd911dc..fd92869 100644 --- a/bob_party/src/core/skin.test.ts +++ b/bob_party/src/core/skin.test.ts @@ -1,34 +1,50 @@ import { Skin } from './Skin'; -/* + + // Instance +let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/BobClassic.png'), 0); + -let classique = new Skin('Classique', 'wouhou'); +// Get tests -// Tests des get describe('Skin get tests', () => { - it('should return Classique', () => { - expect(classique.getSkinName()).toBe('Classique'); + it('should return S0001', () => { + expect(classique.getSkinId()).toBe('S0001'); + }) + it('should return Bob', () => { + expect(classique.getSkinName()).toBe('Bob'); + }) + it('should return require(BobClassic.png)', () => { + expect(classique.getSkinSource()).toBe(require('bob_party/assets/BobsSkins/BobClassic.png')); }) - it('should return wouhou', () => { - expect(classique.getSkinSource()).toBe('wouhou'); + it('should return 0', () => { + expect(classique.getSkinCost()).toBe(0); }) }) -// Set de nouvelles valeurs -classique.setSkinName('The Classique'); -classique.setSkinSource('The wouhou'); +// Setting new values + +classique.setSkinName('Bob Blue'); +classique.setSkinCost(100); +classique.setSkinSource(require('bob_party/assets/BobsSkins/BobBlue.png')); + + + +// Set tests -// Tests de set describe('Skin set tests', () => { it('should return The Classique', () => { - expect(classique.getSkinName()).toBe('The Classique'); + expect(classique.getSkinName()).toBe('Bob blue'); + }) + it('should return require(BobBlue.png)', () => { + expect(classique.getSkinSource()).toBe(require('bob_party/assets/BobsSkins/BobBlue.png')); }) - it('should return The wouhou', () => { - expect(classique.getSkinSource()).toBe('The wouhou'); + it('should return 100', () => { + expect(classique.getSkinCost()).toBe(0); }) -})*/ \ No newline at end of file +}) \ No newline at end of file diff --git a/bob_party/src/core/users.test.ts b/bob_party/src/core/users.test.ts index c46a712..0f1e5ca 100644 --- a/bob_party/src/core/users.test.ts +++ b/bob_party/src/core/users.test.ts @@ -4,15 +4,15 @@ import { Conversation } from './Conversation'; // Instances -let classique = new Skin('Classique', 'wouhou'); -let kikou = new Skin('Kikou', 'trop beau'); +let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/BobClassic.png'), 0); +let blue = new Skin("S0002", "Bob Blue", require('bob_party/assets/BobsSkins/BobBlue.png'), 100); let tab:Skin[] = []; -let tab2:Skin[] = [classique, kikou]; +let tab2:Skin[] = [classique, blue]; let dateBirth = new Date(2010,0o3,0o7); let dateBirth2 = new Date(2009,0o3,0o7); let conv:Conversation[] = []; let conv2:Conversation[] = []; -let usr = new User('00001', 'Killyan', 'France', 'M', dateBirth, 0, 0, classique, tab, conv); +let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab, conv); // Tests des get @@ -23,6 +23,9 @@ describe('User get tests', () => { it('should return Killyan', () => { expect(usr.getUsername()).toBe('Killyan'); }) + it('should return password', () => { + expect(usr.getPassword()).toBe('password'); + }) it('should return France', () => { expect(usr.getNationality()).toBe('France'); }) @@ -38,6 +41,9 @@ describe('User get tests', () => { it('should return 0', () => { expect(usr.getTotalCoins()).toBe(0); }) + it('should return 0', () => { + expect(usr.getGamePlayed()).toBe(0); + }) it('should return classique', () => { expect(usr.getCurrentSkin()).toBe(classique); }) @@ -51,26 +57,27 @@ describe('User get tests', () => { // Set de nouvelles valeurs -usr.setId('00002'); usr.setUsername('BgKillyan'); +usr.setPassword('1234'); usr.setNationality('Marseille'); usr.setSexe('F'); usr.setDateOfBirth(dateBirth2); usr.setCurrentCoins(2); usr.setTotalCoins(2); -usr.setCurrentSkin(kikou); +usr.setGamePlayed(4); +usr.setCurrentSkin(blue); usr.setTabSkin(tab2); usr.setTabConv(conv2); // Tests des set describe('User get tests', () => { - it('should return 00002', () => { - expect(usr.getId()).toBe('00002'); - }) it('should return BgKillyan', () => { expect(usr.getUsername()).toBe('BgKillyan'); }) + it('should return 1234', () => { + expect(usr.getPassword()).toBe('1234'); + }) it('should return Marseille', () => { expect(usr.getNationality()).toBe('Marseille'); }) @@ -86,8 +93,11 @@ describe('User get tests', () => { it('should return 2', () => { expect(usr.getTotalCoins()).toBe(2); }) + it('should return 4', () => { + expect(usr.getGamePlayed()).toBe(4); + }) it('should return kikou', () => { - expect(usr.getCurrentSkin()).toBe(kikou); + expect(usr.getCurrentSkin()).toBe(blue); }) it('should return tab2', () => { expect(usr.getTabSkin()).toBe(tab2);