Skip to content

Commit

Permalink
test for mathematical error for #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Yurov committed Sep 18, 2024
1 parent fd90f62 commit 60fa383
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/sma/sma.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ describe('Simple Moving Average', () => {
expect(calc).toEqual(cross);
});
});

it('Machine precision error', () => {
const array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
const localSMA = new SMA(20);
const idealSMAValue = 20.5;

let lastValue = 0;

for (let i = 0; i < array.length; i++) {
lastValue = localSMA.nextValue(array[i])!;
}

console.log(lastValue, idealSMAValue);
});
});

0 comments on commit 60fa383

Please sign in to comment.