Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit
Browse files Browse the repository at this point in the history
GitSwaggCat committed Nov 8, 2023
1 parent c8965a3 commit ecf8775
Showing 6 changed files with 93 additions and 25 deletions.
20 changes: 4 additions & 16 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import { Phone } from './phone';

const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1');
first.year = 1998;

first.year = -1998;
first.call('12345');
first.endCall();

const second = new Phone('+799900000', -5);
// second.name = 'Телефон 2';
console.log(second.year);
second.call('12345');
second.endCall();

console.log(first, second, Phone.phoneCount);
import { FILE } from "dns";
import { Mouse } from "./mouse";
const first = new Mouse(2,"Белый")
console.log(first.year)
42 changes: 42 additions & 0 deletions rpgsaga/saga/src/mouse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export enum Mode{
ALIVE = "Alive",
DIED = "Died"
}
export class Mouse {
_heathpool: number = 100;
private _age: number;
_color: string;
_mode: Mode = Mode.ALIVE;
constructor(year: number, color: string) {
this.year = year;
this._color = color;
};
set year(year:number ){
this._age = year > 0 && year < 4 ? year:0
}
get year():number {
return this._age
}
hit(): string{
this._heathpool-=10
if (this._heathpool > 0) {
return `Вы ударили мышь, теперь у неё ${this._heathpool} здоровья`
}else{
this._mode = Mode.DIED
return "Мышь сдохла"
}
}
heal():string{
this._heathpool = 100
return `Теперь здоровье мыши в норме и составляет 100 единиц`
}
paint(color): string{
if (this._color == color) {
return `Зачем вы красите ${this._color} в ${color}`
}else{
this._color = color
return `Теперь мышь имеет ${color} цвет`
}
}

}
5 changes: 5 additions & 0 deletions rpgsaga/saga/src/polymorphism.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Animal{
_hp: number;
_age:number;

}
7 changes: 0 additions & 7 deletions rpgsaga/saga/tests/example.spec.ts

This file was deleted.

40 changes: 40 additions & 0 deletions rpgsaga/saga/tests/mouse.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Mouse } from '../src/mouse';
import { Mode } from "../src/mouse";

describe('Testing Mouse constructor', () =>{
it('Mouse should be created with incorrect age', () =>{
const mouse = new Mouse(6, "Красный");
expect(mouse.year).toEqual(0);
expect(mouse._heathpool).toEqual(100);
expect(mouse._color).toEqual("Красный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
it("Mouse should be created", () =>{
const mouse = new Mouse(2,"Чёрный");
expect(mouse.year).toEqual(2);
expect(mouse._heathpool).toEqual(100);
expect(mouse._color).toEqual("Чёрный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
});

describe('Testing Mouse methods', () => {
it("Method hit", () => {
const mouse = new Mouse(2,"Чёрный");
for (let index = 1; index < 10; index++) {
mouse.hit()
expect(mouse._heathpool).toEqual(100 -index*10)
};
});
it("Method heal",()=>{
const mouse = new Mouse(2,"Чёрный");
mouse.heal();
expect(mouse._heathpool).toEqual(100)
});
it("Method color with same color and not", ()=>{
const mouse = new Mouse(2,"Чёрный");
expect(mouse.paint("Красный")).toEqual("Теперь мышь имеет Красный цвет");
expect(mouse.paint("Красный")).toEqual("Зачем вы красите Красный в Красный");
})
});

4 changes: 2 additions & 2 deletions rpgsaga/saga/tests/phone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Phone } from '../src/phone';

describe('Testing phone constructor', () => {
xdescribe('Testing phone constructor', () => {
it('Phone should be created', () => {
const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1');
expect(first.phoneNumber).toEqual('+7900-000 000 (123)');
@@ -27,7 +27,7 @@ describe('Testing phone constructor', () => {
});
});

describe('Testing phone methods', () => {
xdescribe('Testing phone methods', () => {
it('Phone year set valid value', () => {
const first = new Phone('+7900-000 000 (123)', 2000, 'Телефон 1');
first.year = 1991;

0 comments on commit ecf8775

Please sign in to comment.