-
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 branch information
1 parent
ecf8775
commit 1d9f893
Showing
10 changed files
with
176 additions
and
135 deletions.
There are no files selected for viewing
34 changes: 17 additions & 17 deletions
34
rpgsaga/saga/src/mouse.ts → rpgsaga/saga/src/classTask/mouse.ts
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
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,4 +1,10 @@ | ||
import { FILE } from "dns"; | ||
import { Mouse } from "./mouse"; | ||
const first = new Mouse(2,"Белый") | ||
console.log(first.year) | ||
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.
Oops, something went wrong.
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,16 @@ | ||
export enum Mode { | ||
ALIVE = "Alive", | ||
DIED = "Died" | ||
}; | ||
export class Animal { | ||
_mode: Mode = Mode.ALIVE; | ||
_color: string; | ||
_healthpool: number = 100; | ||
constructor(color: string) { | ||
this._color = color; | ||
}; | ||
sound(): string { | ||
return "Мы не можем понять, кто это" | ||
} | ||
}; | ||
|
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,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; | ||
}; | ||
|
||
get year(): number { | ||
return this._age; | ||
} | ||
|
||
sound(): string { | ||
return `Фыр-фыр`; | ||
}; | ||
toString(): string { | ||
return "Это Шиншила"; | ||
}; | ||
}; |
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,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; | ||
}; | ||
|
||
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 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,40 +1,40 @@ | ||
import { Mouse } from '../src/mouse'; | ||
import { Mode } from "../src/mouse"; | ||
import { Mouse } from '../src/classTask/mouse'; | ||
import { Mode } from "../src/classTask/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); | ||
}); | ||
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); | ||
}); | ||
}); | ||
|
||
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) | ||
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("Зачем вы красите Красный в Красный"); | ||
}) | ||
}); | ||
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.
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,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", () => { | ||
}) | ||
}); |