UNPKG

@synotech/utils

Version:

a collection of utilities for internal use

120 lines (98 loc) 3.28 kB
import { MathCryptography } from '../math.cryptography'; describe('MathCrypto', () => { let mathCryptography: MathCryptography; // Setup before each test beforeAll(() => { mathCryptography = new MathCryptography(); }); describe('math: add', () => { test('adds two numbers correctly', () => { expect(mathCryptography.add('0.12455225', '0.32540000')).toBe( '0.44995225' ); }); test('adds multiple numbers correctly', () => { expect( mathCryptography.add('0.12455225', '0.32540000', '0.1') ).toBe('0.54995225'); }); test('adds large numbers correctly', () => { expect( mathCryptography.add( '0.12345678901234567890', '0.17000000000000000000000000' ) ).toBe('0.2934567890123456789'); }); }); describe('math: subtract', () => { test('subtracts two numbers correctly', () => { expect(mathCryptography.subtract('0.32540000', '0.12455225')).toBe( '0.20084775' ); }); test('subtracts multiple numbers correctly', () => { expect( mathCryptography.subtract('0.32540000', '0.12455225', '0.1') ).toBe('0.10084775'); }); test('subtracts large numbers correctly', () => { expect( mathCryptography.subtract('42.12345678901234567890', '0.1') ).toBe('42.0234567890123456789'); }); }); describe('math: multiply', () => { test('multiplies two positive numbers', () => { expect(mathCryptography.multiply('0.1', '0.2')).toBe('0.02'); }); test('multiplies negative and positive numbers', () => { expect(mathCryptography.multiply('-0.1', '0.2')).toBe('-0.02'); }); test('multiplies multiple numbers', () => { expect(mathCryptography.multiply('0.1', '0.2', '0.3')).toBe( '0.006' ); }); }); describe('math: divide', () => { test('divides two positive numbers', () => { expect(mathCryptography.divide('0.3', '0.1')).toBe('3'); }); test('divides negative and positive numbers', () => { expect(mathCryptography.divide('-0.2', '0.1')).toBe('-2'); }); test('divides multiple numbers', () => { expect(mathCryptography.divide('0.6', '0.2', '0.1')).toBe('30'); }); test('throws error when dividing by zero', () => { expect(() => { mathCryptography.divide('0.1', '0'); }).toThrow('Division by zero'); }); }); describe('greaterThan', () => { test('should return true if the first number is greater than the second', () => { expect(mathCryptography.greaterThan('5', '2')).toBe(true); }); test('should return false if the first number is less than the second', () => { expect(mathCryptography.greaterThan('2', '5')).toBe(false); }); test('should return false if the numbers are equal', () => { expect(mathCryptography.greaterThan('3', '3')).toBe(false); }); }); describe('greaterThanOrEqualTo', () => { test('should return true if the first number is greater than the second', () => { expect( mathCryptography.greaterThanOrEqualTo('2.000000000001', '2') ).toBe(true); }); test('should return true if the numbers are equal', () => { expect(mathCryptography.greaterThanOrEqualTo('3', '3')).toBe(true); }); test('should return false if the first number is less than the second', () => { expect(mathCryptography.greaterThanOrEqualTo('1', '3')).toBe(false); }); }); });