Skip to content

Commit

Permalink
lab 3
Browse files Browse the repository at this point in the history
  • Loading branch information
makhotinna committed Nov 21, 2024
1 parent b405614 commit b49a8d9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 35 deletions.
27 changes: 5 additions & 22 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
export const calc = (a: number, b: number, x: number): number => {
const answer = ((a + Math.tan(b * x)) ^ 2) / ((b + 1 / Math.tan(a * x)) ^ 2);
return answer;
};
import { City } from './labs/lab3/city';

export const taskA = (a: number, b: number, x1: number, x2: number, deltax: number): number[] => {
const answersA: number[] = [];
let x = x1;
for (x; x < x2; x += deltax) {
answersA.push(calc(a, b, x));
}
return answersA;
};
const city1 = new City('Moscow', 10, 'Russia');
console.log(city1);

export const taskB = (a: number, b: number, znX: number[]): number[] => {
const answersB: number[] = [];
for (let i = 0; i < 5; i++) {
answersB.push(calc(a, b, znX[i]));
}
return answersB;
};

console.log(taskA(0.1, 0.5, 0.15, 1.37, 0.25));
console.log(taskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56]));
const city2 = new City('Amsterdam', 25, 'Netherlands');
console.log(city2);
24 changes: 24 additions & 0 deletions rpgsaga/saga/src/labs/lab2/lab2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const calc = (a: number, b: number, x: number): number => {
const answer = ((a + Math.tan(b * x)) ^ 2) / ((b + 1 / Math.tan(a * x)) ^ 2);
return answer;
};

export const taskA = (a: number, b: number, x1: number, x2: number, deltax: number): number[] => {
const answersA: number[] = [];
let x = x1;
for (x; x < x2; x += deltax) {
answersA.push(calc(a, b, x));
}
return answersA;
};

export const taskB = (a: number, b: number, znX: number[]): number[] => {
const answersB: number[] = [];
for (let i = 0; i < 5; i++) {
answersB.push(calc(a, b, znX[i]));
}
return answersB;
};

console.log(taskA(0.1, 0.5, 0.15, 1.37, 0.25));
console.log(taskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56]));
39 changes: 39 additions & 0 deletions rpgsaga/saga/src/labs/lab3/city.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export class City {
private _name: string;
private _population: number;
private _country: string;

constructor(name: string, population: number, country: string) {
this.name = name;
this.population = population;
this.country = country;
}

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

public set population(population: number) {
if (population >= 1 && population <= 2000000) {
this._population = population;
} else {
throw new Error('Wrong population');
}
}

public set country(country: string) {
this._country = country;
}

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

public get population() {
return this._population;
}

public get country() {
return this._country;
}
}
39 changes: 26 additions & 13 deletions rpgsaga/saga/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import * as pointer from '../src/index';
import { City } from '../src/labs/lab3/city';

describe('calc', () => {
it('should not be NaN', () => {
expect(Number.isNaN(pointer.calc(1.2, 0.48, 0.7))).toStrictEqual(false);
describe('Constructor test', () => {
it('should create a bunny', () => {
const city = new City('Test', 100000, 'Test');
expect(city.name).toStrictEqual('Test');
expect(city.population).toStrictEqual(100000);
expect(city.country).toStrictEqual('Test');
});
it('should be NaN', () => {
expect(pointer.calc(1.2, 0.48, 15)).toStrictEqual(0);
});

describe('SetPopulation func test', () => {
it('should set 10000', () => {
const bunny = new City('Test', 10000, 'Test');
expect(bunny.population).toStrictEqual(10000);
});
it('should throw error', () => {
expect(() => {
new City('Test', -1, 'Test');
}).toThrow('Wrong population');
});
});

describe('taskA', () => {
it('should be empty if x1 > x2', () => {
expect(pointer.taskA(1.2, 0.48, 2, 0.5, 0.3)).toStrictEqual([]);
describe('SetCountry func test', () => {
it('should set Russia', () => {
const bunny = new City('Test', 5, 'Russia');
expect(bunny.country).toStrictEqual('Russia');
});
});

describe('taskB', () => {
const expected = 5;
it('length of resulting array should equal 6', () => {
expect(pointer.taskB(1.2, 0.48, [0.25, 0.36, 0.56, 0.94, 1.28, 1.7]).length).toStrictEqual(expected);
describe('SetCountry func test', () => {
it('should set Moscow', () => {
const bunny = new City('Moscow', 5, 'Test');
expect(bunny.name).toStrictEqual('Moscow');
});
});

0 comments on commit b49a8d9

Please sign in to comment.