From 3ed58241f58084bf120cedb4fa6d79e74815da81 Mon Sep 17 00:00:00 2001 From: HaQmUser Date: Tue, 5 Nov 2024 11:24:50 +0300 Subject: [PATCH] // --- rpgsaga/package-lock.json | 6 ++++ rpgsaga/saga/src/Rabbit.ts | 6 ++++ rpgsaga/saga/src/RabbitClass.ts | 46 ++++++++++++++++++++++++++ rpgsaga/saga/tests/mathematics.spec.ts | 22 ++++++++---- 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 rpgsaga/package-lock.json create mode 100644 rpgsaga/saga/src/Rabbit.ts create mode 100644 rpgsaga/saga/src/RabbitClass.ts diff --git a/rpgsaga/package-lock.json b/rpgsaga/package-lock.json new file mode 100644 index 00000000..f09b1837 --- /dev/null +++ b/rpgsaga/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "rpgsaga", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/rpgsaga/saga/src/Rabbit.ts b/rpgsaga/saga/src/Rabbit.ts new file mode 100644 index 00000000..cb91641d --- /dev/null +++ b/rpgsaga/saga/src/Rabbit.ts @@ -0,0 +1,6 @@ +import { Rabbit } from './RabbitClass'; + +const rabbitOne = new Rabbit('Vitalik',3,'Brown','Male') +console.log(rabbitOne) +const rabbitTwo = new Rabbit('LuiVitonovich',4,'Black','Female') +console.log(rabbitTwo) \ No newline at end of file diff --git a/rpgsaga/saga/src/RabbitClass.ts b/rpgsaga/saga/src/RabbitClass.ts new file mode 100644 index 00000000..fdfa997b --- /dev/null +++ b/rpgsaga/saga/src/RabbitClass.ts @@ -0,0 +1,46 @@ +export class Rabbit { + private _name: string; + private _age: number; + private _color: string; + private _gender: string; + constructor(name: string, age: number, gender: string, color: string) { + this._name = name; + this._age = age; + this._color = color; + this._gender = gender; + } + + public set age(age: number) { + if (age < 0) { + throw new Error('Invalid age'); + } + this._age = age; + } + public set name(name: string) { + this._name = name; + } + public set color(color: string) { + this.color = color; + } + public set gender(gender: string) { + if (gender.toLowerCase() == 'male'){ + this._gender = 'Male'; + } else if (gender.toLowerCase() == 'female'){ + this._gender = 'Female' + } else { + throw new Error('Invalid gender') + } + } + public get age() { + return this._age; + } + public get name() { + return this._name; + } + public get gender() { + return this._gender; + } + public get color() { + return this._color; + } +} \ No newline at end of file diff --git a/rpgsaga/saga/tests/mathematics.spec.ts b/rpgsaga/saga/tests/mathematics.spec.ts index e43f7d40..3a5090df 100644 --- a/rpgsaga/saga/tests/mathematics.spec.ts +++ b/rpgsaga/saga/tests/mathematics.spec.ts @@ -3,17 +3,27 @@ import { formula, taskA, taskB } from '../src/mathematics'; describe('formula', () => { test('should return right result', () => { - const result = formula(0.25); - expect(result).toBeCloseTo(0.168); + expect(formula(0.25)).toBeCloseTo(0.168); }); test('This Arccos doesnt excist', () => { - const result = formula(2,2); - expect(result).toBeNaN(); + expect(formula(2.2)).toBeNaN(); }); test('should handle division by zero in denominator', () => { - const result = formula(1, 2, 3); + const result = formula(1); expect(result).toBeDefined(); }); - }); \ No newline at end of file + }); + +describe('TaskA',()=> { + test('should return right size',()=>{ + expect(taskA(0.7,2.2,0.3)).toHaveLength(5); + }) +}) + +describe('TaskB',()=> { + test('should return right size',()=>{ + expect(taskB([0.25, 0.36, 0.56, 0.94, 1.28])).toHaveLength(5); + }) + }) \ No newline at end of file