UNPKG

@plokkke/sw-rune

Version:

Library defining all utils for summoners war rune handling

148 lines (147 loc) 7.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const random_1 = require("../src/random"); const RandomModule = __importStar(require("@plokkke/toolbox/random")); const probalilities_1 = require("../src/probalilities"); const constraints_1 = require("../src/constraints"); const constants_1 = require("../src/constants"); describe('Random utils', () => { describe('randomIsAncient', () => { it('should return true if the random number is lower than ANCIENT_PROBABILITY', () => { const randMock = jest.spyOn(Math, 'random').mockImplementation(() => 0.2); const actual = (0, random_1.randomIsAncient)(); expect(actual).toBe(false); expect(randMock).toHaveBeenCalled(); }); it('should return false if the random number is greater than ANCIENT_PROBABILITY', () => { const randMock = jest.spyOn(Math, 'random').mockImplementation(() => 0.9); const actual = (0, random_1.randomIsAncient)(); expect(actual).toBe(false); expect(randMock).toHaveBeenCalled(); }); }); describe('randomHasInnateStat', () => { it('should return true if the random number is lower than INNATE_STAT_PROBABILITY', () => { const randMock = jest.spyOn(Math, 'random').mockImplementation(() => 0.2); const actual = (0, random_1.randomHasInnateStat)(); expect(actual).toBe(true); expect(randMock).toHaveBeenCalled(); }); it('should return false if the random number is greater than INNATE_STAT_PROBABILITY', () => { const randMock = jest.spyOn(Math, 'random').mockImplementation(() => 0.9); const actual = (0, random_1.randomHasInnateStat)(); expect(actual).toBe(false); expect(randMock).toHaveBeenCalled(); }); }); describe('randomSet', () => { it('should return a random rune set', () => { const randMock = jest.spyOn(RandomModule, 'randomIdxByDensity').mockImplementation(() => 1); const actual = (0, random_1.randomSet)(); expect(actual).toBe('FATAL'); expect(randMock).toHaveBeenCalledWith(probalilities_1.SET_DENSITY); }); }); describe('randomSlot', () => { it('should return a random rune slot', () => { const randMock = jest.spyOn(RandomModule, 'randomInt').mockImplementation(() => 2); const actual = (0, random_1.randomSlot)(); expect(actual).toBe(2); expect(randMock).toHaveBeenCalledWith(1, 6); }); }); describe('randomGrade', () => { it('should return a random rune grade', () => { const randMock = jest.spyOn(RandomModule, 'randomIdxByDensity').mockImplementation(() => 1); const actual = (0, random_1.randomGrade)(); expect(actual).toBe(2); expect(randMock).toHaveBeenCalledWith(probalilities_1.GRADE_DENSITY); }); }); describe('randomQuality', () => { it('should return a random rune quality', () => { const randMock = jest.spyOn(RandomModule, 'randomIdxByDensity').mockImplementation(() => 1); const actual = (0, random_1.randomQuality)(); expect(actual).toBe('MAGIC'); expect(randMock).toHaveBeenCalledWith(probalilities_1.QUALITY_DENSITY); }); }); describe('randomMainEffect', () => { it('should return a random main stat type', () => { const slot = 2; const effect = 'ATTACK_PERCENTAGE'; const randMock = jest.spyOn(RandomModule, 'randomItem').mockImplementation(() => effect); const actual = (0, random_1.randomMainEffect)(slot); expect(actual).toBe(effect); expect(randMock).toHaveBeenCalledWith(constraints_1.MAIN_EFFECT_BY_SLOT[slot]); }); }); describe('randomSubEffect', () => { it('should return a random sub stat type', () => { const effect = 'ATTACK_PERCENTAGE'; const randMock = jest.spyOn(RandomModule, 'randomItem').mockImplementation(() => effect); const actual = (0, random_1.randomSubEffect)(); expect(actual).toBe(effect); expect(randMock).toHaveBeenCalledWith(constants_1.RUNE_EFFECTS); }); it('should return a random sub stat type excluding the given types', () => { const effect = 'ATTACK_PERCENTAGE'; const randMock = jest.spyOn(RandomModule, 'randomItem').mockImplementation(() => effect); const actual = (0, random_1.randomSubEffect)('ATTACK_FLAT', 'DEFENSE_FLAT', ['SPEED'], ['CRITICAL_RATE']); expect(actual).toBe(effect); expect(randMock).toHaveBeenCalledWith(['HEALTH_FLAT', 'HEALTH_PERCENTAGE', 'ATTACK_PERCENTAGE', 'DEFENSE_PERCENTAGE', 'CRITICAL_DAMAGE', 'RESISTANCE', 'ACCURACY']); }); }); describe('randomPropValue', () => { it('should return a normal proc', () => { const grade = 6; const effect = 'CRITICAL_DAMAGE'; const value = 10; const randMock = jest.spyOn(RandomModule, 'randomInt').mockImplementation(() => value); const actual = (0, random_1.randomEffectValue)(grade, effect); expect(actual).toBe(value); expect(randMock).toHaveBeenCalledWith(4, 7); }); it('should return a normal proc even in ancient bellow grade 6', () => { const grade = 2; const effect = 'CRITICAL_DAMAGE'; const value = 10; const randMock = jest.spyOn(RandomModule, 'randomInt').mockImplementation(() => value); const actual = (0, random_1.randomEffectValue)(grade, effect, true); expect(actual).toBe(value); expect(randMock).toHaveBeenCalledWith(1, 3); }); it('should return a random ancient value', () => { const grade = 6; const effect = 'CRITICAL_DAMAGE'; const value = 10; const randMock = jest.spyOn(RandomModule, 'randomInt').mockImplementation(() => value); const actual = (0, random_1.randomEffectValue)(grade, effect, true); expect(actual).toBe(value); expect(randMock).toHaveBeenCalledWith(5, 9); }); }); });