forked from ISUCT/TProgramming_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
158 additions
and
20 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
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,38 @@ | ||
import { Animal } from './AnimalSuperclass'; | ||
|
||
export class Parrot extends Animal { | ||
private _vocabulary: number; | ||
constructor(name: string, age: number, color: string, gender: string, vocabulary: number) { | ||
super(name, age, color, gender); | ||
this._vocabulary = vocabulary; | ||
} | ||
|
||
public set age(age: number) { | ||
if (age < 0 || age > 52) { | ||
throw new Error('Invalid age'); | ||
} | ||
this.age = age; | ||
} | ||
|
||
public set vocabulary(vocabulary: number) { | ||
if (vocabulary < 0 || vocabulary > 20) { | ||
throw new Error('Impossible vocabulary'); | ||
} | ||
this._vocabulary = vocabulary; | ||
} | ||
|
||
public get vocabulary() { | ||
return this._vocabulary; | ||
} | ||
|
||
public get age() { | ||
return this._age; | ||
} | ||
|
||
sound(): string { | ||
return 'Chik-Chirik'; | ||
} | ||
toString(): string { | ||
return `Parrot named ${this.name}, is ${this.age} years old,${this.gender} and ${this.color}, know ${this.vocabulary} words`; | ||
} | ||
} |
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,38 @@ | ||
import { Animal } from './AnimalSuperclass'; | ||
|
||
export class Rabbit extends Animal { | ||
private _jump: number; | ||
constructor(name: string, age: number, color: string, gender: string, jump: number) { | ||
super(name, age, color, gender); | ||
this._jump = jump; | ||
} | ||
|
||
public set age(age: number) { | ||
if (age < 0 || age > 5) { | ||
throw new Error('Invalid age'); | ||
} | ||
this.age = age; | ||
} | ||
|
||
public set jump(jump: number) { | ||
if (jump < 0 || jump > 2.7) { | ||
throw new Error('Impossible jump'); | ||
} | ||
this._jump = jump; | ||
} | ||
|
||
public get age() { | ||
return this._age; | ||
} | ||
|
||
public get jump() { | ||
return this._jump; | ||
} | ||
|
||
sound(): string { | ||
return 'Purr-Purr'; | ||
} | ||
toString(): string { | ||
return `Rabbit named ${this.name}, is ${this.age} years old,${this.gender} and ${this.color}, can jump ${this.jump} meters`; | ||
} | ||
} |
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,6 +1,6 @@ | ||
import { Rabbit } from './RabbitClass'; | ||
import { Rabbit } from './Classes/RabbitClass'; | ||
|
||
const rabbitOne = new Rabbit('Vitalik', 3, 'Brown', 'Male'); | ||
const rabbitOne = new Rabbit('Vitalik', 3, 'Brown', 'Male', 1.5); | ||
console.log(rabbitOne); | ||
const rabbitTwo = new Rabbit('LuiVitonovich', 4, 'Black', 'Female'); | ||
const rabbitTwo = new Rabbit('LuiVitonovich', 4, 'Black', 'Female', 1); | ||
console.log(rabbitTwo); |
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,11 @@ | ||
import { Animal } from './Classes/AnimalSuperclass'; | ||
import { Parrot } from './Classes/ParrotClass'; | ||
import { Rabbit } from './Classes/RabbitClass'; | ||
|
||
const animals: Animal[] = [new Parrot('Kez', 2, 'Blue', 'female', 10), new Rabbit('Nastya', 3, 'Brown', 'male', 1.5)]; | ||
export function animalsOutput(){ | ||
animals.forEach(animal => { | ||
console.log(animal.toString()); | ||
console.log(animal.sound()); | ||
}); | ||
} | ||
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 +1,4 @@ | ||
import { animalsOutput } from "./SuperClass"; | ||
Check failure on line 1 in rpgsaga/saga/src/index.ts GitHub Actions / saga-ci
|
||
console.log('Hello world'); | ||
|
||
animalsOutput() | ||
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,36 @@ | ||
import { Parrot } from "../src/Classes/ParrotClass"; | ||
|
||
describe('Parrot',()=> { | ||
let parrot: Parrot; | ||
beforeEach(()=>{ | ||
parrot = new Parrot('Sergey',4,'Black','Male',1.5); | ||
}) | ||
it('Should return right info',()=>{ | ||
expect(parrot.name).toBe('Sergey') | ||
expect(parrot.age).toBe(4) | ||
expect(parrot.color).toBe('Black') | ||
expect(parrot.gender).toBe('Male') | ||
expect(parrot.vocabulary).toBe(1.5) | ||
}) | ||
it('Should return Error when age is invalid',()=>{ | ||
expect(()=>{ | ||
parrot.age = -1 | ||
}).toThrow('Invalid age') | ||
expect(()=>{ | ||
parrot.age = 100 | ||
}).toThrow('Invalid age') | ||
}) | ||
it('Should return Error when gender is invalid',()=>{ | ||
expect(()=>{ | ||
parrot.gender='Mechanic' | ||
}).toThrow('Invalid gender') | ||
}) | ||
it('Should return Error when vocabulary has impossible value',()=>{ | ||
expect(()=>{ | ||
parrot.vocabulary = -1 | ||
}).toThrow('Impossible vocabulary') | ||
expect(()=>{ | ||
parrot.vocabulary = 22 | ||
}).toThrow('Impossible vocabulary') | ||
}) | ||
}) |
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