mtcute/packages/core/tests/lru-set.spec.ts
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

95 lines
2.8 KiB
TypeScript

import { expect } from 'chai'
import Long from 'long'
import { describe, it } from 'mocha'
import { LruSet } from '../utils.js'
describe('LruSet', () => {
describe('for strings', () => {
it('when 1 item is added, it is in the set', () => {
const set = new LruSet(2)
set.add('first')
expect(set.has('first')).true
})
it('when =capacity items are added, they are all in the set', () => {
const set = new LruSet(2)
set.add('first')
set.add('second')
expect(set.has('first')).true
expect(set.has('second')).true
})
it('when >capacity items are added, only the last <capacity> are in the set', () => {
const set = new LruSet(2)
set.add('first')
set.add('second')
set.add('third')
expect(set.has('first')).false
expect(set.has('second')).true
expect(set.has('third')).true
})
it('when the same added is while not eliminated, it is ignored', () => {
const set = new LruSet(2)
set.add('first')
set.add('second')
set.add('first')
set.add('third')
expect(set.has('first')).false
expect(set.has('second')).true
expect(set.has('third')).true
})
})
describe('for Longs', () => {
it('when 1 item is added, it is in the set', () => {
const set = new LruSet(2, true)
set.add(Long.fromNumber(1))
expect(set.has(Long.fromNumber(1))).true
})
it('when =capacity items are added, they are all in the set', () => {
const set = new LruSet(2, true)
set.add(Long.fromNumber(1))
set.add(Long.fromNumber(2))
expect(set.has(Long.fromNumber(1))).true
expect(set.has(Long.fromNumber(2))).true
})
it('when >capacity items are added, only the last <capacity> are in the set', () => {
const set = new LruSet(2, true)
set.add(Long.fromNumber(1))
set.add(Long.fromNumber(2))
set.add(Long.fromNumber(3))
expect(set.has(Long.fromNumber(1))).false
expect(set.has(Long.fromNumber(2))).true
expect(set.has(Long.fromNumber(3))).true
})
it('when the same added is while not eliminated, it is ignored', () => {
const set = new LruSet(2, true)
set.add(Long.fromNumber(1))
set.add(Long.fromNumber(2))
set.add(Long.fromNumber(1))
set.add(Long.fromNumber(3))
expect(set.has(Long.fromNumber(1))).false
expect(set.has(Long.fromNumber(2))).true
expect(set.has(Long.fromNumber(3))).true
})
})
})