missing change

This commit is contained in:
Ulf Gebhardt 2021-10-03 13:41:20 +02:00
parent fa5860ee47
commit a673a5f11e
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 27 additions and 5 deletions

View File

@ -1,6 +1,28 @@
import { calculateDecay } from './decay' import { decayFormula, calculateDecay } from './decay'
describe('utils/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 () => { it.skip('has base 0.99999997802044727', async () => {
const now = new Date() const now = new Date()
now.setSeconds(1) now.setSeconds(1)

View File

@ -1,9 +1,9 @@
import { getCustomRepository } from 'typeorm' import { getCustomRepository } from 'typeorm'
import { Decay } from '../graphql/models/Decay' import { Decay } from '../graphql/model/Decay'
import { TransactionRepository } from '../typeorm/repository/Transaction' import { TransactionRepository } from '../typeorm/repository/Transaction'
function decayFormula(amount: number, durationInSeconds: number): number { function decayFormula(amount: number, seconds: number): number {
return amount * Math.pow(0.99999997802044727, durationInSeconds) return amount * Math.pow(0.99999997802044727, seconds) // This number represents 50% decay a year
} }
async function calculateDecay(amount: number, from: Date, to: Date): Promise<number> { async function calculateDecay(amount: number, from: Date, to: Date): Promise<number> {
@ -56,4 +56,4 @@ async function calculateDecayWithInterval(
return result return result
} }
export { calculateDecay, calculateDecayWithInterval } export { decayFormula, calculateDecay, calculateDecayWithInterval }