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
5 changed files
with
115 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Person } from "./Person"; | ||
|
||
export class Customer extends Person { | ||
toString() { | ||
return 'У Customer toString() переопределён'; | ||
} | ||
come(): void { | ||
console.log(`${this.name} пришёл домой`); | ||
} | ||
} | ||
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,37 @@ | ||
export abstract class Person { | ||
private _name: string; | ||
private _age: number; | ||
private _sick: boolean; | ||
|
||
constructor(name: string, age: number, isSick: boolean = false) { | ||
this._name = name; | ||
this.age = age; | ||
this._sick = isSick; | ||
} | ||
|
||
abstract come(): void; | ||
abstract toString(): void; | ||
|
||
public get sick(): boolean { | ||
return this._sick; | ||
} | ||
public set sick(isSick: boolean) { | ||
this._sick = isSick; | ||
} | ||
|
||
public get name(): string { | ||
return this._name; | ||
} | ||
public set name(name: string) { | ||
this._name = name; | ||
} | ||
public get age(): number { | ||
return this._age; | ||
} | ||
public set age(age: number) { | ||
if (age < 0) { | ||
throw new Error('Age cannot be negative.'); | ||
} | ||
this._age = age; | ||
} | ||
} |
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,17 @@ | ||
import { Customer } from "../src/Customer"; | ||
|
||
describe('test log', () => { | ||
it('should return true', () => { | ||
const customer1 = new Customer('Roman', 32); | ||
expect(customer1.toString()).toEqual('У Customer toString() переопределён'); | ||
}) | ||
it('should return true', () => { | ||
const customer1 = new Customer('Artem', 50); | ||
expect(customer1.name).toEqual('Artem'); | ||
}) | ||
it('should return true', () => { | ||
const customer1 = new Customer('Andrey', 32); | ||
customer1.age = 40; | ||
expect(customer1.age).toEqual(40); | ||
}) | ||
}); |