mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
missing change
This commit is contained in:
parent
fa5860ee47
commit
a673a5f11e
@ -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)
|
||||||
|
|||||||
@ -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 }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user