66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { tap, expect } from '@push.rocks/tapbundle';
|
|
import * as lik from '../ts/index.js';
|
|
|
|
let testInterestmap: lik.InterestMap<number, number>;
|
|
|
|
tap.test('should create an interestmap', async () => {
|
|
testInterestmap = new lik.InterestMap((numberArg) => {
|
|
return numberArg.toString();
|
|
});
|
|
});
|
|
|
|
tap.test('should create an interest', async () => {
|
|
testInterestmap.addInterest(3);
|
|
testInterestmap.addInterest(4);
|
|
});
|
|
|
|
tap.test('should return an already existing interest', async () => {
|
|
const interest3a = await testInterestmap.addInterest(3);
|
|
const interest3b = await testInterestmap.addInterest(3);
|
|
expect(interest3a === interest3b).toBeTrue();
|
|
});
|
|
|
|
tap.test('should be able to inform about a lost interest', async () => {
|
|
testInterestmap.informLostInterest(3);
|
|
});
|
|
|
|
tap.test('checkInterest returns true for existing', async () => {
|
|
expect(testInterestmap.checkInterest(4)).toBeTrue();
|
|
});
|
|
|
|
tap.test('checkInterest returns false for non-existing', async () => {
|
|
expect(testInterestmap.checkInterest(999)).toBeFalse();
|
|
});
|
|
|
|
tap.test('findInterest returns the interest', async () => {
|
|
const interest = testInterestmap.findInterest(4);
|
|
expect(interest).not.toBeNull();
|
|
expect(interest.originalInterest).toEqual(4);
|
|
});
|
|
|
|
tap.test('findInterest returns null for non-existing', async () => {
|
|
const interest = testInterestmap.findInterest(888);
|
|
expect(interest).toBeNull();
|
|
});
|
|
|
|
tap.test('fullfillInterest resolves the promise', async () => {
|
|
const im = new lik.InterestMap<string, string>((s) => s);
|
|
const interest = await im.addInterest('hello');
|
|
interest.fullfillInterest('world');
|
|
const result = await interest.interestFullfilled;
|
|
expect(result).toEqual('world');
|
|
expect(interest.isFullfilled).toBeTrue();
|
|
im.destroy();
|
|
});
|
|
|
|
tap.test('destroy cleans up interestmap', async () => {
|
|
const im = new lik.InterestMap<string, string>((s) => s);
|
|
await im.addInterest('a');
|
|
await im.addInterest('b');
|
|
im.destroy();
|
|
expect(im.checkInterest('a')).toBeFalse();
|
|
expect(im.checkInterest('b')).toBeFalse();
|
|
});
|
|
|
|
export default tap.start();
|