Skip to content

Commit

Permalink
fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sps35 committed Nov 7, 2024
1 parent e6f692c commit 47ba603
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 93 deletions.
146 changes: 75 additions & 71 deletions rpgsaga/saga/src/fox.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
export enum Colors {
Red = "red",
White = "white",
Grey = "grey",
Black = "black",
}

export class Fox {
private name: string;
private age: number;
private color: Colors;

constructor(name: string, age: number, color: Colors) {
this.name = name;

const ageError = this.setAge(age);
if (ageError) throw ageError;

const colorError = this.setColor(color);
if (colorError) throw colorError;
export enum Colors {
Red = 'red',
White = 'white',
Grey = 'grey',
Black = 'black',
}

export class Fox {
private name: string;
private age: number;
private color: Colors;

constructor(name: string, age: number, color: Colors) {
this.name = name;

const ageError = this.setAge(age);
if (ageError) {
throw ageError;
}

const colorError = this.setColor(color);
if (colorError) {
throw colorError;
}

public getView(): string {
return `
}

public getView(): string {
return `
/\\ /\\
//\\\\_//\\\\ ____
\\_ _/ / /
Expand All @@ -32,55 +36,55 @@
[ [ / \\/ _/
_[ [ \\ /_/
`;
}

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

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

public getColor(): Colors {
return this.color;
}

public setAge(age: number) {
if (age >= 0 && age < 33) {
this.age = age;
return null;
}

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

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

public getColor(): Colors {
return this.color;
}

public setAge(age: number) {
if (age >= 0 && age < 33) {
this.age = age;
return null;
}
return new Error("foxes don't live so long");
}

public setColor(color: Colors) {
if (Object.values(Colors).includes(color)) {
this.color = color;
return null;
}
return new Error("foxes don't have such color");
}

public displayFox(): void {
console.log(` Name - ${this.name}`);
console.log(` Age - ${this.age}`);
console.log(` Color - ${this.color}`);
}
return new Error("foxes don't live so long");
}

function newFox(name: string, age: number, color: Colors): Fox | Error {
try {
return new Fox(name, age, color);
} catch (error) {
return error as Error;

public setColor(color: Colors) {
if (Object.values(Colors).includes(color)) {
this.color = color;
return null;
}
return new Error("foxes don't have such color");
}

public displayFox(): void {
console.log(` Name - ${this.name}`);
console.log(` Age - ${this.age}`);
console.log(` Color - ${this.color}`);
}
}

function newFox(name: string, age: number, color: Colors): Fox | Error {
try {
return new Fox(name, age, color);
} catch (error) {
return error as Error;
}

const fox = newFox("Foxy", 5, Colors.Red);
if (fox instanceof Fox) {
fox.displayFox();
console.log(fox.getView());
} else {
console.error(fox.message);
}
}

const fox = newFox('Foxy', 5, Colors.Red);
if (fox instanceof Fox) {
fox.displayFox();
console.log(fox.getView());
} else {
console.error(fox.message);
}
24 changes: 12 additions & 12 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ function calcY(a: number, b: number, x: number): number | undefined{
return Y;
}

function TaskA(a: number, b: number, x_start: number, x_end: number, x_delta: number): number[] | undefined{
function taskA(a: number, b: number, xStart: number, xEnd: number, xDelta: number): number[] | undefined{
let result = [];
if (x_delta === 0) {
if (xDelta === 0) {
return [];
}
if (x_delta > 0) {
for (let i = x_start; i <= x_end; i+=x_delta) {
if (xDelta > 0) {
for (let i = xStart; i <= xEnd; i+=xDelta) {
result.push(calcY(a,b,i))
}
}
else {
for (let i = x_start; i >= x_end; i+=x_delta) {
for (let i = xStart; i >= xEnd; i+=xDelta) {
if ((b * i - Math.PI / 2) % Math.PI === 0) {
continue;
}
Expand All @@ -38,7 +38,7 @@ function TaskA(a: number, b: number, x_start: number, x_end: number, x_delta: nu
return result;
}

function TaskB(a: number, b: number, xValues: number[]): number[] {
function taskB(a: number, b: number, xValues: number[]): number[] {
let result = [];
for (let i = 0; i < xValues.length; i++) {
const x = xValues[i];
Expand All @@ -48,10 +48,10 @@ function TaskB(a: number, b: number, xValues: number[]): number[] {
}

console.log("Ответы на задание A");
console.log(TaskA(0.1, 0.5, 0.15, 1.37, 0.25));
console.log(TaskA(0.1, 0.5, 1.37, 0.15, -0.25));
console.log(TaskA(0.1, 0.5, 0.15, 0.15, 0.25));
console.log(taskA(0.1, 0.5, 0.15, 1.37, 0.25));
console.log(taskA(0.1, 0.5, 1.37, 0.15, -0.25));
console.log(taskA(0.1, 0.5, 0.15, 0.15, 0.25));
console.log("Ответы на задание B");
console.log(TaskB(0.1, 0.5, [0, 0.3, 0.44, 0.6, 0.56]));
console.log(TaskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56]));
export { TaskA, TaskB };
console.log(taskB(0.1, 0.5, [0, 0.3, 0.44, 0.6, 0.56]));
console.log(taskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56]));
export { taskA, taskB };
20 changes: 10 additions & 10 deletions rpgsaga/saga/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TaskA, TaskB } from '../src';
import { taskA, taskB } from '../src';

describe('Tests TaskA', () => {
it('should return 6 values', () => {
Expand All @@ -9,24 +9,24 @@ describe('Tests TaskA', () => {
0.00268923918619863,
0.006831733643974267
];
expect(TaskA(0.1, 0.5, 0.15, 1.37, 0.25)).toEqual(result);
expect(taskA(0.1, 0.5, 0.15, 1.37, 0.25)).toEqual(result);
});

it('should return empty array if x_start is greater than x_end', () => {
expect(TaskA(0.1, 0.5, 1.37, 0.15, 0.25)).toEqual([]);
expect(taskA(0.1, 0.5, 1.37, 0.15, 0.25)).toEqual([]);
});

it('should return empty array if x_delta is zero', () => {
expect(TaskA(0.1, 0.5, 0.15, 1.37, 0)).toEqual([]);
expect(taskA(0.1, 0.5, 0.15, 1.37, 0)).toEqual([]);
});

it('should return empty array if x_delta is negative and x_start is less than x_end', () => {
expect(TaskA(0.1, 0.5, 0.15, 1.37, -0.25)).toEqual([]);
expect(taskA(0.1, 0.5, 0.15, 1.37, -0.25)).toEqual([]);
});

it('should return correct values if x_start is equal to x_end', () => {
const result = [0.000023767712799773597];
expect(TaskA(0.1, 0.5, 0.15, 0.15, 0.25)).toEqual(result);
expect(taskA(0.1, 0.5, 0.15, 0.15, 0.25)).toEqual(result);
});

it('should return correct values if x_delta is negative and x_start is greater than x_end', () => {
Expand All @@ -37,7 +37,7 @@ describe('Tests TaskA', () => {
0.0007773415055814521,
0.00018471786315547907
];
expect(TaskA(0.1, 0.5, 1.37, 0.15, -0.25)).toEqual(result);
expect(taskA(0.1, 0.5, 1.37, 0.15, -0.25)).toEqual(result);
});
});

Expand All @@ -50,11 +50,11 @@ describe('Tests TaskB', () => {
0.000703217341847386,
0.0005720129283157486
];
expect(TaskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56])).toEqual(result);
expect(taskB(0.1, 0.5, [0.2, 0.3, 0.44, 0.6, 0.56])).toEqual(result);
});

it('should return empty array if xValues is empty', () => {
expect(TaskB(0.1, 0.5, [])).toEqual([]);
expect(taskB(0.1, 0.5, [])).toEqual([]);
});

it('should return undefined values if any xValue causes dTan to be zero', () => {
Expand All @@ -65,6 +65,6 @@ describe('Tests TaskB', () => {
0.000703217341847386,
0.0005720129283157486
];
expect(TaskB(0.1, 0.5, [0, 0.3, 0.44, 0.6, 0.56])).toEqual(result);
expect(taskB(0.1, 0.5, [0, 0.3, 0.44, 0.6, 0.56])).toEqual(result);
});
});

0 comments on commit 47ba603

Please sign in to comment.