From d7c9b36ce2c9f94d0248f3bfeed331a281e2b58b Mon Sep 17 00:00:00 2001 From: majean5 Date: Fri, 18 Nov 2022 10:40:04 +0100 Subject: [PATCH] tests unitaires (corrections, ajouts) --- bob_party/src/core/match.ts | 2 +- bob_party/src/core/matchCasino.ts | 4 +-- bob_party/src/core/matchMulti.ts | 4 +-- bob_party/src/core/matchSolo.ts | 4 +-- bob_party/src/core/tests/conversation.test.ts | 12 ++++++++ bob_party/src/core/tests/game.test.ts | 4 --- bob_party/src/core/tests/gameCasino.test.ts | 13 ++++++-- bob_party/src/core/tests/gameMulti.test.ts | 30 +++++++++++++++---- bob_party/src/core/tests/gameSolo.test.ts | 23 +++++++++++++- bob_party/src/core/tests/matchSolo.test.ts | 23 +++++++++++++- bob_party/src/core/tests/message.test.ts | 4 +-- 11 files changed, 101 insertions(+), 22 deletions(-) diff --git a/bob_party/src/core/match.ts b/bob_party/src/core/match.ts index 3d459a2..4ecfacc 100644 --- a/bob_party/src/core/match.ts +++ b/bob_party/src/core/match.ts @@ -67,6 +67,6 @@ export abstract class Match{ } - abstract updatePostMatch(user:User, coins:number):void; + abstract updatePostMatch(user:User, points:number):void; } \ No newline at end of file diff --git a/bob_party/src/core/matchCasino.ts b/bob_party/src/core/matchCasino.ts index 0c2e2bc..3eb4a4b 100644 --- a/bob_party/src/core/matchCasino.ts +++ b/bob_party/src/core/matchCasino.ts @@ -10,9 +10,9 @@ export class MatchMulti extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, coins: number): void { + updatePostMatch(user:User, points: number): void { const manage= new ManagerCoinsUser(); - manage.addCoins(user, this.getGame().coinsCalculator(coins)); + manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/core/matchMulti.ts b/bob_party/src/core/matchMulti.ts index 0bfde7a..83fa33b 100644 --- a/bob_party/src/core/matchMulti.ts +++ b/bob_party/src/core/matchMulti.ts @@ -10,8 +10,8 @@ export class MatchMulti extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, coins: number): void { + updatePostMatch(user:User, points: number): void { const manage= new ManagerCoinsUser(); - manage.addCoins(user, this.getGame().coinsCalculator(coins)); + manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/core/matchSolo.ts b/bob_party/src/core/matchSolo.ts index 80f9e43..fdb281c 100644 --- a/bob_party/src/core/matchSolo.ts +++ b/bob_party/src/core/matchSolo.ts @@ -10,8 +10,8 @@ export class MatchSolo extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, coins: number): void { + updatePostMatch(user:User, points: number): void { const manage= new ManagerCoinsUser(); - manage.addCoins(user, this.getGame().coinsCalculator(coins)); + manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/core/tests/conversation.test.ts b/bob_party/src/core/tests/conversation.test.ts index 82f9062..c010c76 100644 --- a/bob_party/src/core/tests/conversation.test.ts +++ b/bob_party/src/core/tests/conversation.test.ts @@ -1,3 +1,4 @@ +import exp from 'constants'; import { Conversation } from '../Conversation'; import { Message } from '../Message'; import { Skin } from '../Skin'; @@ -42,6 +43,8 @@ describe('Conversation get tests', () => { // Setting new value convo.setName('THE conv'); +convo.ajouterUser(usr3); +convo.ajouterMessage(mess3); // Set test @@ -49,4 +52,13 @@ describe('Conversation set test', () => { it('should return THE conv', () => { expect(convo.setName).toBe('THE conv'); }) + it('should return tabU [usr, usr2, usr3] (users)', () => { + expect(convo.getTabUser()).toBe(tabU); + }) + it('should return tabM [mess, mess2, mess3] (messages)', () => { + expect(convo.getTabMessage()).toBe(tabM); + }) + 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/tests/game.test.ts b/bob_party/src/core/tests/game.test.ts index 3d1bc42..1912f95 100644 --- a/bob_party/src/core/tests/game.test.ts +++ b/bob_party/src/core/tests/game.test.ts @@ -37,7 +37,6 @@ describe('GameSolo get tests', () => { // Setting new values -game.setId('newId'); game.setGameSource('trop cool le jeu'); game.setImageSource(require('bob_party/assets/ImagesJeux/JeuDeDame.jpg')); game.setName('beau jeu'); @@ -47,9 +46,6 @@ game.setNbPlayerMax(3); // Set tests describe('GameSolo set tests', () => { - it('should return newId', () => { - expect(game.getId()).toBe('newId'); - }) it('should return beau jeu', () => { expect(game.getName()).toBe('beau jeu'); }) diff --git a/bob_party/src/core/tests/gameCasino.test.ts b/bob_party/src/core/tests/gameCasino.test.ts index 6900cd3..27ffeb9 100644 --- a/bob_party/src/core/tests/gameCasino.test.ts +++ b/bob_party/src/core/tests/gameCasino.test.ts @@ -3,7 +3,7 @@ import { GameCasino } from '../GameCasino'; // Instances -let game = new GameCasino("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 5); +let game = new GameCasino("GC001", "bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 5); // Get tests @@ -50,4 +50,13 @@ describe('GameCasino set tests', () => { }) it('should return 4', () => { expect(game.getNbPlayerMin()).toBe(4); - }) \ No newline at end of file + }) +}) + + +// Coins Calculator Tests +describe('Coins calculator tests', () => { + it('should return 200', () => { + expect(game.coinsCalculator(200)).toBe(200); + }) +}) \ No newline at end of file diff --git a/bob_party/src/core/tests/gameMulti.test.ts b/bob_party/src/core/tests/gameMulti.test.ts index 1c74a48..c38af68 100644 --- a/bob_party/src/core/tests/gameMulti.test.ts +++ b/bob_party/src/core/tests/gameMulti.test.ts @@ -6,16 +6,19 @@ import { GameCasino } from '../GameCasino'; // Instances let myMap = new Map([ - [50, 3], - [75, 4], - [100, 5], - [150, 6] + [4, 1], + [3, 3], + [2, 5], + [1, 10] ]); -let game = new GameMulti("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 5, myMap); +let game = new GameMulti("GM001", "bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 5, myMap); // Get tests describe('GameMuti get tests', () => { + it('should return GM001', () => { + expect(game.getId()).toBe('GM001'); + }) it('should return bo jeu', () => { expect(game.getName()).toBe('bo jeu'); }) @@ -62,4 +65,21 @@ describe('GameMulti set tests', () => { it('should return 4', () => { expect(game.getNbPlayerMin()).toBe(4); }) +}) + + +// Coins Calculator tests +describe('Coins calculator tests', () => { + it('should return 1', () => { + expect(game.coinsCalculator(4)).toBe(1); + }) + it('should return 3', () => { + expect(game.coinsCalculator(3)).toBe(3); + }) + it('should return 5', () => { + expect(game.coinsCalculator(2)).toBe(5); + }) + it('should return 10', () => { + expect(game.coinsCalculator(1)).toBe(10); + }) }) \ No newline at end of file diff --git a/bob_party/src/core/tests/gameSolo.test.ts b/bob_party/src/core/tests/gameSolo.test.ts index 27e59b7..dbd2332 100644 --- a/bob_party/src/core/tests/gameSolo.test.ts +++ b/bob_party/src/core/tests/gameSolo.test.ts @@ -1,3 +1,4 @@ +import exp from 'constants'; import { GameSolo } from '../GameSolo'; // Instances @@ -7,11 +8,14 @@ let myMap = new Map([ [100, 5], [150, 6] ]); -let game=new GameSolo("bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 1, myMap); +let game=new GameSolo("G0001", "bo jeu", require('bob_party/assets/ImagesJeux/blackjack.jpg'), "super jeu", 1, 1, myMap); // Get tests describe('GameSolo get tests', () => { + it('should return G0001', () => { + expect(game.getId()).toBe('G0001'); + }) it('should return bo jeu', () => { expect(game.getName()).toBe('bo jeu'); }) @@ -58,4 +62,21 @@ describe('GameSolo set tests', () => { it('should return 3', () => { expect(game.getNbPlayerMax()).toBe(3); }) +}) + + +// Coins Calculator tests +describe('Coins calculator tests', () => { + it('should return 3', () => { + expect(game.coinsCalculator(50)).toBe(3); + }) + it('should return 4', () => { + expect(game.coinsCalculator(75)).toBe(4); + }) + it('should return 5', () => { + expect(game.coinsCalculator(100)).toBe(5); + }) + it('should return 6', () => { + expect(game.coinsCalculator(150)).toBe(6); + }) }) \ No newline at end of file diff --git a/bob_party/src/core/tests/matchSolo.test.ts b/bob_party/src/core/tests/matchSolo.test.ts index 89c17ac..94f4d72 100644 --- a/bob_party/src/core/tests/matchSolo.test.ts +++ b/bob_party/src/core/tests/matchSolo.test.ts @@ -11,8 +11,8 @@ let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/Bob let blue = new Skin("S0002", "Bob Blue", require('bob_party/assets/BobsSkins/BobBlue.png'), 100); let tab:Skin[] = [classique, blue]; let dateBirth = new Date(2010,0o3,0o7); -let conv:Conversation[] = []; let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); +let usr2 = new User('00002', 'Rémi', 'pwd', 'Martinique', 'M', dateBirth, 0, 0, 0, classique, tab); let tabU:User[] = [usr]; let myMap = new Map([ [50, 3], @@ -60,4 +60,25 @@ describe('Match set tests', () => { it('should return game2', () => { expect(match.getGame).toBe(game2); }) +}) + + +// Update Post-Match tests +describe('Update post-match tests', () => { + it('should return 3', () => { + match.updatePostMatch(tabU[0],50); + expect(tabU[0].getCurrentCoins()).toBe(3); + }) + it('should return 8', () => { + match.updatePostMatch(tabU[0],100); + expect(tabU[0].getCurrentCoins()).toBe(8); + }) + it('should return 4', () => { + match.updatePostMatch(usr2,75); + expect(usr2.getCurrentCoins()).toBe(4); + }) + it('should return 10', () => { + match.updatePostMatch(usr2,150); + expect(usr2.getCurrentCoins()).toBe(10); + }) }) \ No newline at end of file diff --git a/bob_party/src/core/tests/message.test.ts b/bob_party/src/core/tests/message.test.ts index a157f65..7d16675 100644 --- a/bob_party/src/core/tests/message.test.ts +++ b/bob_party/src/core/tests/message.test.ts @@ -8,8 +8,8 @@ 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 usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); +let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab); let theDate = new Date(2022,10,14); let theDate2 = new Date(2022,10,13); let mess = new Message('Bob Party est le meilleur projet', usr, theDate);