From a673a5f11eb3e881f85bdc346ac991b128cbcb51 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sun, 3 Oct 2021 13:41:20 +0200 Subject: [PATCH] missing change --- backend/src/util/decay.test.ts | 24 +++++++++++++++++++++++- backend/src/util/decay.ts | 8 ++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/backend/src/util/decay.test.ts b/backend/src/util/decay.test.ts index 645cdf6f0..1dbd37595 100644 --- a/backend/src/util/decay.test.ts +++ b/backend/src/util/decay.test.ts @@ -1,6 +1,28 @@ -import { calculateDecay } from './decay' +import { decayFormula, calculateDecay } from './decay' describe('utils/decay', () => { + describe('decayFormula', () => { + it('has base 0.99999997802044727', async () => { + const amount = 1.0 + const seconds = 1 + expect(await decayFormula(amount, seconds)).toBe(0.99999997802044727) + }) + it.skip('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 () => { + 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 + const seconds = 1 + expect(await decayFormula(amount, seconds)).toBe(1.0) + }) + }) it.skip('has base 0.99999997802044727', async () => { const now = new Date() now.setSeconds(1) diff --git a/backend/src/util/decay.ts b/backend/src/util/decay.ts index 7b064b0b1..7ea97ada9 100644 --- a/backend/src/util/decay.ts +++ b/backend/src/util/decay.ts @@ -1,9 +1,9 @@ import { getCustomRepository } from 'typeorm' -import { Decay } from '../graphql/models/Decay' +import { Decay } from '../graphql/model/Decay' import { TransactionRepository } from '../typeorm/repository/Transaction' -function decayFormula(amount: number, durationInSeconds: number): number { - return amount * Math.pow(0.99999997802044727, durationInSeconds) +function decayFormula(amount: number, seconds: number): number { + return amount * Math.pow(0.99999997802044727, seconds) // This number represents 50% decay a year } async function calculateDecay(amount: number, from: Date, to: Date): Promise { @@ -56,4 +56,4 @@ async function calculateDecayWithInterval( return result } -export { calculateDecay, calculateDecayWithInterval } +export { decayFormula, calculateDecay, calculateDecayWithInterval }