tf2-currency
Version:
Set of tools that manage operations with tf2 currency.
375 lines (374 loc) • 17.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var currency_helper_1 = require("./currency.helper");
var currency_class_1 = require("./currency.class");
var _1 = require(".");
describe('CurrencyHelper', function () {
describe('round', function () {
it('Rounds with default decimal', function () {
expect((0, currency_helper_1.round)(52.11111111)).toEqual(52.11);
});
it('Rounds with 4 decimal numbers', function () {
expect((0, currency_helper_1.round)(52.11111111, 4)).toEqual(52.1111);
});
it('Rounds negative with default decimal', function () {
expect((0, currency_helper_1.round)(-52.11111111)).toEqual(-52.11);
});
it('Rounds negative with 4 decimal numbers', function () {
expect((0, currency_helper_1.round)(-52.11111111, 4)).toEqual(-52.1111);
});
});
describe('toScrap', function () {
it('Converts refined to scrap #1', function () {
expect((0, currency_helper_1.toScrap)(14)).toEqual(14 * 9);
});
it('Converts refined to scrap #2', function () {
expect((0, currency_helper_1.toScrap)(14.22)).toEqual(14 * 9 + 2);
});
it('Converts refined to scrap #3', function () {
expect((0, currency_helper_1.toScrap)(14.88)).toEqual(14 * 9 + 8);
});
it('Converts refined to scrap #4', function () {
expect((0, currency_helper_1.toScrap)(14.99)).toEqual(14 * 9 + 9);
});
it('Converts refined to scrap #5', function () {
expect((0, currency_helper_1.toScrap)(0.77)).toEqual(7);
});
it('Converts weapon value #1', function () {
expect((0, currency_helper_1.toScrap)(0.16)).toEqual(1.5);
});
it('Converts weapon value #2', function () {
expect((0, currency_helper_1.toScrap)(0.61)).toEqual(5.5);
});
it('Negative converts refined to scrap #1', function () {
expect((0, currency_helper_1.toScrap)(-14)).toEqual(14 * -9);
});
it('Negative converts refined to scrap #2', function () {
expect((0, currency_helper_1.toScrap)(-14.22)).toEqual(-14 * 9 - 2);
});
it('Negative converts refined to scrap #3', function () {
expect((0, currency_helper_1.toScrap)(-14.88)).toEqual(-14 * 9 - 8);
});
it('Negative converts refined to scrap #4', function () {
expect((0, currency_helper_1.toScrap)(-14.99)).toEqual(-14 * 9 - 9);
});
it('Negative converts refined to scrap #5', function () {
expect((0, currency_helper_1.toScrap)(-0.77)).toEqual(-7);
});
it('Negative converts weapon value #1', function () {
expect((0, currency_helper_1.toScrap)(-0.16)).toEqual(-1.5);
});
it('Negative converts weapon value #2', function () {
expect((0, currency_helper_1.toScrap)(-0.61)).toEqual(-5.5);
});
});
describe('toWeapons', function () {
it('Converts int refined to weapons', function () {
expect((0, currency_helper_1.toWeapons)(14)).toEqual(14 * 18);
});
it('Converts refined with scrap to weapons', function () {
expect((0, currency_helper_1.toWeapons)(14.55)).toEqual(14 * 18 + 10);
});
it('Converts refined with weapons to weapons #1', function () {
expect((0, currency_helper_1.toWeapons)(14.72)).toEqual(14 * 18 + 13);
});
it('Converts refined with weapons to weapons #2', function () {
expect((0, currency_helper_1.toWeapons)(14.05)).toEqual(14 * 18 + 1);
});
it('Converts refined with weapons to weapons #3', function () {
expect((0, currency_helper_1.toWeapons)(14.49)).toEqual(14 * 18 + 9);
});
});
describe('toRefined', function () {
it('Converts scrap to refined #1', function () {
expect((0, currency_helper_1.toRefined)(14 * 9)).toEqual(14);
});
it('Converts scrap to refined #2', function () {
expect((0, currency_helper_1.toRefined)(14 * 9 + 2)).toEqual(14.22);
});
it('Converts scrap to refined #3', function () {
expect((0, currency_helper_1.toRefined)(14 * 9 + 8)).toEqual(14.88);
});
it('Converts scrap to refined #4', function () {
expect((0, currency_helper_1.toRefined)(14 * 9 + 9)).toEqual(15);
});
it('Converts scrap to refined #5', function () {
expect((0, currency_helper_1.toRefined)(7)).toEqual(0.77);
});
it('Converts weapon value #1', function () {
expect((0, currency_helper_1.toRefined)(5.5)).toEqual(0.61);
});
it('Negative converts weapon value #2', function () {
expect((0, currency_helper_1.toRefined)(-1.5)).toEqual(-0.16);
});
it('Negative converts scrap to refined #1', function () {
expect((0, currency_helper_1.toRefined)(-14 * 9)).toEqual(-14);
});
it('Negative converts scrap to refined #2', function () {
expect((0, currency_helper_1.toRefined)(-14 * 9 - 2)).toEqual(-14.22);
});
it('Negative converts scrap to refined #3', function () {
expect((0, currency_helper_1.toRefined)(-14 * 9 - 8)).toEqual(-14.88);
});
it('Negative converts scrap to refined #4', function () {
expect((0, currency_helper_1.toRefined)(-14 * 9 - 9)).toEqual(-15);
});
it('Negative converts scrap to refined #5', function () {
expect((0, currency_helper_1.toRefined)(-7)).toEqual(-0.77);
});
it('Negative converts weapon value #1', function () {
expect((0, currency_helper_1.toRefined)(-5.5)).toEqual(-0.61);
});
it('Negative converts weapon value #2', function () {
expect((0, currency_helper_1.toRefined)(-1.5)).toEqual(-0.16);
});
it('Test 1.66', function () {
expect((0, currency_helper_1.toRefined)(15)).toEqual(1.66);
});
it('Test -1.66', function () {
expect((0, currency_helper_1.toRefined)(-15)).toEqual(-1.66);
});
});
describe('fixMetal', function () {
it('Fixes input metal', function () {
expect((0, currency_helper_1.fixMetal)(53.44444)).toEqual(53.44);
});
it('Keeps same value', function () {
expect((0, currency_helper_1.fixMetal)(12.88)).toEqual(12.88);
});
it('Transfers .99 to 1', function () {
expect((0, currency_helper_1.fixMetal)(1.99)).toEqual(2);
});
it('Rounds weapon values up', function () {
expect((0, currency_helper_1.fixMetal)(0.6)).toEqual(0.61);
});
it('Rounds weapon values down', function () {
expect((0, currency_helper_1.fixMetal)(0.17)).toEqual(0.16);
});
it('Rounds negative weapon values up', function () {
expect((0, currency_helper_1.fixMetal)(-0.6)).toEqual(-0.61);
});
it('Rounds negative weapon values down', function () {
expect((0, currency_helper_1.fixMetal)(-0.17)).toEqual(-0.16);
});
});
describe('fixCurrency', function () {
it('Fixes currency metal input', function () {
expect((0, currency_helper_1.fixCurrency)({
metal: 0.17,
})).toEqual({
keys: 0,
metal: 0.16,
});
});
it('Fixes keys input', function () {
expect((0, currency_helper_1.fixCurrency)({
keys: 15,
})).toEqual({
keys: 15,
metal: 0,
});
});
});
describe('fromKeysToCurrency', function () {
it('Converts with conversion', function () {
expect((0, currency_helper_1.fromKeysToCurrency)(1.2, 62)).toEqual({
keys: 1,
metal: 12.44,
});
});
it('Converts without conversion', function () {
expect((0, currency_helper_1.fromKeysToCurrency)(3)).toEqual({
keys: 3,
metal: 0,
});
});
it('Throw error', function () {
var err;
try {
(0, currency_helper_1.fromKeysToCurrency)(1.2);
}
catch (e) {
err = e;
}
expect(err).toBeInstanceOf(Error);
});
it('Coverts negative key value', function () {
expect((0, currency_helper_1.fromKeysToCurrency)(-3)).toEqual({
keys: -3,
metal: 0,
});
});
it('Coverts negative key value with conversion', function () {
expect((0, currency_helper_1.fromKeysToCurrency)(-1.2, 62)).toEqual({
keys: -1,
metal: -12.44,
});
});
});
describe('isEqual', function () {
it('Is equal', function () {
expect((0, currency_helper_1.isEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52.11 })).toEqual(true);
});
it('Is not equal', function () {
expect((0, currency_helper_1.isEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(false);
});
});
describe('isBigger', function () {
it('Is bigger', function () {
expect((0, currency_helper_1.isBigger)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(true);
});
it('Is not bigger #1', function () {
expect((0, currency_helper_1.isBigger)({ keys: 21, metal: 52.11 }, { keys: 22, metal: 52.11 })).toEqual(false);
});
it('Is not bigger #2', function () {
expect((0, currency_helper_1.isBigger)({ keys: 22, metal: 52 }, { keys: 22, metal: 52.11 })).toEqual(false);
});
});
describe('isSmaller', function () {
it('Is smaller', function () {
expect((0, currency_helper_1.isSmaller)({ keys: 22, metal: 52 }, { keys: 22, metal: 52.11 })).toEqual(true);
});
it('Is not smaller #1', function () {
expect((0, currency_helper_1.isSmaller)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52.11 })).toEqual(false);
});
it('Is not smaller #2', function () {
expect((0, currency_helper_1.isSmaller)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(false);
});
});
describe('isBiggerOrEqual', function () {
it('Is bigger #1', function () {
expect((0, currency_helper_1.isBiggerOrEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(true);
});
it('Is bigger #2', function () {
expect((0, currency_helper_1.isBiggerOrEqual)({ keys: 23, metal: 52 }, { keys: 22, metal: 52 })).toEqual(true);
});
it('Is equal', function () {
expect((0, currency_helper_1.isBiggerOrEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52.11 })).toEqual(true);
});
it('Is not bigger or equal #1', function () {
expect((0, currency_helper_1.isBiggerOrEqual)({ keys: 22, metal: 51.88 }, { keys: 22, metal: 52 })).toEqual(false);
});
it('Is not bigger or equal #2', function () {
expect((0, currency_helper_1.isBiggerOrEqual)({ keys: 21, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(false);
});
});
describe('isSmallerOrEqual', function () {
it('Is smaller #1', function () {
expect((0, currency_helper_1.isSmallerOrEqual)({ keys: 21, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(true);
});
it('Is smaller #2', function () {
expect((0, currency_helper_1.isSmallerOrEqual)({ keys: 22, metal: 51.88 }, { keys: 22, metal: 52 })).toEqual(true);
});
it('Is equal', function () {
expect((0, currency_helper_1.isSmallerOrEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52.11 })).toEqual(true);
});
it('Is not smaller or equal #1', function () {
expect((0, currency_helper_1.isSmallerOrEqual)({ keys: 22, metal: 52.11 }, { keys: 22, metal: 52 })).toEqual(false);
});
it('Is not smaller or equal #2', function () {
expect((0, currency_helper_1.isSmallerOrEqual)({ keys: 23, metal: 52 }, { keys: 22, metal: 52 })).toEqual(false);
});
});
describe('compareTo', function () {
it('Is Equal', function () {
expect((0, currency_helper_1.compareTo)({ keys: 12, metal: 20 }, { keys: 12, metal: 20 })).toEqual(0);
});
it('Is Smaller', function () {
expect((0, currency_helper_1.compareTo)({ keys: 12, metal: 19 }, { keys: 12, metal: 20 })).toEqual(-1);
});
it('Is Equal', function () {
expect((0, currency_helper_1.compareTo)({ keys: 12, metal: 21 }, { keys: 12, metal: 20 })).toEqual(1);
});
});
describe('c', function () {
it('Creates Currency object', function () {
expect((0, currency_helper_1.c)({ keys: 12, metal: 12 })).toEqual(new currency_class_1.Currency({
keys: 12,
metal: 12,
}));
});
});
describe('pluralizeKeys', function () {
it('Negative plural', function () {
expect((0, _1.pluralizeKeys)(-5)).toEqual('-5 keys');
});
it('Negative singular', function () {
expect((0, _1.pluralizeKeys)(-1)).toEqual('-1 key');
});
it('0', function () {
expect((0, _1.pluralizeKeys)(0)).toEqual('0 keys');
});
it('Positive plural', function () {
expect((0, _1.pluralizeKeys)(5)).toEqual('5 keys');
});
it('Positive plural', function () {
expect((0, _1.pluralizeKeys)(1)).toEqual('1 key');
});
});
describe('weaponized', function () {
describe('isEqual', function () {
it('Is equal', function () {
expect(currency_helper_1.w.isEqual({ keys: 22, metalInWeapons: 631 }, { keys: 22, metalInWeapons: 631 })).toEqual(true);
});
it('Is not equal', function () {
expect(currency_helper_1.w.isEqual({ keys: 22, metalInWeapons: 532 }, { keys: 22, metalInWeapons: 123 })).toEqual(false);
});
});
describe('isBigger', function () {
it('Is bigger', function () {
expect(currency_helper_1.w.isBigger({ keys: 22, metalInWeapons: 532 }, { keys: 22, metalInWeapons: 531 })).toEqual(true);
});
it('Is not bigger #1', function () {
expect(currency_helper_1.w.isBigger({ keys: 21, metalInWeapons: 233 }, { keys: 22, metalInWeapons: 110 })).toEqual(false);
});
it('Is not bigger #2', function () {
expect(currency_helper_1.w.isBigger({ keys: 22, metalInWeapons: 533 }, { keys: 22, metalInWeapons: 533 })).toEqual(false);
});
});
describe('isSmaller', function () {
it('Is smaller', function () {
expect(currency_helper_1.w.isSmaller({ keys: 22, metalInWeapons: 123 }, { keys: 22, metalInWeapons: 289 })).toEqual(true);
});
it('Is not smaller #1', function () {
expect(currency_helper_1.w.isSmaller({ keys: 22, metalInWeapons: 219 }, { keys: 22, metalInWeapons: 190 })).toEqual(false);
});
it('Is not smaller #2', function () {
expect(currency_helper_1.w.isSmaller({ keys: 22, metalInWeapons: 123 }, { keys: 22, metalInWeapons: 123 })).toEqual(false);
});
});
describe('isBiggerOrEqual', function () {
it('Is bigger #1', function () {
expect(currency_helper_1.w.isBiggerOrEqual({ keys: 22, metalInWeapons: 125 }, { keys: 22, metalInWeapons: 124 })).toEqual(true);
});
it('Is equal', function () {
expect(currency_helper_1.w.isBiggerOrEqual({ keys: 22, metalInWeapons: 100 }, { keys: 22, metalInWeapons: 100 })).toEqual(true);
});
it('Is not bigger or equal #1', function () {
expect(currency_helper_1.w.isBiggerOrEqual({ keys: 22, metalInWeapons: 90 }, { keys: 22, metalInWeapons: 100 })).toEqual(false);
});
});
describe('isSmallerOrEqual', function () {
it('Is smaller #1', function () {
expect(currency_helper_1.w.isSmallerOrEqual({ keys: 21, metalInWeapons: 90 }, { keys: 22, metalInWeapons: 100 })).toEqual(true);
});
it('Is equal', function () {
expect(currency_helper_1.w.isSmallerOrEqual({ keys: 22, metalInWeapons: 100 }, { keys: 22, metalInWeapons: 100 })).toEqual(true);
});
it('Is not smaller or equal #1', function () {
expect(currency_helper_1.w.isSmallerOrEqual({ keys: 22, metalInWeapons: 100 }, { keys: 22, metalInWeapons: 90 })).toEqual(false);
});
});
describe('compareTo', function () {
it('Is Equal', function () {
expect(currency_helper_1.w.compareTo({ keys: 12, metalInWeapons: 20 }, { keys: 12, metalInWeapons: 20 })).toEqual(0);
});
it('Is Smaller', function () {
expect(currency_helper_1.w.compareTo({ keys: 12, metalInWeapons: 19 }, { keys: 12, metalInWeapons: 20 })).toEqual(-1);
});
it('Is Equal', function () {
expect(currency_helper_1.w.compareTo({ keys: 12, metalInWeapons: 21 }, { keys: 12, metalInWeapons: 20 })).toEqual(1);
});
});
});
});
;