-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: Novoselov_Nikolaj_Vitalevich
Are you sure you want to change the base?
Create PR #25
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. проверим настройки линтера There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не используйте else |
||
this._mode = Mode.DIED | ||
return "Мышь сдохла" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} цвет` | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Animal{ | ||
_hp: number; | ||
_age:number; | ||
|
||
} |
This file was deleted.
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("Зачем вы красите Красный в Красный"); | ||
}) | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum можно вынести в отдельный файл