mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
refactor(stats): Address PR comments
This commit is contained in:
@@ -1,58 +1,64 @@
|
||||
var sinon = require('sinon');
|
||||
var chai = require("chai")
|
||||
chai.use(require("sinon-chai"))
|
||||
var expect = chai.expect
|
||||
import {
|
||||
maxHealth,
|
||||
maxLevel,
|
||||
capByLevel,
|
||||
tnl,
|
||||
diminishingReturns,
|
||||
} from '../../common/script/index';
|
||||
|
||||
var shared = require('../../common/script/index.js');
|
||||
describe('helper functions used in stat calculations', () => {
|
||||
|
||||
describe('helper functions used in stat calculations', function() {
|
||||
|
||||
var HEALTH_CAP = 50;
|
||||
var LEVEL_CAP = 100;
|
||||
var LEVEL = 57;
|
||||
var BONUS = 600;
|
||||
var MAXIMUM = 200;
|
||||
var HALFWAY = 75;
|
||||
|
||||
it('provides a maximum Health value', function() {
|
||||
expect(shared.maxHealth).to.eql(HEALTH_CAP);
|
||||
});
|
||||
|
||||
describe('maximum level cap', function() {
|
||||
it('returns a maximum level for attribute gain', function() {
|
||||
expect(shared.maxLevel).to.eql(LEVEL_CAP);
|
||||
});
|
||||
|
||||
it('returns level given if below cap', function() {
|
||||
expect(shared.capByLevel(LEVEL)).to.eql(LEVEL);
|
||||
});
|
||||
|
||||
it('returns level given if equal to cap', function() {
|
||||
expect(shared.capByLevel(LEVEL_CAP)).to.eql(LEVEL_CAP);
|
||||
});
|
||||
|
||||
it('returns level cap if above cap', function() {
|
||||
expect(shared.capByLevel(LEVEL_CAP + LEVEL)).to.eql(LEVEL_CAP);
|
||||
describe('maxHealth', () => {
|
||||
it('provides a maximum Health value', () => {
|
||||
const HEALTH_CAP = 50;
|
||||
expect(maxHealth).to.eql(HEALTH_CAP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Experience to next level', function() {
|
||||
it('increases Experience target from one level to the next', function() {
|
||||
expect(shared.tnl(LEVEL + 1)).to.be.greaterThan(shared.tnl(LEVEL));
|
||||
const LEVEL_CAP = 100;
|
||||
const LEVEL = 57;
|
||||
|
||||
describe('maxLevel', () => {
|
||||
it('returns a maximum level for attribute gain', () => {
|
||||
expect(maxLevel).to.eql(LEVEL_CAP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('diminishing returns', function() {
|
||||
it('provides a value under the maximum, given a bonus and maximum', function() {
|
||||
expect(shared.diminishingReturns(BONUS,MAXIMUM)).to.be.lessThan(MAXIMUM);
|
||||
describe('capByLevel', () => {
|
||||
it('returns level given if below cap', () => {
|
||||
expect(capByLevel(LEVEL)).to.eql(LEVEL);
|
||||
});
|
||||
|
||||
it('provides a value under the maximum, given a bonus, maximum, and halfway point', function() {
|
||||
expect(shared.diminishingReturns(BONUS,MAXIMUM,HALFWAY)).to.be.lessThan(MAXIMUM);
|
||||
it('returns level given if equal to cap', () => {
|
||||
expect(capByLevel(LEVEL_CAP)).to.eql(LEVEL_CAP);
|
||||
});
|
||||
|
||||
it('provides a different curve if a halfway point is defined', function() {
|
||||
expect(shared.diminishingReturns(BONUS,MAXIMUM,HALFWAY)).to.not.eql(shared.diminishingReturns(BONUS,MAXIMUM));
|
||||
it('returns level cap if above cap', () => {
|
||||
expect(capByLevel(LEVEL_CAP + LEVEL)).to.eql(LEVEL_CAP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toNextLevel', () => {
|
||||
it('increases Experience target from one level to the next', () => {
|
||||
expect(tnl(LEVEL + 1)).to.be.greaterThan(shared.tnl(LEVEL));
|
||||
});
|
||||
});
|
||||
|
||||
describe('diminishingReturns', () => {
|
||||
const BONUS = 600;
|
||||
const MAXIMUM = 200;
|
||||
const HALFWAY = 75;
|
||||
|
||||
it('provides a value under the maximum, given a bonus and maximum', () => {
|
||||
expect(diminishingReturns(BONUS, MAXIMUM)).to.be.lessThan(MAXIMUM);
|
||||
});
|
||||
|
||||
it('provides a value under the maximum, given a bonus, maximum, and halfway point', () => {
|
||||
expect(diminishingReturns(BONUS, MAXIMUM, HALFWAY)).to.be.lessThan(MAXIMUM);
|
||||
});
|
||||
|
||||
it('provides a different curve if a halfway point is defined', () => {
|
||||
expect(diminishingReturns(BONUS, MAXIMUM, HALFWAY)).to.not.eql(shared.diminishingReturns(BONUS, MAXIMUM));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user