-
Notifications
You must be signed in to change notification settings - Fork 33
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 2 commits
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export enum Mode { | ||
ALIVE = "Alive", | ||
DIED = "Died" | ||
} | ||
export class Mouse { | ||
_healthpool: 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 | ||
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. при неправильном значении бросайте exception |
||
} | ||
get year(): number { | ||
return this._age | ||
} | ||
hit(): string { | ||
this._healthpool -= 10 | ||
if (this._healthpool > 0) { | ||
return `Вы ударили мышь, теперь у неё ${this._healthpool} здоровья` | ||
} else { | ||
this._mode = Mode.DIED | ||
return "Мышь сдохла" | ||
} | ||
} | ||
heal(): string { | ||
this._healthpool = 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 |
---|---|---|
@@ -1,16 +1,10 @@ | ||
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 { Animal } from "./polymorphism/animal"; | ||
import { Mode } from "./polymorphism/animal"; | ||
import { Fox } from "./polymorphism/fox"; | ||
import { chinchilla } from "./polymorphism/chinchilla"; | ||
let animalArray:object[] = [] | ||
const Karina = new Fox(200, "Белая"); | ||
const Evgenia = new chinchilla(19, "Чёрная") | ||
animalArray.push(Karina,Evgenia) | ||
console.log(Karina.sound()) | ||
console.log(Evgenia.sound()) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export enum Mode { | ||
ALIVE = "Alive", | ||
DIED = "Died" | ||
}; | ||
export class Animal { | ||
_mode: Mode = Mode.ALIVE; | ||
_color: string; | ||
_healthpool: 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. и вот это поле публичное |
||
constructor(color: string) { | ||
this._color = color; | ||
}; | ||
sound(): string { | ||
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. тогда сделайте его абстрактным |
||
return "Мы не можем понять, кто это" | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Animal } from "./animal"; | ||
import { Mode } from "./animal"; | ||
export class chinchilla extends Animal { | ||
private _age: number; | ||
constructor(year: number, color: string) { | ||
super(color); | ||
this.year = year; | ||
}; | ||
set year(year: number) { | ||
this._age = year > 0 && year < 20 ? year : 0; | ||
}; | ||
Comment on lines
+9
to
+11
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. а вот тут интересно - у вас у всех есть возраст - но нет в базовом классе -> я могу создать животьное у которого не будет этого года - что может привести к неожиданному поведению |
||
|
||
get year(): number { | ||
return this._age; | ||
} | ||
|
||
sound(): string { | ||
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. 👍 |
||
}; | ||
toString(): string { | ||
return "Это Шиншила"; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Animal } from "./animal"; | ||
import { Mode } from "./animal"; | ||
export class Fox extends Animal { | ||
private _age: number; | ||
constructor(year: number, color: string) { | ||
super(color); | ||
this.year = year; | ||
}; | ||
set year(year: number) { | ||
this._age = year > 0 && year < 25 ? year : 0; | ||
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. при неправильном годе - бросайте exception кроме того вы можете определить базовое поведение и хранить сколько лет живет то или иное животное - и исходя из этого сделать этот метод вообще в базовом классе |
||
}; | ||
|
||
get year(): number { | ||
return this._age; | ||
}; | ||
|
||
sound(): string { | ||
return `Миу`; | ||
}; | ||
|
||
toString(): string { | ||
return "Это Лиса"; | ||
}; | ||
|
||
hit(): string { | ||
this._healthpool -= 10; | ||
if (this._healthpool > 0) { | ||
return `Вы ударили лису, теперь у неё ${this._healthpool} здоровья` | ||
} else { | ||
this._healthpool = 100; | ||
return "У лисы осталось 0 здоровья, однако боги исцелили её"; | ||
}; | ||
}; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Mouse } from '../src/classTask/mouse'; | ||
import { Mode } from "../src/classTask/mouse"; | ||
|
||
xdescribe('Testing Mouse constructor', () => { | ||
it('Mouse should be created with incorrect age', () => { | ||
const mouse = new Mouse(6, "Красный"); | ||
expect(mouse.year).toEqual(0); | ||
expect(mouse._healthpool).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._healthpool).toEqual(100); | ||
expect(mouse._color).toEqual("Чёрный"); | ||
expect(mouse._mode).toEqual(Mode.ALIVE); | ||
}); | ||
}); | ||
|
||
xdescribe('Testing Mouse methods', () => { | ||
it("Method hit", () => { | ||
const mouse = new Mouse(2, "Чёрный"); | ||
for (let index = 1; index < 10; index++) { | ||
mouse.hit() | ||
expect(mouse._healthpool).toEqual(100 - index * 10) | ||
}; | ||
}); | ||
it("Method heal", () => { | ||
const mouse = new Mouse(2, "Чёрный"); | ||
mouse.heal(); | ||
expect(mouse._healthpool).toEqual(100) | ||
}); | ||
it("Method color with same color and not", () => { | ||
const mouse = new Mouse(2, "Чёрный"); | ||
expect(mouse.paint("Красный")).toEqual("Теперь мышь имеет Красный цвет"); | ||
expect(mouse.paint("Красный")).toEqual("Зачем вы красите Красный в Красный"); | ||
}) | ||
}); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
import { Animal } from "../src/polymorphism/animal"; | ||
import { Mode } from "../src/polymorphism/animal"; | ||
import { Fox } from "../src/polymorphism/fox"; | ||
import { chinchilla } from "../src/polymorphism/chinchilla"; | ||
import { generateKeyPair } from "crypto"; | ||
|
||
describe('Testing Animals constructor', () => { | ||
it('Animals should be created with incorrect age', () => { | ||
const Evgenia = new chinchilla(200, "Белая"); | ||
const Karina = new Fox(200, "Чёрная"); | ||
expect(Evgenia.year).toEqual(0) | ||
expect(Karina.year).toEqual(0) | ||
expect(Evgenia._color).toEqual("Белая") | ||
expect(Karina._color).toEqual("Чёрная") | ||
}); | ||
|
||
it("Animals should be created", () => { | ||
const Evgenia = new chinchilla(19, "Белая"); | ||
const Karina = new Fox(19, "Чёрная"); | ||
expect(Evgenia.year).toEqual(19) | ||
expect(Karina.year).toEqual(19) | ||
}); | ||
}); | ||
|
||
describe('Testing Animals methods', () => { | ||
it("Method toString", () => { | ||
const Evgenia = new chinchilla(19, "Белая"); | ||
const Karina = new Fox(19, "Чёрная"); | ||
expect(`${Evgenia}`).toEqual("Это Шиншила"); | ||
expect(`${Karina}`).toEqual("Это Лиса"); | ||
}); | ||
it("Method sound", () => { | ||
const Evgenia = new chinchilla(19, "Белая"); | ||
const Karina = new Fox(19, "Чёрная"); | ||
expect(Karina.sound()).toEqual("Миу"); | ||
expect(Evgenia.sound()).toEqual("Фыр-фыр"); | ||
}); | ||
it("Method color with same color and not", () => { | ||
}) | ||
}); |
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.
и извне могу ее убить - поле то публичное