-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
commit
1 parent
c8965a3
commit ecf8775
Showing
6 changed files
with
93 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} цвет` | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Animal{ | ||
_hp: number; | ||
_age:number; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Зачем вы красите Красный в Красный"); | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters