From ecb0fe287d880649e573ed07cff1a63780caffd0 Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Sun, 10 Oct 2021 16:17:10 +0200 Subject: [PATCH] fix test and more checks --- backend/src/util/decay.test.ts | 15 ++++++++------- backend/src/util/decay.ts | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/src/util/decay.test.ts b/backend/src/util/decay.test.ts index 3a1c33716..e34d8b58b 100644 --- a/backend/src/util/decay.test.ts +++ b/backend/src/util/decay.test.ts @@ -2,24 +2,25 @@ import { decayFormula, calculateDecay } from './decay' describe('utils/decay', () => { describe('decayFormula', () => { - it('has base 0.99999997802044727', async () => { + it('has base 0.99999997802044727', () => { const amount = 1.0 const seconds = 1 - expect(await decayFormula(amount, seconds)).toBe(0.99999997802044727) + expect(decayFormula(amount, seconds)).toBe(0.99999997802044727) }) // Not sure if the following skiped tests make sence!? - it.skip('has negative decay?', async () => { + it('has negative decay?', async () => { const amount = -1.0 const seconds = 1 expect(await decayFormula(amount, seconds)).toBe(-0.99999997802044727) }) - it.skip('has correct backward calculation', async () => { + it('has correct backward calculation', async () => { const amount = 1.0 const seconds = -1 expect(await decayFormula(amount, seconds)).toBe(1.0000000219795533) }) - it.skip('has correct forward calculation', async () => { - const amount = 1.000000219795533 + // not possible, nodejs hasn't enough accuracy + it('has correct forward calculation', async () => { + const amount = 1.0 / 0.99999997802044727 const seconds = 1 expect(await decayFormula(amount, seconds)).toBe(1.0) }) @@ -32,7 +33,7 @@ describe('utils/decay', () => { expect(await calculateDecay(1.0, oneSecondAgo, now)).toBe(0.99999997802044727) }) - it.skip('returns input amount when from and to is the same', async () => { + it('returns input amount when from and to is the same', async () => { const now = new Date() expect(await calculateDecay(100.0, now, now)).toBe(100.0) }) diff --git a/backend/src/util/decay.ts b/backend/src/util/decay.ts index 9fdbac7c2..4e03aa596 100644 --- a/backend/src/util/decay.ts +++ b/backend/src/util/decay.ts @@ -10,6 +10,12 @@ async function calculateDecay(amount: number, from: Date, to: Date): Promise