Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create PR #25

Open
wants to merge 5 commits into
base: Novoselov_Nikolaj_Vitalevich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum можно вынести в отдельный файл

ALIVE = "Alive",
DIED = "Died"
}
export class Mouse {
_heathpool: number = 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

проверим настройки линтера

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а _heathpool не должен быть приватным или protected

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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не используйте else

this._mode = Mode.DIED
return "Мышь сдохла"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

линтер точно не заработал - нужна ; в конце строки

}
}
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)');
Expand All @@ -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;
Expand Down
Loading