circular_buffer_js icon indicating copy to clipboard operation
circular_buffer_js copied to clipboard

circular_buffer.rotateRight()

Open machinshin opened this issue 4 years ago • 2 comments

starting to figure this out. got a typescript error:

> [email protected] test /Users/vat/workspace/StoneCypher/circular_buffer_js
> jest --color --verbose && jest -c jest-stoch.config.js --color --verbose


 FAIL  src/ts/tests/circular_buffer.spec.ts
  ● Test suite failed to run

    src/ts/circular_buffer.ts:62:28 - error TS2345: Argument of type 'T | undefined' is not assignable to parameter of type 'T'.
      'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
        Type 'undefined' is not assignable to type 'T'.
          'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.

    62       this._values.unshift(this.pop());
                                  ~~~~~~~~~~

 PASS  src/ts/tests/rig.spec.ts
  ✓ Tests are running (arithmetic isn't wrong) (2 ms)
  ✓ fast-check is running (stoch arithmetic isn't wrong) (18 ms)

Running coverage on untested files...Failed to collect coverage from /Users/vat/workspace/StoneCypher/circular_buffer_js/src/ts/circular_buffer.ts
ERROR: src/ts/circular_buffer.ts:62:28 - error TS2345: Argument of type 'T | undefined' is not assignable to parameter of type 'T'.
  'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
    Type 'undefined' is not assignable to type 'T'.
      'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.

62       this._values.unshift(this.pop());
                              ~~~~~~~~~~
STACK:
--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------|---------|----------|---------|---------|-------------------
All files           |       0 |      100 |     100 |       0 |
 package_version.ts |       0 |      100 |     100 |       0 | 4-7
--------------------|---------|----------|---------|---------|-------------------
Jest: "global" coverage threshold for statements (90%) not met: 0%
Jest: "global" coverage threshold for lines (90%) not met: 0%
Test Suites: 1 failed, 1 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        9.511 s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest --color --verbose && jest -c jest-stoch.config.js --color --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vat/.npm/_logs/2021-02-03T23_16_58_642Z-debug.log
npm run test  21.00s user 3.10s system 98% cpu 24.455 total

machinshin avatar Feb 03 '21 23:02 machinshin

@machinshin nudge

StoneCypher avatar Jul 19 '21 16:07 StoneCypher

the reason it's doing this is that you didn't handle the case for when the container is empty

using c++ terminology, a container of type T doesn't always return type T - it can return undefined if there's nothing in there

what one would need to do is handle undefined first

StoneCypher avatar May 11 '22 14:05 StoneCypher