-
-
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
1 parent
ccf8229
commit efd0eda
Showing
5 changed files
with
175 additions
and
5 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,87 @@ | ||
/** | ||
* Represents a class for performing arithmetic operations. | ||
*/ | ||
export default class ArithmeticOp { | ||
/** | ||
* Calculates the sum of the given numbers. | ||
* @param numbers - The numbers to be summed. | ||
* @returns The sum of the numbers. | ||
*/ | ||
protected sum(...numbers: number[]): number { | ||
return numbers.reduce((acc, curr) => acc + curr, 0); | ||
} | ||
|
||
/** | ||
* Calculates the difference between the given numbers. | ||
* @param numbers - The numbers to be subtracted. | ||
* @returns The difference between the numbers. | ||
*/ | ||
protected sub(...numbers: number[]): number { | ||
return numbers.reduce((acc, curr) => acc - curr); | ||
} | ||
|
||
/** | ||
* Calculates the product of the given numbers. | ||
* @param numbers - The numbers to be multiplied. | ||
* @returns The product of the numbers. | ||
*/ | ||
protected mul(...numbers: number[]): number { | ||
return numbers.reduce((acc, curr) => acc * curr, 1); | ||
} | ||
|
||
/** | ||
* Calculates the division of the given numbers. | ||
* @param numbers - The numbers to be divided. | ||
* @returns The division of the numbers. | ||
*/ | ||
protected div(...numbers: number[]): number { | ||
return numbers.reduce((acc, curr) => acc / curr); | ||
} | ||
|
||
/** | ||
* Calculates the modulo of the given numbers. | ||
* @param numbers - The numbers to be modded. | ||
* @returns The modulo of the numbers. | ||
*/ | ||
protected mod(...numbers: number[]): number { | ||
return numbers.reduce((acc, curr) => acc % curr); | ||
} | ||
|
||
/** | ||
* Calculates the power of the given base and exponent. | ||
* @param base - The base number. | ||
* @param exponent - The exponent number. | ||
* @returns The power of the base and exponent. | ||
*/ | ||
protected power(base: number, exponent: number): number { | ||
let result = 1; | ||
for (let i = 0; i < exponent; i++) { | ||
result *= base; | ||
} | ||
return result; | ||
} | ||
|
||
public getSum() { | ||
return this.sum; | ||
} | ||
|
||
public getSub() { | ||
return this.sub; | ||
} | ||
|
||
public getMul() { | ||
return this.mul; | ||
} | ||
|
||
public getDiv() { | ||
return this.div; | ||
} | ||
|
||
public getMod() { | ||
return this.mod; | ||
} | ||
|
||
public getPower() { | ||
return this.power; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/typescript/src/generateCriticalPointInterval/index.ts
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,6 @@ | ||
export default function generateCriticalPointInterval( | ||
min: number, | ||
max: number, | ||
) { | ||
return Math.random() * (max - min + 1) + min; | ||
} |
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,54 @@ | ||
import ArithmeticOp from "../src/arithmeticOp/index"; | ||
|
||
describe("ArithmeticOp", () => { | ||
let arithmeticOp: ArithmeticOp; | ||
|
||
beforeEach(() => { | ||
arithmeticOp = new ArithmeticOp(); | ||
}); | ||
|
||
describe("sum", () => { | ||
it("should calculate the sum of the given numbers", () => { | ||
expect(arithmeticOp.getSum()(1, 2, 3)).toBe(6); | ||
expect(arithmeticOp.getSum()(10, 20, 30, 40)).toBe(100); | ||
}); | ||
}); | ||
|
||
describe("sub", () => { | ||
it("should calculate the difference between the given numbers", () => { | ||
expect(arithmeticOp.getSub()(5, 2)).toBe(3); | ||
expect(arithmeticOp.getSub()(10, 5, 3)).toBe(2); | ||
}); | ||
}); | ||
|
||
describe("mul", () => { | ||
it("should calculate the product of the given numbers", () => { | ||
expect(arithmeticOp.getMul()(2, 3)).toBe(6); | ||
expect(arithmeticOp.getMul()(5, 10, 2)).toBe(100); | ||
}); | ||
}); | ||
|
||
describe("div", () => { | ||
it("should calculate the division of the given numbers", () => { | ||
expect(arithmeticOp.getDiv()(10, 2)).toBe(5); | ||
expect(arithmeticOp.getDiv()(100, 5, 2)).toBe(10); | ||
}); | ||
}); | ||
|
||
describe("mod", () => { | ||
it("should calculate the modulo of the given numbers", () => { | ||
expect(arithmeticOp.getMod()(10, 3)).toBe(1); | ||
expect(arithmeticOp.getMod()(100, 5, 3)).toBe(0); | ||
expect(arithmeticOp.getMod()(100, 54, 6)).toBe(4); | ||
}); | ||
}); | ||
|
||
describe("power", () => { | ||
it("should calculate the power of the given base and exponent", () => { | ||
expect(arithmeticOp.getPower()(2, 3)).toBe(8); | ||
expect(arithmeticOp.getPower()(5, 3)).toBe(125); | ||
expect(arithmeticOp.getPower()(-10, 2)).toBe(100); | ||
expect(arithmeticOp.getPower()(-2, 3)).toBe(-8); | ||
}); | ||
}); | ||
}); |
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