-
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.
Merge pull request #6 from EugeneWWolf/Ermakova_Ksenija_Dmitrievna
Pig class finished
- Loading branch information
Showing
3 changed files
with
1,738 additions
and
1,915 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,34 @@ | ||
export class Pig | ||
{ | ||
private _mass: number; | ||
public identificator: string; // Код на бирке у свиньи | ||
|
||
constructor(mass: number, identificator: string) | ||
{ | ||
this.mass = mass; | ||
this.identificator = identificator; | ||
} | ||
|
||
get mass(): number | ||
{ | ||
return this._mass; | ||
} | ||
|
||
set mass(value: number) | ||
{ | ||
if (value >= 50) | ||
{ | ||
this._mass = value; | ||
} | ||
else | ||
{ | ||
throw new Error("Pig's mass should be 50 kg or bigger."); | ||
} | ||
} | ||
|
||
getSalo(): number | ||
{ | ||
// Допускается, что количество получаемого со свиньи сала равно 20% от её массы тела | ||
return this._mass * 0.2; | ||
} | ||
} |
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,27 @@ | ||
import { Pig } from '../src/pig'; | ||
|
||
describe('Testing pig constructor', () => { | ||
it('Pig should be created', () => { | ||
const pig = new Pig(500, "DIV69"); | ||
expect(pig.mass).toEqual(500); | ||
expect(pig.identificator).toEqual("DIV69"); | ||
}); | ||
it('Pig with invalid mass', () => { | ||
expect(() => new Pig(10, "RIP38")).toThrow(Error("Pig's mass should be 50 kg or bigger.")); | ||
}); | ||
}); | ||
|
||
describe('Testing pig methods', () => { | ||
it('Should give right amount of сало', () => { | ||
const pig = new Pig(100, "ADB69"); | ||
expect(pig.getSalo()).toEqual(20); | ||
}); | ||
it('Should be able to return float values', () => { | ||
const pig = new Pig(101, "ADB69"); | ||
expect(pig.getSalo()).toBeCloseTo(20.2); | ||
}); | ||
it('Should be able to work with float values', () => { | ||
const pig = new Pig(100.5, "ADB69"); | ||
expect(pig.getSalo()).toBeCloseTo(20.1); | ||
}); | ||
}); |
Oops, something went wrong.