forked from vergnet/application-amicale
Added score tests
This commit is contained in:
parent
8dc620b987
commit
e6fcbdb165
2 changed files with 75 additions and 0 deletions
|
@ -22,6 +22,10 @@ export default class ScoreManager {
|
||||||
return this.#level;
|
return this.#level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLevelProgression(): number {
|
||||||
|
return this.#levelProgression;
|
||||||
|
}
|
||||||
|
|
||||||
incrementScore() {
|
incrementScore() {
|
||||||
this.#score++;
|
this.#score++;
|
||||||
}
|
}
|
||||||
|
|
71
screens/Tetris/__tests__/ScoreManager.test.js
Normal file
71
screens/Tetris/__tests__/ScoreManager.test.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import React from 'react';
|
||||||
|
import ScoreManager from "../ScoreManager";
|
||||||
|
|
||||||
|
|
||||||
|
test('incrementScore', () => {
|
||||||
|
let scoreManager = new ScoreManager();
|
||||||
|
expect(scoreManager.getScore()).toBe(0);
|
||||||
|
scoreManager.incrementScore();
|
||||||
|
expect(scoreManager.getScore()).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('addLinesRemovedPoints', () => {
|
||||||
|
let scoreManager = new ScoreManager();
|
||||||
|
scoreManager.addLinesRemovedPoints(0);
|
||||||
|
scoreManager.addLinesRemovedPoints(5);
|
||||||
|
expect(scoreManager.getScore()).toBe(0);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(0);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(1);
|
||||||
|
expect(scoreManager.getScore()).toBe(40);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(1);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(2);
|
||||||
|
expect(scoreManager.getScore()).toBe(140);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(4);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(3);
|
||||||
|
expect(scoreManager.getScore()).toBe(440);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(9);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(4);
|
||||||
|
expect(scoreManager.getScore()).toBe(1640);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(17);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('canLevelUp', () => {
|
||||||
|
let scoreManager = new ScoreManager();
|
||||||
|
expect(scoreManager.canLevelUp()).toBeFalse();
|
||||||
|
expect(scoreManager.getLevel()).toBe(0);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(0);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(1);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeTrue();
|
||||||
|
expect(scoreManager.getLevel()).toBe(1);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(1);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(1);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeFalse();
|
||||||
|
expect(scoreManager.getLevel()).toBe(1);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(2);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(2);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeFalse();
|
||||||
|
expect(scoreManager.getLevel()).toBe(1);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(5);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(1);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeTrue();
|
||||||
|
expect(scoreManager.getLevel()).toBe(2);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(1);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(4);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeFalse();
|
||||||
|
expect(scoreManager.getLevel()).toBe(2);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(9);
|
||||||
|
|
||||||
|
scoreManager.addLinesRemovedPoints(2);
|
||||||
|
expect(scoreManager.canLevelUp()).toBeTrue();
|
||||||
|
expect(scoreManager.getLevel()).toBe(3);
|
||||||
|
expect(scoreManager.getLevelProgression()).toBe(2);
|
||||||
|
});
|
Loading…
Reference in a new issue