Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/update algorithm test #75

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Test/update algorithm test #75

merged 1 commit into from
Mar 15, 2024

Conversation

ishiko732
Copy link
Member

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:

  • init_difficulty(Rating.Easy) = 3.9437000000000006 , expected : 3.9437
  • init_difficulty(Rating.Again) = 7.5455000000000005, expected : 7.5455
  • Math.pow(0.9, 1 / -0.5) - 1 =0.23456790123456783, expected : 0.2345679012345679

use decimal.js to test decimal precision
Copy link

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.
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.<anonymous> (__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.<anonymous> (__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.<anonymous> (__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.<anonymous> (__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.<anonymous> (__tests__/FSRSV4.test.ts:93:24)

Report generated by 🧪jest coverage report action from 2133a8d

@ishiko732 ishiko732 merged commit 93d14e7 into master Mar 15, 2024
0 of 2 checks passed
@ishiko732 ishiko732 deleted the Test/algorithm-test branch March 15, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants