Skip to content

Commit

Permalink
LAB_3_FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimChmirkov committed Jan 6, 2025
1 parent d0cd1a3 commit a379486
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
22 changes: 11 additions & 11 deletions rpgsaga/saga/src/class_dog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ export class Dog {
private _weight: number;

constructor(dogName: string, dogAge: number, dogWeight: number) {
this._name = dogName;
this._age = dogAge;
this._weight = dogWeight;
this.name = dogName;
this.age = dogAge;
this.weight = dogWeight;
}

public set name(name: string) {
this._name = name;
}

public get name(): string {
return this._name;
}

public set age(age: number) {
if (age >= 0 && age <= 20) {
this._age = age;
Expand All @@ -25,10 +21,6 @@ export class Dog {
}
}

public get age(): number {
return this._age;
}

public set weight(weight: number) {
if (weight > 0 && weight <= 45) {
this._weight = weight;
Expand All @@ -37,6 +29,14 @@ export class Dog {
}
}

public get name(): string {
return this._name;
}

public get age(): number {
return this._age;
}

public get weight(): number {
return this._weight;
}
Expand Down
6 changes: 6 additions & 0 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ console.log(Dog1);

const Dog2 = new Dog('Bonya', 12, 15);
console.log(Dog2);

const Dog4 = new Dog('Borya', 10, 200);
console.log(Dog4);

const Dog3 = new Dog('Nyusha', 100, 5);
console.log(Dog3);
28 changes: 28 additions & 0 deletions rpgsaga/saga/tests/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,44 @@ describe('Constructor test', () => {
});
});

describe('Constructor test', () => {
it('should create a dog', () => {
const dog = new Dog('Test', -10, 20);
expect(dog.name).toStrictEqual('Test');
expect(dog.age).toStrictEqual(-10);
expect(dog.weight).toStrictEqual(20);
});
});

describe('Constructor test', () => {
it('should create a dog', () => {
const dog = new Dog('Test', -10, -20);
expect(dog.name).toStrictEqual('Test');
expect(dog.age).toStrictEqual(-10);
expect(dog.weight).toStrictEqual(-20);
});
});

describe('SetAge func test', () => {
it('should set 5', () => {
const dog = new Dog('Test', 5, 2);
expect(dog.age).toStrictEqual(5);
});
it('should throw error', () => {
expect(() => {
new Dog('Test', 100, 5);
}).toThrow('Wrong age');
});
});

describe('SetWeight func test', () => {
it('should set 10', () => {
const dog = new Dog('Test', 5, 10);
expect(dog.weight).toStrictEqual(10);
});
it('should throw error', () => {
expect(() => {
new Dog('Test', 2, 200);
}).toThrow('Wrong weight');
});
});

0 comments on commit a379486

Please sign in to comment.