Added score tests

This commit is contained in:
Arnaud Vergnet 2020-03-23 19:31:02 +01:00
parent 8dc620b987
commit e6fcbdb165
2 changed files with 75 additions and 0 deletions

View file

@ -22,6 +22,10 @@ export default class ScoreManager {
return this.#level;
}
getLevelProgression(): number {
return this.#levelProgression;
}
incrementScore() {
this.#score++;
}

View 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);
});