/
mrrobot
/
js-final
Обзор
Документация
Войти
/
mrrobot
/
js-final
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/weapons.test.js
170 строк
4 KB
Ivan Popov
tests
22 май 2026, 19:49
22 май 2026, 19:49
67f2760
Код
Авторство
О чём код?
'use strict'; const { Weapon, Arm, Bow, Sword, Knife, Staff, LongBow, Axe, StormStaff } = require('../src/weapons'); describe('Weapon base class', () => { test('constructor sets all properties', () => { const w = new Weapon('Старый меч', 20, 10, 1); expect(w.name).toBe('Старый меч'); expect(w.attack).toBe(20); expect(w.durability).toBe(10); expect(w.initDurability).toBe(10); expect(w.range).toBe(1); }); test('takeDamage reduces durability', () => { const w = new Weapon('test', 10, 10, 1); w.takeDamage(5); expect(w.durability).toBe(5); }); test('takeDamage clamps at 0', () => { const w = new Weapon('test', 10, 10, 1); w.takeDamage(50); expect(w.durability).toBe(0); }); test('getDamage returns 0 when durability is 0', () => { const w = new Weapon('test', 10, 10, 1); w.takeDamage(10); expect(w.getDamage()).toBe(0); }); test('getDamage returns full attack at >= 30%', () => { const w = new Weapon('test', 10, 100, 1); w.takeDamage(70); expect(w.getDamage()).toBe(10); }); test('getDamage returns half attack at < 30%', () => { const w = new Weapon('test', 10, 100, 1); w.takeDamage(75); expect(w.getDamage()).toBe(5); }); test('isBroken false when durability > 0, true at 0', () => { const w = new Weapon('test', 10, 10, 1); expect(w.isBroken()).toBe(false); w.takeDamage(10); expect(w.isBroken()).toBe(true); }); }); describe('Arm', () => { test('has expected stats', () => { const a = new Arm(); expect(a.name).toBe('Рука'); expect(a.attack).toBe(1); expect(a.durability).toBe(Infinity); expect(a.initDurability).toBe(Infinity); expect(a.range).toBe(1); }); test('never breaks', () => { const a = new Arm(); a.takeDamage(10000); expect(a.durability).toBe(Infinity); expect(a.isBroken()).toBe(false); expect(a.getDamage()).toBe(1); }); }); describe('Bow', () => { test('has expected stats', () => { const b = new Bow(); expect(b.name).toBe('Лук'); expect(b.attack).toBe(10); expect(b.durability).toBe(200); expect(b.range).toBe(3); }); test('getDamage thresholds from spec example', () => { const bow = new Bow(); expect(bow.getDamage()).toBe(10); expect(bow.durability).toBe(200); bow.takeDamage(100); expect(bow.getDamage()).toBe(10); expect(bow.durability).toBe(100); bow.takeDamage(50); expect(bow.getDamage()).toBe(5); expect(bow.durability).toBe(50); bow.takeDamage(150); expect(bow.getDamage()).toBe(0); expect(bow.durability).toBe(0); expect(bow.isBroken()).toBe(true); }); }); describe('Sword', () => { test('has expected stats', () => { const s = new Sword(); expect(s.name).toBe('Меч'); expect(s.attack).toBe(25); expect(s.durability).toBe(500); expect(s.range).toBe(1); }); }); describe('Knife', () => { test('has expected stats', () => { const k = new Knife(); expect(k.name).toBe('Нож'); expect(k.attack).toBe(5); expect(k.durability).toBe(300); expect(k.range).toBe(1); }); }); describe('Staff', () => { test('has expected stats', () => { const s = new Staff(); expect(s.name).toBe('Посох'); expect(s.attack).toBe(8); expect(s.durability).toBe(300); expect(s.range).toBe(2); }); }); describe('LongBow', () => { test('has expected stats', () => { const lb = new LongBow(); expect(lb.name).toBe('Длинный лук'); expect(lb.attack).toBe(15); expect(lb.durability).toBe(200); expect(lb.initDurability).toBe(200); expect(lb.range).toBe(4); }); }); describe('Axe', () => { test('has expected stats with 800 durability', () => { const a = new Axe(); expect(a.name).toBe('Секира'); expect(a.attack).toBe(27); expect(a.durability).toBe(800); expect(a.initDurability).toBe(800); expect(a.range).toBe(1); }); test('threshold uses 800 not 500', () => { const a = new Axe(); a.takeDamage(560); expect(a.durability).toBe(240); expect(a.getDamage()).toBe(27); a.takeDamage(1); expect(a.durability).toBe(239); expect(a.getDamage()).toBe(13.5); }); }); describe('StormStaff', () => { test('has expected stats', () => { const s = new StormStaff(); expect(s.name).toBe('Посох Бури'); expect(s.attack).toBe(10); expect(s.durability).toBe(300); expect(s.range).toBe(3); }); });