open-spaced-repetition / ts-fsrs

ts-fsrs is a versatile package based on TypeScript that supports ES modules, CommonJS, and UMD.
https://open-spaced-repetition.github.io/ts-fsrs/
MIT License
216 stars 22 forks source link

Test/update algorithm test #75

Closed ishiko732 closed 8 months ago

ishiko732 commented 8 months ago

use decimal.js to test decimal precision.

Due to the implementation of the IEEE754 standard for the number type in JavaScript, there are precision issues. For example, 0.1 + 0.2 !== 0.3. When w[4] = 5.1443 , w[5] = 1.2006:

github-actions[bot] commented 8 months ago

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/opt/hostedtoolcache/node/16.20.2/x64/bin/npx' failed with exit code 1
St.:grey_question:
Category Percentage Covered / Total
🟒 Statements 100% 305/305
🟒 Branches 100% 122/122
🟒 Functions 100% 47/47
🟒 Lines 100% 298/298

Test suite run failed

Failed tests: 5/72. Failed suites: 2/12. ``` ● forgetting_curve β€Ί retrievability expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 4 Array [ 1, - 0.946059, - 0.9299294, - 0.92216794, + 0.946058996209746, + 0.9299293969296923, + 0.9221679352414079, 0.9, - 0.79394596, + 0.7939459645042156, ] 52 | expected.push(forgetting_curve(delta_t[i], s[i])); 53 | } > 54 | expect(collection).toEqual(expected); | ^ 55 | expect(collection).toEqual([ 56 | 1.0, 0.946059, 0.9299294, 0.92216794, 0.9, 0.79394596, 57 | ]); at Object. (__tests__/algorithm.test.ts:54:24) ● init_ds β€Ί initial difficulty expect(received).toEqual(expected) // deep equality - Expected - 2 + Received + 2 Array [ - 7.5455, + 7.5455000000000005, 6.3449, 5.1443, - 3.9437, + 3.9437000000000006, ] 91 | ); 92 | }); > 93 | expect(collection).toEqual(expected); | ^ 94 | // again: w[4]-w[5]*(-2) 95 | // hard: w[4]-w[5]*(-1) 96 | // good: w[4]-w[5]*(0) at Object. (__tests__/algorithm.test.ts:93:24) ● next_ds β€Ί next_difficulty expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 4 Array [ - 6.66816418, - 5.83669392, - 5.00522366, - 4.1737534, + 6.67, + 5.84, + 5.01, + 4.17, ] 132 | expected.push(expected_d); 133 | }); > 134 | expect(collection).toEqual([6.66816418, 5.83669392, 5.00522366, 4.1737534]); | ^ 135 | expect(collection).toEqual(expected); 136 | }); 137 | at Object. (__tests__/algorithm.test.ts:134:24) ● next_ds β€Ί next_stability expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 4 Array [ - 26.98093855, - 14.12848781, - 63.60068241, - 208.72742276, + 26.98093855235639, + 14.128487814042128, + 63.60068241343109, + 208.72742275730025, ] 218 | expected_next_s.push(next_s(d[index], s[index], r[index], grade)); 219 | }); > 220 | expect(s_recall_collection).toEqual([ | ^ 221 | 26.98093855, 14.12848781, 63.60068241, 208.72742276, 222 | ]); 223 | expect(s_recall_collection).toEqual(expected_s_recall); at Object. (__tests__/algorithm.test.ts:220:33) ``` --- ``` ● FSRS V4 AC by py-fsrs β€Ί first repeat expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 1 Array [ 8.4348, 6.8686, 5.3024, - 3.7362, + 3.7361999999999993, ] 91 | } 92 | expect(stability).toEqual([1.14, 1.01, 5.44, 14.67]); > 93 | expect(difficulty).toEqual([8.4348, 6.8686, 5.3024, 3.7362]); | ^ 94 | expect(reps).toEqual([1, 1, 1, 1]); 95 | expect(lapses).toEqual([0, 0, 0, 0]); 96 | expect(elapsed_days).toEqual([0, 0, 0, 0]); at Object. (__tests__/FSRSV4.test.ts:93:24) ```

Report generated by πŸ§ͺjest coverage report action from 2133a8dbb81d638aa86e13e6c9bbba1d25eb0b5b