From 4f43c78e672f86a3144336de0f2a71b12747b871 Mon Sep 17 00:00:00 2001 From: jamashita Date: Wed, 17 Apr 2024 10:15:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20biome=20applied?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/address/AAddress.ts | 34 +-- src/address/Address.ts | 6 +- src/address/AddressUtil.ts | 52 ++-- src/address/ImmutableAddress.ts | 12 +- src/address/MutableAddress.ts | 12 +- src/address/ReadonlyAddress.ts | 4 +- src/address/__tests__/AAddress.spec.ts | 130 +++------ src/address/__tests__/AddressUtil.spec.ts | 23 +- .../__tests__/ImmutableAddress.spec.ts | 68 ++--- src/address/__tests__/MutableAddress.spec.ts | 63 ++--- src/address/mock/MockAddress.ts | 4 +- src/collection/Collection.ts | 2 +- src/collection/Quantity.ts | 4 +- src/dictionary/ADictionary.ts | 26 +- src/dictionary/Dictionary.ts | 6 +- src/dictionary/DictionaryUtil.ts | 55 ++-- src/dictionary/ImmutableDictionary.ts | 8 +- src/dictionary/MutableDictionary.ts | 8 +- src/dictionary/ReadonlyDictionary.ts | 4 +- src/dictionary/__tests__/ADictionary.spec.ts | 100 +++---- .../__tests__/DictionaryUtil.spec.ts | 16 +- .../__tests__/ImmutableDictionary.spec.ts | 57 ++-- .../__tests__/MutableDictionary.spec.ts | 46 +--- src/sequence/ASequence.ts | 31 ++- src/sequence/ImmutableSequence.ts | 8 +- src/sequence/MutableSequence.ts | 8 +- src/sequence/ReadonlySequence.ts | 4 +- src/sequence/Sequence.ts | 6 +- src/sequence/SequenceUtil.ts | 58 ++-- src/sequence/__tests__/ASequence.spec.ts | 117 +++----- .../__tests__/ImmutableSequence.spec.ts | 114 ++------ .../__tests__/MutableSequence.spec.ts | 90 ++----- src/sequence/__tests__/SequenceUtil.spec.ts | 16 +- src/tree/ATree.ts | 6 +- src/tree/ATrees.ts | 25 +- src/tree/ClosureTable/ClosureTable.ts | 28 +- .../ClosureTable/ClosureTableHierarchies.ts | 31 ++- .../ClosureTable/ClosureTableHierarchy.ts | 6 +- src/tree/ClosureTable/TreeIDFactory.ts | 4 +- .../__tests__/ClosureTable.spec.ts | 13 +- .../__tests__/ClosureTableHierarchies.spec.ts | 41 ++- .../__tests__/ClosureTableHierarchy.spec.ts | 2 +- .../ClosureTable/mock/MockClosureTable.ts | 12 +- .../mock/MockClosureTableHierarchies.ts | 4 +- .../mock/MockClosureTableHierarchy.ts | 6 +- .../ClosureTable/mock/MockTreeIDFactory.ts | 2 +- src/tree/ReadonlyTrees.ts | 6 +- src/tree/SerializableTree.ts | 6 +- src/tree/SerializableTreeObject.ts | 2 +- src/tree/SerializableTrees.ts | 21 +- src/tree/StructurableTree.ts | 18 +- src/tree/StructurableTreeObject.ts | 4 +- src/tree/StructurableTrees.ts | 65 +++-- src/tree/Tree.ts | 4 +- src/tree/TreeID.ts | 2 +- src/tree/TreeNode/ATreeNode.ts | 16 +- src/tree/TreeNode/SerializableTreeNode.ts | 22 +- src/tree/TreeNode/StructurableTreeNode.ts | 13 +- src/tree/TreeNode/TreeNode.ts | 4 +- src/tree/TreeNode/__tests__/ATreeNode.spec.ts | 194 ++++++------- .../__tests__/SerializableTreeNode.spec.ts | 136 +++++----- .../__tests__/StructurableTreeNode.spec.ts | 174 ++++++------ src/tree/TreeNode/mock/MockTreeNode.ts | 10 +- src/tree/Trees.ts | 4 +- src/tree/__tests__/SerializableTree.spec.ts | 2 +- src/tree/__tests__/SerializableTrees.spec.ts | 101 ++----- src/tree/__tests__/StructurableTree.spec.ts | 8 +- src/tree/__tests__/StructurableTrees.spec.ts | 102 ++----- src/tree/__tests__/Tree.spec.ts | 144 +++------- src/tree/__tests__/Trees.spec.ts | 254 +++--------------- src/tree/mock/MockTree.ts | 12 +- src/tree/mock/MockTreeID.ts | 4 +- src/tree/mock/MockTreeObject.ts | 8 +- src/tree/mock/MockTrees.ts | 18 +- 74 files changed, 1028 insertions(+), 1698 deletions(-) diff --git a/src/address/AAddress.ts b/src/address/AAddress.ts index 6d7a9f8..8927065 100644 --- a/src/address/AAddress.ts +++ b/src/address/AAddress.ts @@ -1,7 +1,7 @@ import { Objet } from '@jamashita/anden/object'; -import { BinaryPredicate, ForEach, Mapping, Nullable } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; -import { Address } from './Address.js'; +import type { BinaryPredicate, ForEach, Mapping, Nullable } from '@jamashita/anden/type'; +import { type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { Address } from './Address.js'; export abstract class AAddress extends Quantity implements Address { protected readonly address: Map; @@ -55,11 +55,11 @@ export abstract class AAddress extends Quantity implements Addre protected filterInternal(predicate: NarrowingBinaryPredicate): Map { const m: Map = new Map(); - this.address.forEach((value: V) => { - if (predicate(value, undefined)) { - m.set(Quantity.genKey(value), value); + for (const [, v] of this.address) { + if (predicate(v, undefined)) { + m.set(Quantity.genKey(v), v); } - }); + } return m; } @@ -77,9 +77,9 @@ export abstract class AAddress extends Quantity implements Addre } public forEach(foreach: ForEach): void { - this.address.forEach((v: V) => { + for (const [, v] of this.address) { foreach(v); - }); + } } public get(): null { @@ -90,7 +90,9 @@ export abstract class AAddress extends Quantity implements Addre return this.address.has(Quantity.genKey(value)); } + // biome-ignore lint/suspicious/noConfusingVoidType: public iterator(): IterableIterator<[void, V]> { + // biome-ignore lint/suspicious/noConfusingVoidType: const iterable: Array<[void, V]> = []; for (const [, v] of this.address) { @@ -102,14 +104,14 @@ export abstract class AAddress extends Quantity implements Addre protected mapInternal(mapping: Mapping): Map { const m: Map = new Map(); - let i: number = 0; + let i = 0; - this.address.forEach((value: V) => { - const w: W = mapping(value, i); + for (const [, v] of this.address) { + const w: W = mapping(v, i); m.set(Quantity.genKey(w), w); i++; - }); + } return m; } @@ -117,9 +119,9 @@ export abstract class AAddress extends Quantity implements Addre public serialize(): string { const props: Array = []; - this.forEach((element: V) => { - props.push(Objet.identify(element)); - }); + for (const [, v] of this.address) { + props.push(Objet.identify(v)); + } return props.join(', '); } diff --git a/src/address/Address.ts b/src/address/Address.ts index c06ad8d..720882c 100644 --- a/src/address/Address.ts +++ b/src/address/Address.ts @@ -1,6 +1,6 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate } from '../collection/index.js'; -import { ReadonlyAddress } from './ReadonlyAddress.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import type { NarrowingBinaryPredicate } from '../collection/index.js'; +import type { ReadonlyAddress } from './ReadonlyAddress.js'; export interface Address extends ReadonlyAddress { add(value: V): Address; diff --git a/src/address/AddressUtil.ts b/src/address/AddressUtil.ts index 90b7635..80b9b1c 100644 --- a/src/address/AddressUtil.ts +++ b/src/address/AddressUtil.ts @@ -1,39 +1,41 @@ -import { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; -import { Address } from './Address.js'; -import { ReadonlyAddress } from './ReadonlyAddress.js'; +import type { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; +import type { Address } from './Address.js'; +import type { ReadonlyAddress } from './ReadonlyAddress.js'; -// eslint-disable-next-line @typescript-eslint/no-extraneous-class -export class AddressUtil { - public static await>(address: ReadonlyAddress>, callback: UnaryFunction, A>): Promise { +export namespace AddressUtil { + export const wait = >(address: ReadonlyAddress>, callback: UnaryFunction, A>): Promise => { if (address.isEmpty()) { return Promise.resolve(callback(new Set())); } - let rejected: boolean = false; + let rejected = false; const set: Set = new Set(); return new Promise((resolve: Resolve, reject: Reject) => { - address.forEach((value: PromiseLike) => { - value.then((v: V) => { - if (rejected) { - return; - } + for (const value of address.values()) { + value.then( + (v: V) => { + if (rejected) { + return; + } - set.add(v); + set.add(v); - if (set.size === address.size()) { - resolve(callback(set)); - } - }, (e: unknown) => { - if (rejected) { - return; - } + if (set.size === address.size()) { + resolve(callback(set)); + } + }, + (e: unknown) => { + if (rejected) { + return; + } - rejected = true; + rejected = true; - reject(e); - }); - }); + reject(e); + } + ); + } }); - } + }; } diff --git a/src/address/ImmutableAddress.ts b/src/address/ImmutableAddress.ts index 0d6add8..efdc0e1 100644 --- a/src/address/ImmutableAddress.ts +++ b/src/address/ImmutableAddress.ts @@ -1,14 +1,14 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; import { AAddress } from './AAddress.js'; import { AddressUtil } from './AddressUtil.js'; -import { ReadonlyAddress } from './ReadonlyAddress.js'; +import type { ReadonlyAddress } from './ReadonlyAddress.js'; export class ImmutableAddress extends AAddress { private static readonly EMPTY: ImmutableAddress = new ImmutableAddress(new Map()); public static await(address: ReadonlyAddress>): Promise> { - return AddressUtil.await(address, (values: Set) => { + return AddressUtil.wait(address, (values: Set) => { return ImmutableAddress.ofSet(values); }); } @@ -34,9 +34,9 @@ export class ImmutableAddress extends AAddress { public static ofSet(set: ReadonlySet): ImmutableAddress { const m: Map = new Map(); - set.forEach((v: V) => { + for (const v of set) { m.set(Quantity.genKey(v), v); - }); + } return ImmutableAddress.ofInternal(m); } diff --git a/src/address/MutableAddress.ts b/src/address/MutableAddress.ts index e51f849..b3b7988 100644 --- a/src/address/MutableAddress.ts +++ b/src/address/MutableAddress.ts @@ -1,12 +1,12 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; import { AAddress } from './AAddress.js'; import { AddressUtil } from './AddressUtil.js'; -import { ReadonlyAddress } from './ReadonlyAddress.js'; +import type { ReadonlyAddress } from './ReadonlyAddress.js'; export class MutableAddress extends AAddress { public static await(address: ReadonlyAddress>): Promise> { - return AddressUtil.await(address, (values: Set) => { + return AddressUtil.wait(address, (values: Set) => { return MutableAddress.ofSet(values); }); } @@ -28,9 +28,9 @@ export class MutableAddress extends AAddress { public static ofSet(set: ReadonlySet): MutableAddress { const m: Map = new Map(); - set.forEach((v: V) => { + for (const v of set) { m.set(Quantity.genKey(v), v); - }); + } return MutableAddress.ofInternal(m); } diff --git a/src/address/ReadonlyAddress.ts b/src/address/ReadonlyAddress.ts index 5a44fbe..9ae410b 100644 --- a/src/address/ReadonlyAddress.ts +++ b/src/address/ReadonlyAddress.ts @@ -1,5 +1,5 @@ -import { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; +import type { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; export interface ReadonlyAddress extends Collection, Cloneable> { filter(predicate: NarrowingBinaryPredicate): ReadonlyAddress; diff --git a/src/address/__tests__/AAddress.spec.ts b/src/address/__tests__/AAddress.spec.ts index 193405e..b739fda 100644 --- a/src/address/__tests__/AAddress.spec.ts +++ b/src/address/__tests__/AAddress.spec.ts @@ -1,5 +1,5 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Nullable, Predicate } from '@jamashita/anden/type'; +import type { Nullable, Predicate } from '@jamashita/anden/type'; import { MockAddress } from '../mock/MockAddress.js'; describe('AAddress', () => { @@ -9,9 +9,7 @@ describe('AAddress', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const address: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2])); expect(address.contains(value3)).toBe(false); }); @@ -21,9 +19,7 @@ describe('AAddress', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(2); - const address: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2])); expect(address.contains(value1)).toBe(true); expect(address.contains(value2)).toBe(true); @@ -35,9 +31,7 @@ describe('AAddress', () => { it('returns true when the same instance given', () => { const value: MockValueObject = new MockValueObject(1); - const address: MockAddress> = new MockAddress( - new Set([value]) - ); + const address: MockAddress> = new MockAddress(new Set([value])); expect(address.equals(address)).toBe(true); }); @@ -46,20 +40,14 @@ describe('AAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MockAddress> = new MockAddress( - new Set([value1]) - ); - const address2: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address1: MockAddress> = new MockAddress(new Set([value1])); + const address2: MockAddress> = new MockAddress(new Set([value1, value2])); expect(address1.equals(address2)).toBe(false); }); it('returns false when the different class instance given', () => { - const address: MockAddress> = new MockAddress( - new Set() - ); + const address: MockAddress> = new MockAddress(new Set()); expect(address.equals(new MockValueObject('mock'))).toBe(false); }); @@ -68,12 +56,8 @@ describe('AAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MockAddress> = new MockAddress( - new Set([value2, value1]) - ); - const address2: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address1: MockAddress> = new MockAddress(new Set([value2, value1])); + const address2: MockAddress> = new MockAddress(new Set([value1, value2])); expect(address1.equals(address2)).toBe(true); }); @@ -82,12 +66,8 @@ describe('AAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); - const address2: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address1: MockAddress> = new MockAddress(new Set([value1, value2])); + const address2: MockAddress> = new MockAddress(new Set([value1, value2])); expect(address1.equals(address2)).toBe(true); }); @@ -100,9 +80,7 @@ describe('AAddress', () => { const value3: MockValueObject = new MockValueObject(6); const value4: MockValueObject = new MockValueObject(8); - const address: MockAddress> = new MockAddress( - new Set([value1, value2, value3, value4]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2, value3, value4])); const every: boolean = address.every((value: MockValueObject) => { return value.get() % 2 === 0; @@ -118,24 +96,12 @@ describe('AAddress', () => { const value4: MockValueObject = new MockValueObject(8); const value5: MockValueObject = new MockValueObject(3); - const address1: MockAddress> = new MockAddress( - new Set([value1, value2, value3, value4]) - ); - const address2: MockAddress> = new MockAddress( - new Set([value2, value1, value3, value4]) - ); - const address3: MockAddress> = new MockAddress( - new Set([value2, value3, value1, value4]) - ); - const address4: MockAddress> = new MockAddress( - new Set([value2, value3, value4, value1]) - ); - const address5: MockAddress> = new MockAddress( - new Set([value1, value5, value3, value4]) - ); - const address6: MockAddress> = new MockAddress( - new Set([value1, value2, value5, value4]) - ); + const address1: MockAddress> = new MockAddress(new Set([value1, value2, value3, value4])); + const address2: MockAddress> = new MockAddress(new Set([value2, value1, value3, value4])); + const address3: MockAddress> = new MockAddress(new Set([value2, value3, value1, value4])); + const address4: MockAddress> = new MockAddress(new Set([value2, value3, value4, value1])); + const address5: MockAddress> = new MockAddress(new Set([value1, value5, value3, value4])); + const address6: MockAddress> = new MockAddress(new Set([value1, value2, value5, value4])); const predicate: Predicate> = (v: MockValueObject) => { return v.get() % 2 === 0; @@ -164,9 +130,7 @@ describe('AAddress', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const address: MockAddress> = new MockAddress( - new Set([value1, value2, value3, value4]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2, value3, value4])); const found1: Nullable> = address.find((v: MockValueObject) => { return v.get() === 1; @@ -195,12 +159,11 @@ describe('AAddress', () => { const value3: MockValueObject = new MockValueObject(3); const values: Array> = [value1, value2, value3]; - const address: MockAddress> = new MockAddress( - new Set(values) - ); - let i: number = 0; + const address: MockAddress> = new MockAddress(new Set(values)); + let i = 0; expect(address.size()).toBe(values.length); + // biome-ignore lint/complexity/noForEach: address.forEach((value: MockValueObject) => { expect(value).toBe(values[i]); i++; @@ -212,12 +175,8 @@ describe('AAddress', () => { it('always returns null', () => { const value1: MockValueObject = new MockValueObject(1); - const address1: MockAddress> = new MockAddress( - new Set() - ); - const address2: MockAddress> = new MockAddress( - new Set([value1]) - ); + const address1: MockAddress> = new MockAddress(new Set()); + const address2: MockAddress> = new MockAddress(new Set([value1])); expect(address1.size()).toBe(0); expect(address2.get()).toBeNull(); @@ -231,12 +190,8 @@ describe('AAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); - const address2: MockAddress> = new MockAddress( - new Set() - ); + const address1: MockAddress> = new MockAddress(new Set([value1, value2])); + const address2: MockAddress> = new MockAddress(new Set()); expect(address1.isEmpty()).toBe(false); expect(address2.isEmpty()).toBe(true); @@ -249,11 +204,9 @@ describe('AAddress', () => { const value2: MockValueObject = new MockValueObject(2); const values: Array> = [value1, value2]; - const address: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2])); - let i: number = 0; + let i = 0; for (const value of address) { expect(value[1]).toBe(values[i]); @@ -272,12 +225,8 @@ describe('AAddress', () => { const value6: MockValueObject = new MockValueObject(5); const value7: MockValueObject = new MockValueObject(7); - const address1: MockAddress> = new MockAddress( - new Set([value1, value2, value3, value4]) - ); - const address2: MockAddress> = new MockAddress( - new Set([value1, value5, value6, value7]) - ); + const address1: MockAddress> = new MockAddress(new Set([value1, value2, value3, value4])); + const address2: MockAddress> = new MockAddress(new Set([value1, value5, value6, value7])); const predicate: Predicate> = (v: MockValueObject) => { return v.get() % 2 === 0; @@ -296,9 +245,7 @@ describe('AAddress', () => { const value3: MockValueObject = new MockValueObject(8); const value4: MockValueObject = new MockValueObject(10); - const address: MockAddress> = new MockAddress( - new Set([value1, value2, value3, value4]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2, value3, value4])); const predicate: Predicate> = (v: MockValueObject) => { return v.get() % 2 === 1; @@ -317,13 +264,12 @@ describe('AAddress', () => { const value3: MockValueObject = new MockValueObject(3); const values: Array> = [value1, value2, value3]; - const address: MockAddress> = new MockAddress( - new Set(values) - ); + const address: MockAddress> = new MockAddress(new Set(values)); const set: Set> = address.toSet(); expect(address.size()).toBe(set.size); + // biome-ignore lint/complexity/noForEach: values.forEach((value: MockValueObject) => { expect(set.has(value)).toBe(true); }); @@ -339,9 +285,7 @@ describe('AAddress', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const address: MockAddress> = new MockAddress( - new Set([value1, value2, value3]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2, value3])); expect(address.toString()).toBe('1, 2, 3'); }); @@ -353,11 +297,9 @@ describe('AAddress', () => { const value2: MockValueObject = new MockValueObject(2); const values: Array> = [value1, value2]; - const address: MockAddress> = new MockAddress( - new Set([value1, value2]) - ); + const address: MockAddress> = new MockAddress(new Set([value1, value2])); - let i: number = 0; + let i = 0; for (const value of address.values()) { expect(value.get()).toBe(values[i]?.get()); diff --git a/src/address/__tests__/AddressUtil.spec.ts b/src/address/__tests__/AddressUtil.spec.ts index 1d4201d..17a3c26 100644 --- a/src/address/__tests__/AddressUtil.spec.ts +++ b/src/address/__tests__/AddressUtil.spec.ts @@ -1,14 +1,14 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Address } from '../Address.js'; +import type { Address } from '../Address.js'; import { AddressUtil } from '../AddressUtil.js'; import { ImmutableAddress } from '../ImmutableAddress.js'; describe('AddressUtil', () => { - describe('await', () => { + describe('wait', () => { it('returns empty set when given address is empty', async () => { const add: Address>> = ImmutableAddress.empty(); - await AddressUtil.await(add, (values: Set>) => { + await AddressUtil.wait(add, (values: Set>) => { expect(values.size).toBe(0); return ImmutableAddress.ofSet(values); @@ -21,15 +21,10 @@ describe('AddressUtil', () => { const mock3: MockValueObject = new MockValueObject(3); const mock4: MockValueObject = new MockValueObject(4); const add: Address>> = ImmutableAddress.ofSet( - new Set([ - Promise.resolve(mock1), - Promise.resolve(mock2), - Promise.resolve(mock3), - Promise.resolve(mock4) - ]) + new Set([Promise.resolve(mock1), Promise.resolve(mock2), Promise.resolve(mock3), Promise.resolve(mock4)]) ); - await AddressUtil.await(add, (values: Set>) => { + await AddressUtil.wait(add, (values: Set>) => { expect(values.size).toBe(add.size()); expect(values.has(mock1)).toBe(true); expect(values.has(mock2)).toBe(true); @@ -51,9 +46,11 @@ describe('AddressUtil', () => { ]) ); - await expect(AddressUtil.await(add, (values: Set>) => { - return ImmutableAddress.ofSet(values); - })).rejects.toThrow(err); + await expect( + AddressUtil.wait(add, (values: Set>) => { + return ImmutableAddress.ofSet(values); + }) + ).rejects.toThrow(err); }); }); }); diff --git a/src/address/__tests__/ImmutableAddress.spec.ts b/src/address/__tests__/ImmutableAddress.spec.ts index 8639f31..5bbc504 100644 --- a/src/address/__tests__/ImmutableAddress.spec.ts +++ b/src/address/__tests__/ImmutableAddress.spec.ts @@ -20,15 +20,11 @@ describe('ImmutableAddress', () => { describe('of', () => { it('returns copied collection, does not use the same one', () => { - const address: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([ - new MockValueObject(1), - new MockValueObject(2) - ]) - ); + const address: ImmutableAddress> = ImmutableAddress.ofSet(new Set([new MockValueObject(1), new MockValueObject(2)])); const copied: ImmutableAddress> = ImmutableAddress.of(address); expect(address.size()).toBe(copied.size()); + // biome-ignore lint/complexity/noForEach: address.forEach((v: MockValueObject) => { expect(copied.contains(v)).toBe(true); }); @@ -48,15 +44,9 @@ describe('ImmutableAddress', () => { }); it('returns instance', () => { - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([new MockValueObject(1), new MockValueObject(3)]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([new MockValueObject(1), new MockValueObject(3)])); const address2: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([ - new MockValueObject(2), - new MockValueObject(4), - new MockValueObject(5) - ]) + new Set([new MockValueObject(2), new MockValueObject(4), new MockValueObject(5)]) ); expect(address1.size()).toBe(2); @@ -94,9 +84,7 @@ describe('ImmutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2])); const address2: ImmutableAddress> = address1.add(value1); expect(address1).toBe(address2); @@ -120,9 +108,7 @@ describe('ImmutableAddress', () => { describe('duplicate', () => { it('returns ImmutableAddress.empty() when there are no values', () => { - const address: ImmutableAddress> = ImmutableAddress.ofSet( - new Set() - ); + const address: ImmutableAddress> = ImmutableAddress.ofSet(new Set()); expect(address.duplicate()).toBe(ImmutableAddress.empty()); }); @@ -134,14 +120,13 @@ describe('ImmutableAddress', () => { const value4: MockValueObject = new MockValueObject(4); const value5: MockValueObject = new MockValueObject(5); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2, value3, value4])); const address2: ImmutableAddress> = address1.duplicate(); expect(address1.size()).toBe(address2.size()); expect(address1).not.toBe(address2); expect(address2).not.toBe(address2.add(value5)); + // biome-ignore lint/complexity/noForEach: address1.forEach((v: MockValueObject) => { expect(address2.contains(v)).toBe(true); }); @@ -156,9 +141,7 @@ describe('ImmutableAddress', () => { const value4: MockValueObject = new MockValueObject(4); const value5: MockValueObject = new MockValueObject(5); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2, value3, value4])); const filtered1: ImmutableAddress> = address1.filter((v: MockValueObject) => { return v.get() % 2 === 0; }); @@ -178,9 +161,7 @@ describe('ImmutableAddress', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2, value3, value4])); const filtered: ImmutableAddress> = address1.filter((v: MockValueObject) => { return v.get() > 100; }); @@ -195,9 +176,7 @@ describe('ImmutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1])); const hashCode1: string = address1.hashCode(); const address2: ImmutableAddress> = address1.add(value2); const hashCode2: string = address2.hashCode(); @@ -211,12 +190,8 @@ describe('ImmutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2]) - ); - const address2: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2])); + const address2: ImmutableAddress> = ImmutableAddress.ofSet(new Set([])); expect(address1.isEmpty()).toBe(false); expect(address2.isEmpty()).toBe(true); @@ -230,15 +205,14 @@ describe('ImmutableAddress', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2, value3, value4])); const address2: ImmutableAddress> = address1.map((v: MockValueObject) => { return new MockValueObject(v.get() * 2); }); expect(address1.size()).toBe(address2.size()); expect(address1).not.toBe(address2); + // biome-ignore lint/complexity/noForEach: address2.forEach((v: MockValueObject) => { expect(v.get() % 2).toBe(0); }); @@ -250,9 +224,7 @@ describe('ImmutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2])); const address2: ImmutableAddress> = address1.remove(value1); expect(address1.size()).toBe(2); @@ -263,9 +235,7 @@ describe('ImmutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1]) - ); + const address: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1])); const beforeLength: number = address.size(); expect(address.remove(value2)).toBe(address); @@ -277,9 +247,7 @@ describe('ImmutableAddress', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(2); - const address1: ImmutableAddress> = ImmutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: ImmutableAddress> = ImmutableAddress.ofSet(new Set([value1, value2])); const address2: ImmutableAddress> = address1.remove(value3); expect(address1).not.toBe(address2); diff --git a/src/address/__tests__/MutableAddress.spec.ts b/src/address/__tests__/MutableAddress.spec.ts index adaa240..de4797c 100644 --- a/src/address/__tests__/MutableAddress.spec.ts +++ b/src/address/__tests__/MutableAddress.spec.ts @@ -20,15 +20,11 @@ describe('MutableAddress', () => { describe('of', () => { it('returns copied collection, does not use the same one', () => { - const address: MutableAddress> = MutableAddress.ofSet( - new Set([ - new MockValueObject(1), - new MockValueObject(2) - ]) - ); + const address: MutableAddress> = MutableAddress.ofSet(new Set([new MockValueObject(1), new MockValueObject(2)])); const copied: MutableAddress> = MutableAddress.of(address); expect(address.size()).toBe(copied.size()); + // biome-ignore lint/complexity/noForEach: address.forEach((v: MockValueObject) => { expect(copied.contains(v)).toBe(true); }); @@ -41,18 +37,9 @@ describe('MutableAddress', () => { describe('ofSet', () => { it('returns instance', () => { - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([ - new MockValueObject(1), - new MockValueObject(3) - ]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([new MockValueObject(1), new MockValueObject(3)])); const address2: MutableAddress> = MutableAddress.ofSet( - new Set([ - new MockValueObject(2), - new MockValueObject(4), - new MockValueObject(5) - ]) + new Set([new MockValueObject(2), new MockValueObject(4), new MockValueObject(5)]) ); expect(address1.size()).toBe(2); @@ -86,9 +73,7 @@ describe('MutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2])); const address2: MutableAddress> = address1.add(value1); expect(address1).toBe(address2); @@ -100,9 +85,7 @@ describe('MutableAddress', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(1); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2])); const address2: MutableAddress> = address1.add(value3); expect(address1).toBe(address2); @@ -118,14 +101,13 @@ describe('MutableAddress', () => { const value4: MockValueObject = new MockValueObject(4); const value5: MockValueObject = new MockValueObject(5); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2, value3, value4])); const address2: MutableAddress> = address1.duplicate(); expect(address1.size()).toBe(address2.size()); expect(address1).not.toBe(address2); expect(address2).toBe(address2.add(value5)); + // biome-ignore lint/complexity/noForEach: address1.forEach((v: MockValueObject) => { expect(address2.contains(v)).toBe(true); }); @@ -140,9 +122,7 @@ describe('MutableAddress', () => { const value4: MockValueObject = new MockValueObject(4); const value5: MockValueObject = new MockValueObject(5); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2, value3, value4])); const filtered1: MutableAddress> = address1.filter((v: MockValueObject) => { return v.get() % 2 === 0; }); @@ -162,9 +142,7 @@ describe('MutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1])); const hashCode1: string = address1.hashCode(); const address2: MutableAddress> = address1.add(value2); const hashCode2: string = address2.hashCode(); @@ -178,12 +156,8 @@ describe('MutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2]) - ); - const address2: MutableAddress> = MutableAddress.ofSet( - new Set([]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2])); + const address2: MutableAddress> = MutableAddress.ofSet(new Set([])); expect(address1.isEmpty()).toBe(false); expect(address2.isEmpty()).toBe(true); @@ -197,15 +171,14 @@ describe('MutableAddress', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2, value3, value4]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2, value3, value4])); const address2: MutableAddress> = address1.map((v: MockValueObject) => { return new MockValueObject(v.get() * 2); }); expect(address1.size()).toBe(address2.size()); expect(address1).not.toBe(address2); + // biome-ignore lint/complexity/noForEach: address2.forEach((v: MockValueObject) => { expect(v.get() % 2).toBe(0); }); @@ -217,9 +190,7 @@ describe('MutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address1: MutableAddress> = MutableAddress.ofSet( - new Set([value1, value2]) - ); + const address1: MutableAddress> = MutableAddress.ofSet(new Set([value1, value2])); const address2: MutableAddress> = address1.remove(value1); expect(address1).toBe(address2); @@ -230,9 +201,7 @@ describe('MutableAddress', () => { const value1: MockValueObject = new MockValueObject(1); const value2: MockValueObject = new MockValueObject(2); - const address: MutableAddress> = MutableAddress.ofSet( - new Set([value1]) - ); + const address: MutableAddress> = MutableAddress.ofSet(new Set([value1])); const beforeLength: number = address.size(); expect(address.remove(value2)).toBe(address); diff --git a/src/address/mock/MockAddress.ts b/src/address/mock/MockAddress.ts index 32c03bf..354023a 100644 --- a/src/address/mock/MockAddress.ts +++ b/src/address/mock/MockAddress.ts @@ -6,9 +6,9 @@ export class MockAddress extends AAddress { public constructor(set: ReadonlySet) { const map: Map = new Map(); - set.forEach((v: V) => { + for (const v of set) { map.set(Quantity.genKey(v), v); - }); + } super(map); } diff --git a/src/collection/Collection.ts b/src/collection/Collection.ts index 18bbf9d..d0788e6 100644 --- a/src/collection/Collection.ts +++ b/src/collection/Collection.ts @@ -1,4 +1,4 @@ -import { BinaryPredicate, ForEach, Mapping, Nominative, Nullable } from '@jamashita/anden/type'; +import type { BinaryPredicate, ForEach, Mapping, Nominative, Nullable } from '@jamashita/anden/type'; export type NarrowingBinaryPredicate = (arg1: A1, arg2: A2) => arg1 is B1; diff --git a/src/collection/Quantity.ts b/src/collection/Quantity.ts index 1d7222c..889af86 100644 --- a/src/collection/Quantity.ts +++ b/src/collection/Quantity.ts @@ -1,6 +1,6 @@ import { Objet } from '@jamashita/anden/object'; -import { BinaryPredicate, ForEach, isNominative, Mapping, Nullable } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from './Collection.js'; +import { type BinaryPredicate, type ForEach, isNominative, type Mapping, type Nullable } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from './Collection.js'; export abstract class Quantity extends Objet implements Collection { protected static genKey(key: T): T | string { diff --git a/src/dictionary/ADictionary.ts b/src/dictionary/ADictionary.ts index 0ca60d0..a338f85 100644 --- a/src/dictionary/ADictionary.ts +++ b/src/dictionary/ADictionary.ts @@ -1,7 +1,7 @@ import { Objet } from '@jamashita/anden/object'; -import { BinaryPredicate, ForEach, isNominative, Kind, Mapping, Nullable, Undefinable } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; -import { Dictionary } from './Dictionary.js'; +import { type BinaryPredicate, type ForEach, isNominative, Kind, type Mapping, type Nullable, type Undefinable } from '@jamashita/anden/type'; +import { type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { Dictionary } from './Dictionary.js'; export abstract class ADictionary extends Quantity implements Dictionary { protected readonly dictionary: Map; @@ -77,11 +77,11 @@ export abstract class ADictionary extends Quantity implement protected filterInternal(predicate: NarrowingBinaryPredicate): Map { const m: Map = new Map(); - this.dictionary.forEach(([k, v]: [K, V]) => { + for (const [, [k, v]] of this.dictionary) { if (predicate(v, k)) { m.set(Quantity.genKey(k), [k, v]); } - }); + } return m; } @@ -99,9 +99,9 @@ export abstract class ADictionary extends Quantity implement } public forEach(foreach: ForEach): void { - this.dictionary.forEach(([k, v]: [K, V]) => { + for (const [, [k, v]] of this.dictionary) { foreach(v, k); - }); + } } public get(key: K): Nullable { @@ -138,12 +138,12 @@ export abstract class ADictionary extends Quantity implement protected mapInternal(mapping: Mapping): Map { const m: Map = new Map(); - let i: number = 0; + let i = 0; - this.dictionary.forEach(([k, v]: [K, V]) => { + for (const [, [k, v]] of this.dictionary) { m.set(Quantity.genKey(k), [k, mapping(v, i)]); i++; - }); + } return m; } @@ -185,12 +185,10 @@ export abstract class ADictionary extends Quantity implement public values(): IterableIterator { const iterable: Array = []; - this.forEach((v: V) => { + for (const [, [, v]] of this.dictionary) { iterable.push(v); - }); + } return iterable.values(); } } - - diff --git a/src/dictionary/Dictionary.ts b/src/dictionary/Dictionary.ts index a64982f..d31df62 100644 --- a/src/dictionary/Dictionary.ts +++ b/src/dictionary/Dictionary.ts @@ -1,6 +1,6 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate } from '../collection/index.js'; -import { ReadonlyDictionary } from './ReadonlyDictionary.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import type { NarrowingBinaryPredicate } from '../collection/index.js'; +import type { ReadonlyDictionary } from './ReadonlyDictionary.js'; export interface Dictionary extends ReadonlyDictionary { filter(predicate: NarrowingBinaryPredicate): Dictionary; diff --git a/src/dictionary/DictionaryUtil.ts b/src/dictionary/DictionaryUtil.ts index 20eea33..d357051 100644 --- a/src/dictionary/DictionaryUtil.ts +++ b/src/dictionary/DictionaryUtil.ts @@ -1,39 +1,44 @@ -import { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; -import { Dictionary } from './Dictionary.js'; -import { ReadonlyDictionary } from './ReadonlyDictionary.js'; +import type { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; +import type { Dictionary } from './Dictionary.js'; +import type { ReadonlyDictionary } from './ReadonlyDictionary.js'; -// eslint-disable-next-line @typescript-eslint/no-extraneous-class -export class DictionaryUtil { - public static await>(dictionary: ReadonlyDictionary>, callback: UnaryFunction, D>): Promise { +export namespace DictionaryUtil { + export const wait = >( + dictionary: ReadonlyDictionary>, + callback: UnaryFunction, D> + ): Promise => { if (dictionary.isEmpty()) { return Promise.resolve(callback(new Map())); } - let rejected: boolean = false; + let rejected = false; const map: Map = new Map(); return new Promise((resolve: Resolve, reject: Reject) => { - dictionary.forEach((value: PromiseLike, key: K) => { - value.then((v: V) => { - if (rejected) { - return; - } + for (const [key, value] of dictionary) { + value.then( + (v: V) => { + if (rejected) { + return; + } - map.set(key, v); + map.set(key, v); - if (map.size === dictionary.size()) { - resolve(callback(map)); - } - }, (e: unknown) => { - if (rejected) { - return; - } + if (map.size === dictionary.size()) { + resolve(callback(map)); + } + }, + (e: unknown) => { + if (rejected) { + return; + } - rejected = true; + rejected = true; - reject(e); - }); - }); + reject(e); + } + ); + } }); - } + }; } diff --git a/src/dictionary/ImmutableDictionary.ts b/src/dictionary/ImmutableDictionary.ts index 95807f2..70718ea 100644 --- a/src/dictionary/ImmutableDictionary.ts +++ b/src/dictionary/ImmutableDictionary.ts @@ -1,14 +1,14 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; import { ADictionary } from './ADictionary.js'; import { DictionaryUtil } from './DictionaryUtil.js'; -import { ReadonlyDictionary } from './ReadonlyDictionary.js'; +import type { ReadonlyDictionary } from './ReadonlyDictionary.js'; export class ImmutableDictionary extends ADictionary { private static readonly EMPTY: ImmutableDictionary = new ImmutableDictionary(new Map()); public static await(dictionary: ReadonlyDictionary>): Promise> { - return DictionaryUtil.await(dictionary, (values: Map) => { + return DictionaryUtil.wait(dictionary, (values: Map) => { return ImmutableDictionary.ofMap(values); }); } diff --git a/src/dictionary/MutableDictionary.ts b/src/dictionary/MutableDictionary.ts index 1010b68..c264de0 100644 --- a/src/dictionary/MutableDictionary.ts +++ b/src/dictionary/MutableDictionary.ts @@ -1,12 +1,12 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import { type Collection, type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; import { ADictionary } from './ADictionary.js'; import { DictionaryUtil } from './DictionaryUtil.js'; -import { ReadonlyDictionary } from './ReadonlyDictionary.js'; +import type { ReadonlyDictionary } from './ReadonlyDictionary.js'; export class MutableDictionary extends ADictionary { public static await(dictionary: ReadonlyDictionary>): Promise> { - return DictionaryUtil.await(dictionary, (values: Map) => { + return DictionaryUtil.wait(dictionary, (values: Map) => { return MutableDictionary.ofMap(values); }); } diff --git a/src/dictionary/ReadonlyDictionary.ts b/src/dictionary/ReadonlyDictionary.ts index 28dba89..45d2476 100644 --- a/src/dictionary/ReadonlyDictionary.ts +++ b/src/dictionary/ReadonlyDictionary.ts @@ -1,5 +1,5 @@ -import { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; +import type { BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; export interface ReadonlyDictionary extends Collection, Cloneable> { filter(predicate: NarrowingBinaryPredicate): ReadonlyDictionary; diff --git a/src/dictionary/__tests__/ADictionary.spec.ts b/src/dictionary/__tests__/ADictionary.spec.ts index 42558ad..3b2039f 100644 --- a/src/dictionary/__tests__/ADictionary.spec.ts +++ b/src/dictionary/__tests__/ADictionary.spec.ts @@ -1,5 +1,5 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { BinaryPredicate, Nullable } from '@jamashita/anden/type'; +import type { BinaryPredicate, Nullable } from '@jamashita/anden/type'; import { MockDictionary } from '../mock/MockDictionary.js'; describe('AProject', () => { @@ -10,9 +10,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(3); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.contains(value2)).toBe(false); }); @@ -23,9 +21,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(2); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.contains(value1)).toBe(true); expect(dictionary.contains(value2)).toBe(true); @@ -38,9 +34,7 @@ describe('AProject', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key, value]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key, value]])); expect(dictionary.equals(dictionary)).toBe(true); }); @@ -52,9 +46,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(4); - const dictionary1: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary1: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); const dictionary2: MockDictionary, MockValueObject> = new MockDictionary( new Map([ [key1, value1], @@ -66,9 +58,10 @@ describe('AProject', () => { }); it('returns false when the different class instance given', () => { - const dictionary: MockDictionary, MockValueObject> = new MockDictionary, MockValueObject>( - new Map() - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary< + MockValueObject, + MockValueObject + >(new Map()); expect(dictionary.equals(new MockValueObject('mock'))).toBe(false); }); @@ -183,9 +176,7 @@ describe('AProject', () => { [key3, value3] ]; - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map(kv) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map(kv)); const every1: boolean = dictionary.every((_: MockValueObject, key: MockValueObject) => { return key.get() % 3 === 0; @@ -259,9 +250,7 @@ describe('AProject', () => { ]) ); - const predicate: BinaryPredicate, MockValueObject> = ( - value: MockValueObject - ) => { + const predicate: BinaryPredicate, MockValueObject> = (value: MockValueObject) => { return value.get() % 2 === 0; }; @@ -293,12 +282,14 @@ describe('AProject', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([ - [key1, value1], - [key2, value2], - [key3, value3], - [key4, value4] - ])); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary( + new Map([ + [key1, value1], + [key2, value2], + [key3, value3], + [key4, value4] + ]) + ); const found1: Nullable> = dictionary.find((v: MockValueObject) => { return v.get() === 1; @@ -337,14 +328,12 @@ describe('AProject', () => { [key2, value2] ]; - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map(kv) - ); - let i: number = 0; + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map(kv)); + let i = 0; expect(dictionary.size()).toBe(kv.length); dictionary.forEach((value: MockValueObject, key: MockValueObject) => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // biome-ignore lint/style/noNonNullAssertion: const [k, v]: [MockValueObject, MockValueObject] = kv[i]!; expect(key).toBe(k); @@ -361,9 +350,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.size()).toBe(1); expect(dictionary.get(key1)).toBe(value1); @@ -376,9 +363,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.size()).toBe(1); expect(dictionary.get(key2)).toBeNull(); @@ -392,9 +377,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(2); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.has(key2)).toBe(false); }); @@ -405,9 +388,7 @@ describe('AProject', () => { const value1: MockValueObject = new MockValueObject(3); - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); expect(dictionary.has(key1)).toBe(true); expect(dictionary.has(key2)).toBe(true); @@ -419,12 +400,11 @@ describe('AProject', () => { const key1: MockValueObject = new MockValueObject(1); const value1: MockValueObject = new MockValueObject(2); - const dictionary1: MockDictionary, MockValueObject> = new MockDictionary( - new Map([[key1, value1]]) - ); - const dictionary2: MockDictionary, MockValueObject> = new MockDictionary, MockValueObject>( - new Map() - ); + const dictionary1: MockDictionary, MockValueObject> = new MockDictionary(new Map([[key1, value1]])); + const dictionary2: MockDictionary, MockValueObject> = new MockDictionary< + MockValueObject, + MockValueObject + >(new Map()); expect(dictionary1.isEmpty()).toBe(false); expect(dictionary2.isEmpty()).toBe(true); @@ -448,7 +428,7 @@ describe('AProject', () => { ]) ); - let i: number = 0; + let i = 0; for (const [k, v] of dictionary) { expect(k).toBe(keys[i]); @@ -474,7 +454,7 @@ describe('AProject', () => { ]) ); - let i: number = 0; + let i = 0; for (const key of dictionary.keys()) { expect(key).toBe(keys[i]); @@ -499,9 +479,7 @@ describe('AProject', () => { [key3, value3] ]; - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map(kv) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map(kv)); const predicate: BinaryPredicate, MockValueObject> = (value: MockValueObject) => { return value.get() % 2 === 0; @@ -554,15 +532,13 @@ describe('AProject', () => { [key2, value2] ]; - const dictionary: MockDictionary, MockValueObject> = new MockDictionary( - new Map(kv) - ); + const dictionary: MockDictionary, MockValueObject> = new MockDictionary(new Map(kv)); const map: Map, MockValueObject> = dictionary.toMap(); - let i: number = 0; + let i = 0; expect(dictionary.size()).toBe(map.size); dictionary.forEach((value: MockValueObject, key: MockValueObject) => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // biome-ignore lint/style/noNonNullAssertion: const [k, v]: [MockValueObject, MockValueObject] = kv[i]!; expect(key).toBe(k); @@ -607,7 +583,7 @@ describe('AProject', () => { ]) ); - let i: number = 0; + let i = 0; for (const key of dictionary.values()) { expect(key).toBe(values[i]); diff --git a/src/dictionary/__tests__/DictionaryUtil.spec.ts b/src/dictionary/__tests__/DictionaryUtil.spec.ts index 89eaa8c..2709dc2 100644 --- a/src/dictionary/__tests__/DictionaryUtil.spec.ts +++ b/src/dictionary/__tests__/DictionaryUtil.spec.ts @@ -1,14 +1,14 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Dictionary } from '../Dictionary.js'; +import type { Dictionary } from '../Dictionary.js'; import { DictionaryUtil } from '../DictionaryUtil.js'; import { ImmutableDictionary } from '../ImmutableDictionary.js'; describe('DictionaryUtil', () => { - describe('await', () => { + describe('wait', () => { it('returns empty map when given dictionary is empty', async () => { const dic: Dictionary, Promise>> = ImmutableDictionary.empty(); - await DictionaryUtil.await(dic, (values: Map, MockValueObject>) => { + await DictionaryUtil.wait(dic, (values: Map, MockValueObject>) => { expect(values.size).toBe(0); return ImmutableDictionary.ofMap(values); @@ -33,7 +33,7 @@ describe('DictionaryUtil', () => { ]) ); - await DictionaryUtil.await(dic, (values: Map, MockValueObject>) => { + await DictionaryUtil.wait(dic, (values: Map, MockValueObject>) => { expect(values.size).toBe(dic.size()); expect(values.get(key1)).toBe(mock1); expect(values.get(key2)).toBe(mock2); @@ -55,9 +55,11 @@ describe('DictionaryUtil', () => { ]) ); - await expect(DictionaryUtil.await(dic, (values: Map, MockValueObject>) => { - return ImmutableDictionary.ofMap(values); - })).rejects.toThrow(err); + await expect( + DictionaryUtil.wait(dic, (values: Map, MockValueObject>) => { + return ImmutableDictionary.ofMap(values); + }) + ).rejects.toThrow(err); }); }); }); diff --git a/src/dictionary/__tests__/ImmutableDictionary.spec.ts b/src/dictionary/__tests__/ImmutableDictionary.spec.ts index d6d7c23..41c8cf9 100644 --- a/src/dictionary/__tests__/ImmutableDictionary.spec.ts +++ b/src/dictionary/__tests__/ImmutableDictionary.spec.ts @@ -44,9 +44,10 @@ describe('ImmutableDictionary', () => { describe('ofMap', () => { it('returns ImmutableDictionary.empty() when the size is 0', () => { - const dictionary: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap, MockValueObject>( - new Map() - ); + const dictionary: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap< + MockValueObject, + MockValueObject + >(new Map()); expect(dictionary.isEmpty()).toBe(true); expect(dictionary).toBe(ImmutableDictionary.empty()); @@ -74,9 +75,7 @@ describe('ImmutableDictionary', () => { describe('duplicate', () => { it('returns ImmutableDictionary.empty() when there are no key-value pairs', () => { - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([])); expect(dictionary1.duplicate()).toBe(ImmutableDictionary.empty()); }); @@ -132,9 +131,11 @@ describe('ImmutableDictionary', () => { const filtered1: ImmutableDictionary, MockValueObject> = dictionary1.filter((v: MockValueObject) => { return v.get().length % 2 === 0; }); - const filtered2: ImmutableDictionary, MockValueObject> = dictionary1.filter((_v: MockValueObject, k: MockValueObject) => { - return k.get() % 2 === 1; - }); + const filtered2: ImmutableDictionary, MockValueObject> = dictionary1.filter( + (_v: MockValueObject, k: MockValueObject) => { + return k.get() % 2 === 1; + } + ); const filtered3: ImmutableDictionary, MockValueObject> = dictionary1.filter((v: MockValueObject) => { return v === value5; }); @@ -184,11 +185,7 @@ describe('ImmutableDictionary', () => { const value1: MockValueObject = new MockValueObject('a'); const value2: MockValueObject = new MockValueObject('aa'); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([ - [key1, value1] - ]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key1, value1]])); const hashCode1: string = dictionary1.hashCode(); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.set(key2, value2); const hashCode2: string = dictionary2.hashCode(); @@ -203,12 +200,8 @@ describe('ImmutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key, value]]) - ); - const dictionary2: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key, value]])); + const dictionary2: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([])); expect(dictionary1.isEmpty()).toBe(false); expect(dictionary2.isEmpty()).toBe(true); @@ -247,9 +240,7 @@ describe('ImmutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key, value]]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key, value]])); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.remove(key); expect(dictionary1.size()).toBe(1); @@ -262,9 +253,7 @@ describe('ImmutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key1, value]]) - ); + const dictionary: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key1, value]])); const beforeLength: number = dictionary.size(); expect(dictionary.remove(key2)).toBe(dictionary); @@ -283,9 +272,7 @@ describe('ImmutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key1, value]]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key1, value]])); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.remove(key2); expect(dictionary1).not.toBe(dictionary2); @@ -298,9 +285,7 @@ describe('ImmutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key, value]]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key, value]])); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.remove(key); expect(dictionary2).toBe(ImmutableDictionary.empty()); @@ -341,9 +326,7 @@ describe('ImmutableDictionary', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(3); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key1, value1]]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key1, value1]])); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.set(key1, value2); expect(dictionary1).not.toBe(dictionary2); @@ -359,9 +342,7 @@ describe('ImmutableDictionary', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(3); - const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap( - new Map([[key1, value1]]) - ); + const dictionary1: ImmutableDictionary, MockValueObject> = ImmutableDictionary.ofMap(new Map([[key1, value1]])); const dictionary2: ImmutableDictionary, MockValueObject> = dictionary1.set(key2, value2); expect(dictionary1).not.toBe(dictionary2); diff --git a/src/dictionary/__tests__/MutableDictionary.spec.ts b/src/dictionary/__tests__/MutableDictionary.spec.ts index 1a5ba2a..c363035 100644 --- a/src/dictionary/__tests__/MutableDictionary.spec.ts +++ b/src/dictionary/__tests__/MutableDictionary.spec.ts @@ -42,9 +42,7 @@ describe('MutableDictionary', () => { describe('ofMap', () => { it('returns MutableAddress.empty() when set size is 0', () => { - const dictionary: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([]) - ); + const dictionary: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([])); expect(dictionary.isEmpty()).toBe(true); }); @@ -121,9 +119,11 @@ describe('MutableDictionary', () => { const filtered1: MutableDictionary, MockValueObject> = dictionary1.filter((v: MockValueObject) => { return v.get().length % 2 === 0; }); - const filtered2: MutableDictionary, MockValueObject> = dictionary1.filter((_v: MockValueObject, k: MockValueObject) => { - return k.get() % 2 === 1; - }); + const filtered2: MutableDictionary, MockValueObject> = dictionary1.filter( + (_v: MockValueObject, k: MockValueObject) => { + return k.get() % 2 === 1; + } + ); const filtered3: MutableDictionary, MockValueObject> = dictionary1.filter((v: MockValueObject) => { return v === value5; }); @@ -146,11 +146,7 @@ describe('MutableDictionary', () => { const value1: MockValueObject = new MockValueObject('a'); const value2: MockValueObject = new MockValueObject('aa'); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([ - [key1, value1] - ]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value1]])); const hashCode1: string = dictionary1.hashCode(); const dictionary2: MutableDictionary, MockValueObject> = dictionary1.set(key2, value2); const hashCode2: string = dictionary2.hashCode(); @@ -165,12 +161,8 @@ describe('MutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key1, value]]) - ); - const dictionary2: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value]])); + const dictionary2: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([])); expect(dictionary1.isEmpty()).toBe(false); expect(dictionary2.isEmpty()).toBe(true); @@ -209,9 +201,7 @@ describe('MutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key, value]]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key, value]])); const dictionary2: MutableDictionary, MockValueObject> = dictionary1.remove(key); expect(dictionary1).toBe(dictionary2); @@ -224,9 +214,7 @@ describe('MutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key1, value]]) - ); + const dictionary: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value]])); const beforeLength: number = dictionary.size(); expect(dictionary.remove(key2)).toBe(dictionary); @@ -245,9 +233,7 @@ describe('MutableDictionary', () => { const value: MockValueObject = new MockValueObject(2); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key1, value]]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value]])); const dictionary2: MutableDictionary, MockValueObject> = dictionary1.remove(key3); expect(dictionary1).toBe(dictionary2); @@ -286,9 +272,7 @@ describe('MutableDictionary', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(3); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key1, value1]]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value1]])); const dictionary2: MutableDictionary, MockValueObject> = dictionary1.set(key1, value2); expect(dictionary1).toBe(dictionary2); @@ -303,9 +287,7 @@ describe('MutableDictionary', () => { const value1: MockValueObject = new MockValueObject(2); const value2: MockValueObject = new MockValueObject(3); - const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap( - new Map([[key1, value1]]) - ); + const dictionary1: MutableDictionary, MockValueObject> = MutableDictionary.ofMap(new Map([[key1, value1]])); const dictionary2: MutableDictionary, MockValueObject> = dictionary1.set(key2, value2); expect(dictionary1).toBe(dictionary2); diff --git a/src/sequence/ASequence.ts b/src/sequence/ASequence.ts index 653c706..3f3835d 100644 --- a/src/sequence/ASequence.ts +++ b/src/sequence/ASequence.ts @@ -1,7 +1,16 @@ import { Objet } from '@jamashita/anden/object'; -import { BinaryFunction, BinaryPredicate, ForEach, isEquatable, Kind, Mapping, Nullable, Undefinable } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; -import { Sequence } from './Sequence.js'; +import { + type BinaryFunction, + type BinaryPredicate, + type ForEach, + isEquatable, + Kind, + type Mapping, + type Nullable, + type Undefinable +} from '@jamashita/anden/type'; +import { type NarrowingBinaryPredicate, Quantity } from '../collection/index.js'; +import type { Sequence } from './Sequence.js'; export abstract class ASequence extends Quantity implements Sequence { protected sequence: Array; @@ -109,9 +118,11 @@ export abstract class ASequence extends Quantity implements Se } public iterator(): IterableIterator<[number, V]> { - return this.sequence.map((e: V, i: number): [number, V] => { - return [i, e]; - }).values(); + return this.sequence + .map((e: V, i: number): [number, V] => { + return [i, e]; + }) + .values(); } public reduce(reducer: BinaryFunction, initialValue?: V): V { @@ -134,9 +145,11 @@ export abstract class ASequence extends Quantity implements Se } public serialize(): string { - return this.sequence.map((v: V) => { - return Objet.identify(v); - }).join(', '); + return this.sequence + .map((v: V) => { + return Objet.identify(v); + }) + .join(', '); } protected setInternal(key: number, value: V): Array { diff --git a/src/sequence/ImmutableSequence.ts b/src/sequence/ImmutableSequence.ts index d977658..5297a95 100644 --- a/src/sequence/ImmutableSequence.ts +++ b/src/sequence/ImmutableSequence.ts @@ -1,14 +1,14 @@ -import { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; +import type { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; import { ASequence } from './ASequence.js'; -import { ReadonlySequence } from './ReadonlySequence.js'; +import type { ReadonlySequence } from './ReadonlySequence.js'; import { SequenceUtil } from './SequenceUtil.js'; export class ImmutableSequence extends ASequence { private static readonly EMPTY: ImmutableSequence = new ImmutableSequence([]); public static await(sequence: ReadonlySequence>): Promise> { - return SequenceUtil.await(sequence, (values: Array) => { + return SequenceUtil.wait(sequence, (values: Array) => { return ImmutableSequence.ofArray(values); }); } diff --git a/src/sequence/MutableSequence.ts b/src/sequence/MutableSequence.ts index fea5744..5bb8063 100644 --- a/src/sequence/MutableSequence.ts +++ b/src/sequence/MutableSequence.ts @@ -1,12 +1,12 @@ -import { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; +import type { BinaryFunction, BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; import { ASequence } from './ASequence.js'; -import { ReadonlySequence } from './ReadonlySequence.js'; +import type { ReadonlySequence } from './ReadonlySequence.js'; import { SequenceUtil } from './SequenceUtil.js'; export class MutableSequence extends ASequence { public static await(sequence: ReadonlySequence>): Promise> { - return SequenceUtil.await(sequence, (values: Array) => { + return SequenceUtil.wait(sequence, (values: Array) => { return MutableSequence.ofArray(values); }); } diff --git a/src/sequence/ReadonlySequence.ts b/src/sequence/ReadonlySequence.ts index 193f1c2..95295cc 100644 --- a/src/sequence/ReadonlySequence.ts +++ b/src/sequence/ReadonlySequence.ts @@ -1,5 +1,5 @@ -import { BinaryFunction, BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; -import { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; +import type { BinaryFunction, BinaryPredicate, Cloneable, Mapping } from '@jamashita/anden/type'; +import type { Collection, NarrowingBinaryPredicate } from '../collection/index.js'; export interface ReadonlySequence extends Collection, Cloneable> { filter(predicate: NarrowingBinaryPredicate): ReadonlySequence; diff --git a/src/sequence/Sequence.ts b/src/sequence/Sequence.ts index d681759..31b5f99 100644 --- a/src/sequence/Sequence.ts +++ b/src/sequence/Sequence.ts @@ -1,6 +1,6 @@ -import { BinaryPredicate, Mapping } from '@jamashita/anden/type'; -import { NarrowingBinaryPredicate } from '../collection/index.js'; -import { ReadonlySequence } from './ReadonlySequence.js'; +import type { BinaryPredicate, Mapping } from '@jamashita/anden/type'; +import type { NarrowingBinaryPredicate } from '../collection/index.js'; +import type { ReadonlySequence } from './ReadonlySequence.js'; export interface Sequence extends ReadonlySequence { add(value: V): Sequence; diff --git a/src/sequence/SequenceUtil.ts b/src/sequence/SequenceUtil.ts index 01d2cb0..7275fd0 100644 --- a/src/sequence/SequenceUtil.ts +++ b/src/sequence/SequenceUtil.ts @@ -1,46 +1,48 @@ -import { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; -import { ReadonlySequence } from './ReadonlySequence.js'; -import { Sequence } from './Sequence.js'; +import type { Reject, Resolve, UnaryFunction } from '@jamashita/anden/type'; +import type { ReadonlySequence } from './ReadonlySequence.js'; +import type { Sequence } from './Sequence.js'; -// eslint-disable-next-line @typescript-eslint/no-extraneous-class -export class SequenceUtil { - public static await>(sequence: ReadonlySequence>, callback: UnaryFunction, S>): Promise { +export namespace SequenceUtil { + export const wait = >(sequence: ReadonlySequence>, callback: UnaryFunction, S>): Promise => { if (sequence.isEmpty()) { return Promise.resolve(callback([])); } - let rejected: boolean = false; + let rejected = false; const map: Map = new Map(); return new Promise((resolve: Resolve, reject: Reject) => { sequence.forEach((value: PromiseLike, key: number) => { - value.then((v: V) => { - if (rejected) { - return; - } + value.then( + (v: V) => { + if (rejected) { + return; + } - map.set(key, v); + map.set(key, v); - if (map.size === sequence.size()) { - const values: Array = []; + if (map.size === sequence.size()) { + const values: Array = []; - for (let i: number = 0; i < map.size; i++) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - values.push(map.get(i)!); - } + for (let i = 0; i < map.size; i++) { + // biome-ignore lint/style/noNonNullAssertion: + values.push(map.get(i)!); + } - resolve(callback(values)); - } - }, (e: unknown) => { - if (rejected) { - return; - } + resolve(callback(values)); + } + }, + (e: unknown) => { + if (rejected) { + return; + } - rejected = true; + rejected = true; - reject(e); - }); + reject(e); + } + ); }); }); - } + }; } diff --git a/src/sequence/__tests__/ASequence.spec.ts b/src/sequence/__tests__/ASequence.spec.ts index 34c215d..aedd58d 100644 --- a/src/sequence/__tests__/ASequence.spec.ts +++ b/src/sequence/__tests__/ASequence.spec.ts @@ -1,5 +1,5 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Nullable, Predicate } from '@jamashita/anden/type'; +import type { Nullable, Predicate } from '@jamashita/anden/type'; import { MockSequence } from '../mock/MockSequence.js'; describe('ASequence', () => { @@ -96,42 +96,12 @@ describe('ASequence', () => { const value4: MockValueObject = new MockValueObject(8); const value5: MockValueObject = new MockValueObject(3); - const sequence1: MockSequence> = new MockSequence([ - value1, - value2, - value3, - value4 - ]); - const sequence2: MockSequence> = new MockSequence([ - value2, - value1, - value3, - value4 - ]); - const sequence3: MockSequence> = new MockSequence([ - value2, - value3, - value1, - value4 - ]); - const sequence4: MockSequence> = new MockSequence([ - value2, - value3, - value4, - value1 - ]); - const sequence5: MockSequence> = new MockSequence([ - value1, - value5, - value3, - value4 - ]); - const sequence6: MockSequence> = new MockSequence([ - value1, - value2, - value5, - value4 - ]); + const sequence1: MockSequence> = new MockSequence([value1, value2, value3, value4]); + const sequence2: MockSequence> = new MockSequence([value2, value1, value3, value4]); + const sequence3: MockSequence> = new MockSequence([value2, value3, value1, value4]); + const sequence4: MockSequence> = new MockSequence([value2, value3, value4, value1]); + const sequence5: MockSequence> = new MockSequence([value1, value5, value3, value4]); + const sequence6: MockSequence> = new MockSequence([value1, value2, value5, value4]); const predicate: Predicate> = (v: MockValueObject) => { return v.get() % 2 === 0; @@ -160,12 +130,7 @@ describe('ASequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence: MockSequence> = new MockSequence([ - value1, - value2, - value3, - value4 - ]); + const sequence: MockSequence> = new MockSequence([value1, value2, value3, value4]); const found1: Nullable> = sequence.find((v: MockValueObject) => { return v.get() === 1; @@ -204,16 +169,12 @@ describe('ASequence', () => { describe('get', () => { it('returns value at the correct key', () => { - const values: Array> = [ - new MockValueObject(1), - new MockValueObject(2), - new MockValueObject(3) - ]; + const values: Array> = [new MockValueObject(1), new MockValueObject(2), new MockValueObject(3)]; const sequence: MockSequence> = new MockSequence(values); expect(sequence.size()).toBe(values.length); - for (let i: number = 0; i < sequence.size(); i++) { + for (let i = 0; i < sequence.size(); i++) { expect(sequence.get(i)).toBe(values[i]); } }); @@ -232,10 +193,7 @@ describe('ASequence', () => { describe('isEmpty', () => { it('returns true if the values does not exist', () => { - const sequence1: MockSequence> = new MockSequence([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence1: MockSequence> = new MockSequence([new MockValueObject(1), new MockValueObject(2)]); const sequence2: MockSequence> = new MockSequence([]); expect(sequence1.isEmpty()).toBe(false); @@ -245,12 +203,9 @@ describe('ASequence', () => { describe('iterator', () => { it('returns [number, MockValueObject]', () => { - const sequence: MockSequence> = new MockSequence([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence: MockSequence> = new MockSequence([new MockValueObject(1), new MockValueObject(2)]); - let i: number = 0; + let i = 0; for (const value of sequence) { expect(value[0]).toBe(i); @@ -275,26 +230,32 @@ describe('ASequence', () => { const o: MockValueObject = new MockValueObject(1); const sequence: MockSequence> = new MockSequence([]); - expect(sequence.reduce((_o1: MockValueObject, o2: MockValueObject) => { - return o2; - }, o)).toBe(o); + expect( + sequence.reduce((_o1: MockValueObject, o2: MockValueObject) => { + return o2; + }, o) + ).toBe(o); }); it('returns first element when the array size is only 1', () => { const o: MockValueObject = new MockValueObject(1); const sequence: MockSequence> = new MockSequence([o]); - expect(sequence.reduce((o1: MockValueObject) => { - return o1; - })).toBe(o); + expect( + sequence.reduce((o1: MockValueObject) => { + return o1; + }) + ).toBe(o); }); it('returns reduced value', () => { const sequence: MockSequence = new MockSequence([1, 2, 3, 4]); - expect(sequence.reduce((o1: number, o2: number) => { - return o1 + o2; - })).toBe(10); + expect( + sequence.reduce((o1: number, o2: number) => { + return o1 + o2; + }) + ).toBe(10); }); }); @@ -330,12 +291,7 @@ describe('ASequence', () => { const value3: MockValueObject = new MockValueObject(6); const value4: MockValueObject = new MockValueObject(8); - const sequence: MockSequence> = new MockSequence([ - value1, - value2, - value3, - value4 - ]); + const sequence: MockSequence> = new MockSequence([value1, value2, value3, value4]); const predicate: Predicate> = (v: MockValueObject) => { return v.get() % 2 === 1; @@ -349,17 +305,13 @@ describe('ASequence', () => { describe('toArray', () => { it('returns its retaining shallow-copied array', () => { - const values: Array> = [ - new MockValueObject(1), - new MockValueObject(2), - new MockValueObject(3) - ]; + const values: Array> = [new MockValueObject(1), new MockValueObject(2), new MockValueObject(3)]; const sequence: MockSequence> = new MockSequence(values); const array: Array> = sequence.toArray(); expect(sequence.size()).toBe(values.length); - for (let i: number = 0; i < values.length; i++) { + for (let i = 0; i < values.length; i++) { expect(sequence.get(i)).toBe(array[i]); } @@ -383,13 +335,10 @@ describe('ASequence', () => { describe('values', () => { it('returns its retaining values', () => { - const values: Array> = [ - new MockValueObject(1), - new MockValueObject(2) - ]; + const values: Array> = [new MockValueObject(1), new MockValueObject(2)]; const sequence: MockSequence> = new MockSequence(values); - let i: number = 0; + let i = 0; for (const value of sequence.values()) { expect(value).toBe(values[i]); diff --git a/src/sequence/__tests__/ImmutableSequence.spec.ts b/src/sequence/__tests__/ImmutableSequence.spec.ts index 78b5589..c779f96 100644 --- a/src/sequence/__tests__/ImmutableSequence.spec.ts +++ b/src/sequence/__tests__/ImmutableSequence.spec.ts @@ -1,5 +1,5 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Nullable } from '@jamashita/anden/type'; +import type { Nullable } from '@jamashita/anden/type'; import { ImmutableSequence } from '../ImmutableSequence.js'; describe('ImmutableSequence', () => { @@ -21,10 +21,7 @@ describe('ImmutableSequence', () => { describe('of', () => { it('returns copied collection, does not use the same one', () => { - const sequence: ImmutableSequence> = ImmutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence: ImmutableSequence> = ImmutableSequence.ofArray([new MockValueObject(1), new MockValueObject(2)]); const copied: ImmutableSequence> = ImmutableSequence.of(sequence); expect(sequence.size()).toBe(copied.size()); @@ -47,10 +44,7 @@ describe('ImmutableSequence', () => { }); it('returns instance', () => { - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(3) - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([new MockValueObject(1), new MockValueObject(3)]); const sequence2: ImmutableSequence> = ImmutableSequence.ofArray([ new MockValueObject(2), new MockValueObject(4), @@ -120,12 +114,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(2); - const sequence: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3, - value4 - ]); + const sequence: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3, value4]); const filtered: ImmutableSequence> = sequence.filter((v: MockValueObject) => { return v.get() > 100; @@ -142,12 +131,7 @@ describe('ImmutableSequence', () => { const value4: MockValueObject = new MockValueObject(2); const value5: MockValueObject = new MockValueObject(5); - const sequence: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3, - value4 - ]); + const sequence: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3, value4]); const filtered1: ImmutableSequence> = sequence.filter((v: MockValueObject) => { return v.get() % 2 === 0; @@ -184,10 +168,7 @@ describe('ImmutableSequence', () => { describe('isEmpty', () => { it('returns true if the value size is 0', () => { - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([new MockValueObject(1), new MockValueObject(2)]); const sequence2: ImmutableSequence> = ImmutableSequence.ofArray([]); expect(sequence1.isEmpty()).toBe(false); @@ -228,11 +209,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(0); @@ -248,11 +225,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(1); expect(sequence1).not.toBe(sequence2); @@ -267,11 +240,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(2); expect(sequence1).not.toBe(sequence2); @@ -286,11 +255,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(3); expect(sequence1).toBe(sequence2); @@ -301,11 +266,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(-1); expect(sequence1).toBe(sequence2); @@ -316,11 +277,7 @@ describe('ImmutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.remove(0.8); expect(sequence1).toBe(sequence2); @@ -334,11 +291,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(0, value4); expect(sequence1).not.toBe(sequence2); @@ -355,11 +308,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(1, value4); expect(sequence1).not.toBe(sequence2); @@ -376,11 +325,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(2, value4); expect(sequence1).not.toBe(sequence2); @@ -397,11 +342,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(-1, value4); expect(sequence1).toBe(sequence2); @@ -413,11 +354,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(sequence1.size(), value4); @@ -430,11 +367,7 @@ describe('ImmutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: ImmutableSequence> = ImmutableSequence.ofArray([value1, value2, value3]); const sequence2: ImmutableSequence> = sequence1.set(2.2, value4); @@ -454,9 +387,7 @@ describe('ImmutableSequence', () => { }); it('when the size is 1, just copy a sequence shallowly', () => { - const arr: Array> = [ - new MockValueObject(2) - ]; + const arr: Array> = [new MockValueObject(2)]; const sequence: ImmutableSequence> = ImmutableSequence.ofArray(arr); const sorted: ImmutableSequence> = sequence.sort(() => { return 1; @@ -468,12 +399,7 @@ describe('ImmutableSequence', () => { }); it('returns like an array', () => { - const arr: Array> = [ - new MockValueObject(4), - new MockValueObject(2), - new MockValueObject(3), - new MockValueObject(1) - ]; + const arr: Array> = [new MockValueObject(4), new MockValueObject(2), new MockValueObject(3), new MockValueObject(1)]; const sequence: ImmutableSequence> = ImmutableSequence.ofArray(arr); const sorted: ImmutableSequence> = sequence.sort((m1: MockValueObject, m2: MockValueObject) => { return m1.get() - m2.get(); diff --git a/src/sequence/__tests__/MutableSequence.spec.ts b/src/sequence/__tests__/MutableSequence.spec.ts index f421178..bf04b0c 100644 --- a/src/sequence/__tests__/MutableSequence.spec.ts +++ b/src/sequence/__tests__/MutableSequence.spec.ts @@ -1,5 +1,5 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Nullable } from '@jamashita/anden/type'; +import type { Nullable } from '@jamashita/anden/type'; import { MutableSequence } from '../MutableSequence.js'; describe('MutableSequence', () => { @@ -21,13 +21,11 @@ describe('MutableSequence', () => { describe('of', () => { it('returns copied collection, does not use the same one', () => { - const sequence: MutableSequence> = MutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence: MutableSequence> = MutableSequence.ofArray([new MockValueObject(1), new MockValueObject(2)]); const copied: MutableSequence> = MutableSequence.of(sequence); expect(sequence.size()).toBe(copied.size()); + // biome-ignore lint/complexity/noForEach: sequence.forEach((v: MockValueObject) => { expect(copied.contains(v)).toBe(true); }); @@ -46,10 +44,7 @@ describe('MutableSequence', () => { }); it('returns instance', () => { - const sequence1: MutableSequence> = MutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(3) - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([new MockValueObject(1), new MockValueObject(3)]); const sequence2: MutableSequence> = MutableSequence.ofArray([ new MockValueObject(2), new MockValueObject(4), @@ -120,12 +115,7 @@ describe('MutableSequence', () => { const value4: MockValueObject = new MockValueObject(2); const value5: MockValueObject = new MockValueObject(5); - const sequence: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3, - value4 - ]); + const sequence: MutableSequence> = MutableSequence.ofArray([value1, value2, value3, value4]); const filtered1: MutableSequence> = sequence.filter((v: MockValueObject) => { return v.get() % 2 === 0; @@ -162,10 +152,7 @@ describe('MutableSequence', () => { describe('isEmpty', () => { it('returns true if the value size is 0', () => { - const sequence1: MutableSequence> = MutableSequence.ofArray([ - new MockValueObject(1), - new MockValueObject(2) - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([new MockValueObject(1), new MockValueObject(2)]); const sequence2: MutableSequence> = MutableSequence.ofArray([]); expect(sequence1.isEmpty()).toBe(false); @@ -206,11 +193,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(0); expect(sequence1).toBe(sequence2); @@ -222,11 +205,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(1); expect(sequence1).toBe(sequence2); @@ -240,11 +219,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(2); expect(sequence1).toBe(sequence2); @@ -258,11 +233,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(3); expect(sequence1).toBe(sequence2); @@ -273,11 +244,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(-1); expect(sequence1).toBe(sequence2); @@ -288,11 +255,7 @@ describe('MutableSequence', () => { const value2: MockValueObject = new MockValueObject(2); const value3: MockValueObject = new MockValueObject(3); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.remove(0.9); expect(sequence1).toBe(sequence2); @@ -306,11 +269,7 @@ describe('MutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.set(0, value4); expect(sequence1).toBe(sequence2); @@ -326,11 +285,7 @@ describe('MutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.set(1, value4); expect(sequence1).toBe(sequence2); @@ -346,11 +301,7 @@ describe('MutableSequence', () => { const value3: MockValueObject = new MockValueObject(3); const value4: MockValueObject = new MockValueObject(4); - const sequence1: MutableSequence> = MutableSequence.ofArray([ - value1, - value2, - value3 - ]); + const sequence1: MutableSequence> = MutableSequence.ofArray([value1, value2, value3]); const sequence2: MutableSequence> = sequence1.set(2, value4); expect(sequence1).toBe(sequence2); @@ -409,9 +360,7 @@ describe('MutableSequence', () => { }); it('when the size is 1, just copy a sequence shallowly', () => { - const arr: Array> = [ - new MockValueObject(2) - ]; + const arr: Array> = [new MockValueObject(2)]; const sequence: MutableSequence> = MutableSequence.ofArray(arr); const sorted: MutableSequence> = sequence.sort(() => { return 1; @@ -423,12 +372,7 @@ describe('MutableSequence', () => { }); it('returns like an array', () => { - const arr: Array> = [ - new MockValueObject(4), - new MockValueObject(2), - new MockValueObject(3), - new MockValueObject(1) - ]; + const arr: Array> = [new MockValueObject(4), new MockValueObject(2), new MockValueObject(3), new MockValueObject(1)]; const sequence: MutableSequence> = MutableSequence.ofArray(arr); const sorted: MutableSequence> = sequence.sort((m1: MockValueObject, m2: MockValueObject) => { return m1.get() - m2.get(); diff --git a/src/sequence/__tests__/SequenceUtil.spec.ts b/src/sequence/__tests__/SequenceUtil.spec.ts index 15dc88e..05107bd 100644 --- a/src/sequence/__tests__/SequenceUtil.spec.ts +++ b/src/sequence/__tests__/SequenceUtil.spec.ts @@ -1,14 +1,14 @@ import { MockValueObject } from '@jamashita/anden/object'; import { ImmutableSequence } from '../ImmutableSequence.js'; -import { Sequence } from '../Sequence.js'; +import type { Sequence } from '../Sequence.js'; import { SequenceUtil } from '../SequenceUtil.js'; describe('SequenceUtil', () => { - describe('await', () => { + describe('wait', () => { it('returns empty array when given sequence is empty', async () => { const seq: Sequence>> = ImmutableSequence.empty(); - await SequenceUtil.await(seq, (values: Array>) => { + await SequenceUtil.wait(seq, (values: Array>) => { expect(values).toHaveLength(0); return ImmutableSequence.ofArray(values); @@ -27,7 +27,7 @@ describe('SequenceUtil', () => { Promise.resolve(mock4) ]); - await SequenceUtil.await(seq, (values: Array>) => { + await SequenceUtil.wait(seq, (values: Array>) => { expect(values).toHaveLength(seq.size()); expect(values[0]).toBe(mock1); expect(values[1]).toBe(mock2); @@ -47,9 +47,11 @@ describe('SequenceUtil', () => { Promise.resolve(new MockValueObject(4)) ]); - await expect(SequenceUtil.await(seq, (values: Array>) => { - return ImmutableSequence.ofArray(values); - })).rejects.toThrow(err); + await expect( + SequenceUtil.wait(seq, (values: Array>) => { + return ImmutableSequence.ofArray(values); + }) + ).rejects.toThrow(err); }); }); }); diff --git a/src/tree/ATree.ts b/src/tree/ATree.ts index cd466b3..ba507b9 100644 --- a/src/tree/ATree.ts +++ b/src/tree/ATree.ts @@ -1,7 +1,7 @@ import { Objet } from '@jamashita/anden/object'; -import { ForEach, Nullable, Predicate } from '@jamashita/anden/type'; -import { Tree } from './Tree.js'; -import { ATreeNode } from './TreeNode/index.js'; +import type { ForEach, Nullable, Predicate } from '@jamashita/anden/type'; +import type { Tree } from './Tree.js'; +import type { ATreeNode } from './TreeNode/index.js'; export abstract class ATree> extends Objet implements Tree { protected readonly root: T; diff --git a/src/tree/ATrees.ts b/src/tree/ATrees.ts index d5a2a40..64800ea 100644 --- a/src/tree/ATrees.ts +++ b/src/tree/ATrees.ts @@ -1,11 +1,14 @@ import { Objet } from '@jamashita/anden/object'; -import { BinaryPredicate, ForEach, Kind, Nullable } from '@jamashita/anden/type'; -import { Collection } from '../collection/index.js'; -import { ATree } from './ATree.js'; -import { ATreeNode } from './TreeNode/index.js'; -import { Trees } from './Trees.js'; - -export abstract class ATrees, E extends ATree, C extends Collection> extends Objet implements Trees { +import { type BinaryPredicate, type ForEach, Kind, type Nullable } from '@jamashita/anden/type'; +import type { Collection } from '../collection/index.js'; +import type { ATree } from './ATree.js'; +import type { ATreeNode } from './TreeNode/index.js'; +import type { Trees } from './Trees.js'; + +export abstract class ATrees, E extends ATree, C extends Collection> + extends Objet + implements Trees +{ protected readonly trees: C; protected constructor(trees: C) { @@ -56,9 +59,9 @@ export abstract class ATrees, E extends public forEach(foreach: ForEach): void { this.trees.forEach((tree: E, key: K) => { - tree.forEach((value: V) => { + for (const value of tree.values()) { foreach(value, key); - }); + } }); } @@ -89,9 +92,9 @@ export abstract class ATrees, E extends public values(): Iterable { const values: Array = []; - this.trees.forEach((v: E) => { + for (const v of this.trees.values()) { values.push(...v.values()); - }); + } return values; } diff --git a/src/tree/ClosureTable/ClosureTable.ts b/src/tree/ClosureTable/ClosureTable.ts index af6c8fa..10b7b07 100644 --- a/src/tree/ClosureTable/ClosureTable.ts +++ b/src/tree/ClosureTable/ClosureTable.ts @@ -1,11 +1,11 @@ -import { BinaryPredicate, ForEach, Kind, Mapping, Nullable } from '@jamashita/anden/type'; -import { MutableAddress, ReadonlyAddress } from '../../address/index.js'; +import { type BinaryPredicate, type ForEach, Kind, type Mapping, type Nullable } from '@jamashita/anden/type'; +import { MutableAddress, type ReadonlyAddress } from '../../address/index.js'; import { Quantity } from '../../collection/index.js'; import { ImmutableDictionary, MutableDictionary } from '../../dictionary/index.js'; import { ImmutableSequence } from '../../sequence/index.js'; -import { TreeID } from '../TreeID.js'; -import { ClosureTableHierarchies } from './ClosureTableHierarchies.js'; -import { ClosureTableHierarchy } from './ClosureTableHierarchy.js'; +import type { TreeID } from '../TreeID.js'; +import type { ClosureTableHierarchies } from './ClosureTableHierarchies.js'; +import type { ClosureTableHierarchy } from './ClosureTableHierarchy.js'; export class ClosureTable extends Quantity> { private readonly table: ImmutableDictionary>; @@ -22,7 +22,7 @@ export class ClosureTable extends Quantity> = MutableDictionary.empty(); - hierarchies.forEach((hierarchy: ClosureTableHierarchy) => { + for (const [, hierarchy] of hierarchies) { const offsprings: Nullable> = dictionary.get(hierarchy.getAncestor()); if (Kind.isNull(offsprings)) { @@ -31,11 +31,11 @@ export class ClosureTable extends Quantity extends Quantity { - const keys: Array = [...this.table].sort(([, v1]: [K, ReadonlyAddress], [, v2]: [K, ReadonlyAddress]) => { - return v1.size() - v2.size(); - }).map(([k]: [K, ReadonlyAddress]) => { - return k; - }); + const keys: Array = [...this.table] + .sort(([, v1]: [K, ReadonlyAddress], [, v2]: [K, ReadonlyAddress]) => { + return v1.size() - v2.size(); + }) + .map(([k]: [K, ReadonlyAddress]) => { + return k; + }); return ImmutableSequence.ofArray(keys); } diff --git a/src/tree/ClosureTable/ClosureTableHierarchies.ts b/src/tree/ClosureTable/ClosureTableHierarchies.ts index f1c865f..b79831c 100644 --- a/src/tree/ClosureTable/ClosureTableHierarchies.ts +++ b/src/tree/ClosureTable/ClosureTableHierarchies.ts @@ -1,13 +1,16 @@ -import { BinaryPredicate, ForEach, JSONifiable, Mapping, Nullable } from '@jamashita/anden/type'; -import { ReadonlyAddress } from '../../address/index.js'; -import { Collection, Quantity } from '../../collection/index.js'; -import { ReadonlyDictionary } from '../../dictionary/index.js'; +import type { BinaryPredicate, ForEach, JSONifiable, Mapping, Nullable } from '@jamashita/anden/type'; +import type { ReadonlyAddress } from '../../address/index.js'; +import { type Collection, Quantity } from '../../collection/index.js'; +import type { ReadonlyDictionary } from '../../dictionary/index.js'; import { ImmutableSequence } from '../../sequence/index.js'; -import { TreeID } from '../TreeID.js'; -import { ClosureTableHierarchy, ClosureTableJSON } from './ClosureTableHierarchy.js'; -import { TreeIDFactory } from './TreeIDFactory.js'; - -export class ClosureTableHierarchies extends Quantity> implements JSONifiable> { +import type { TreeID } from '../TreeID.js'; +import { ClosureTableHierarchy, type ClosureTableJSON } from './ClosureTableHierarchy.js'; +import type { TreeIDFactory } from './TreeIDFactory.js'; + +export class ClosureTableHierarchies + extends Quantity> + implements JSONifiable> +{ private readonly hierarchies: ImmutableSequence>; private static readonly EMPTY: ClosureTableHierarchies = new ClosureTableHierarchies(ImmutableSequence.empty()); @@ -18,11 +21,11 @@ export class ClosureTableHierarchies extends Quantity(hierarchies: ReadonlyDictionary>): ClosureTableHierarchies { const array: Array> = []; - hierarchies.forEach((offsprings: ReadonlyAddress, ancestor: K) => { - offsprings.forEach((offspring: K) => { - array.push(ClosureTableHierarchy.of(ancestor, offspring)); - }); - }); + for (const [ancestor, offsprings] of hierarchies) { + for (const [, offspring] of offsprings) { + array.push(ClosureTableHierarchy.of(ancestor, offspring)); + } + } return ClosureTableHierarchies.ofArray(array); } diff --git a/src/tree/ClosureTable/ClosureTableHierarchy.ts b/src/tree/ClosureTable/ClosureTableHierarchy.ts index 05ff593..e04ecad 100644 --- a/src/tree/ClosureTable/ClosureTableHierarchy.ts +++ b/src/tree/ClosureTable/ClosureTableHierarchy.ts @@ -1,7 +1,7 @@ import { ValueObject } from '@jamashita/anden/object'; -import { Equatable, JSONifiable, Primitive } from '@jamashita/anden/type'; -import { TreeID } from '../TreeID.js'; -import { TreeIDFactory } from './TreeIDFactory.js'; +import type { Equatable, JSONifiable, Primitive } from '@jamashita/anden/type'; +import type { TreeID } from '../TreeID.js'; +import type { TreeIDFactory } from './TreeIDFactory.js'; export type ClosureTableJSON = Readonly<{ ancestor: Primitive; diff --git a/src/tree/ClosureTable/TreeIDFactory.ts b/src/tree/ClosureTable/TreeIDFactory.ts index a52c15f..4d722aa 100644 --- a/src/tree/ClosureTable/TreeIDFactory.ts +++ b/src/tree/ClosureTable/TreeIDFactory.ts @@ -1,5 +1,5 @@ -import { Primitive } from '@jamashita/anden/type'; -import { TreeID } from '../TreeID.js'; +import type { Primitive } from '@jamashita/anden/type'; +import type { TreeID } from '../TreeID.js'; export interface TreeIDFactory { forge(id: Primitive): K; diff --git a/src/tree/ClosureTable/__tests__/ClosureTable.spec.ts b/src/tree/ClosureTable/__tests__/ClosureTable.spec.ts index fdba2c6..a193dd1 100644 --- a/src/tree/ClosureTable/__tests__/ClosureTable.spec.ts +++ b/src/tree/ClosureTable/__tests__/ClosureTable.spec.ts @@ -1,7 +1,7 @@ -import { SpyInstance } from 'vitest'; -import { MockAddress, ReadonlyAddress } from '../../../address/index.js'; -import { Dictionary, MockDictionary } from '../../../dictionary/index.js'; -import { ReadonlySequence } from '../../../sequence/index.js'; +import type { SpyInstance } from 'vitest'; +import { MockAddress, type ReadonlyAddress } from '../../../address/index.js'; +import { type Dictionary, MockDictionary } from '../../../dictionary/index.js'; +import type { ReadonlySequence } from '../../../sequence/index.js'; import { MockTreeID } from '../../mock/MockTreeID.js'; import { ClosureTable } from '../ClosureTable.js'; import { ClosureTableHierarchies } from '../ClosureTableHierarchies.js'; @@ -15,7 +15,7 @@ describe('ClosureTable', () => { expect(ClosureTable.empty()).toBe(ClosureTable.empty()); }); - it('\'s size is 0', () => { + it("'s size is 0", () => { expect(ClosureTable.empty().size()).toBe(0); }); }); @@ -137,6 +137,7 @@ describe('ClosureTable', () => { // @ts-expect-error table.table = dictionary; + // biome-ignore lint/complexity/noForEach: table.forEach(() => { // NOOP }); @@ -190,7 +191,7 @@ describe('ClosureTable', () => { ); const table: ClosureTable = ClosureTable.of(hierarchies); - let i: number = 0; + let i = 0; for (const [, v] of table) { switch (i) { diff --git a/src/tree/ClosureTable/__tests__/ClosureTableHierarchies.spec.ts b/src/tree/ClosureTable/__tests__/ClosureTableHierarchies.spec.ts index bcd8dcb..9a7612f 100644 --- a/src/tree/ClosureTable/__tests__/ClosureTableHierarchies.spec.ts +++ b/src/tree/ClosureTable/__tests__/ClosureTableHierarchies.spec.ts @@ -1,16 +1,16 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { SpyInstance } from 'vitest'; +import type { SpyInstance } from 'vitest'; import { ImmutableAddress, MockAddress } from '../../../address/index.js'; import { ImmutableDictionary } from '../../../dictionary/index.js'; import { MockTreeID } from '../../mock/MockTreeID.js'; import { ClosureTableHierarchies } from '../ClosureTableHierarchies.js'; -import { ClosureTableHierarchy, ClosureTableJSON } from '../ClosureTableHierarchy.js'; +import type { ClosureTableHierarchy, ClosureTableJSON } from '../ClosureTableHierarchy.js'; import { MockClosureTableHierarchy } from '../mock/MockClosureTableHierarchy.js'; import { MockTreeIDFactory } from '../mock/MockTreeIDFactory.js'; describe('ClosureTableHierarchies', () => { describe('empty', () => { - it('\'s size is 0', () => { + it("'s size is 0", () => { expect(ClosureTableHierarchies.empty().size()).toBe(0); }); @@ -21,13 +21,29 @@ describe('ClosureTableHierarchies', () => { describe('of', () => { it('returns flattened ClosureTableHierarchies', () => { - const dictionary: ImmutableDictionary> = ImmutableDictionary.ofMap(new Map([ - [new MockTreeID('mock 1'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 1'), new MockTreeID('mock 2'), new MockTreeID('mock 3'), new MockTreeID('mock 4'), new MockTreeID('mock 5')]))], - [new MockTreeID('mock 2'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 2'), new MockTreeID('mock 4'), new MockTreeID('mock 5')]))], - [new MockTreeID('mock 3'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 3')]))], - [new MockTreeID('mock 4'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 4')]))], - [new MockTreeID('mock 5'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 5')]))] - ])); + const dictionary: ImmutableDictionary> = ImmutableDictionary.ofMap( + new Map([ + [ + new MockTreeID('mock 1'), + ImmutableAddress.ofSet( + new Set([ + new MockTreeID('mock 1'), + new MockTreeID('mock 2'), + new MockTreeID('mock 3'), + new MockTreeID('mock 4'), + new MockTreeID('mock 5') + ]) + ) + ], + [ + new MockTreeID('mock 2'), + ImmutableAddress.ofSet(new Set([new MockTreeID('mock 2'), new MockTreeID('mock 4'), new MockTreeID('mock 5')])) + ], + [new MockTreeID('mock 3'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 3')]))], + [new MockTreeID('mock 4'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 4')]))], + [new MockTreeID('mock 5'), ImmutableAddress.ofSet(new Set([new MockTreeID('mock 5')]))] + ]) + ); const hierarchies: ClosureTableHierarchies = ClosureTableHierarchies.of(dictionary); @@ -81,7 +97,7 @@ describe('ClosureTableHierarchies', () => { const hierarchies: ClosureTableHierarchies = ClosureTableHierarchies.ofJSON(json, factory); expect(hierarchies.size()).toBe(json.length); - for (let i: number = 0; i < hierarchies.size(); i++) { + for (let i = 0; i < hierarchies.size(); i++) { expect(hierarchies.get(i)?.getAncestor().get()).toBe(json[i]?.ancestor); expect(hierarchies.get(i)?.getOffspring().get()).toBe(json[i]?.offspring); } @@ -217,6 +233,7 @@ describe('ClosureTableHierarchies', () => { // @ts-expect-error hierarchies.hierarchies = address; + // biome-ignore lint/complexity/noForEach: hierarchies.forEach(() => { // NOOP }); @@ -266,7 +283,7 @@ describe('ClosureTableHierarchies', () => { ]; const hierarchies: ClosureTableHierarchies = ClosureTableHierarchies.ofArray(array); - let i: number = 0; + let i = 0; for (const [, v] of hierarchies) { expect(v).toBe(array[i]); diff --git a/src/tree/ClosureTable/__tests__/ClosureTableHierarchy.spec.ts b/src/tree/ClosureTable/__tests__/ClosureTableHierarchy.spec.ts index bf5a02c..2f10102 100644 --- a/src/tree/ClosureTable/__tests__/ClosureTableHierarchy.spec.ts +++ b/src/tree/ClosureTable/__tests__/ClosureTableHierarchy.spec.ts @@ -1,5 +1,5 @@ import { MockTreeID } from '../../mock/MockTreeID.js'; -import { ClosureTableHierarchy, ClosureTableJSON } from '../ClosureTableHierarchy.js'; +import { ClosureTableHierarchy, type ClosureTableJSON } from '../ClosureTableHierarchy.js'; import { MockTreeIDFactory } from '../mock/MockTreeIDFactory.js'; describe('ClosureTableHierarchy', () => { diff --git a/src/tree/ClosureTable/mock/MockClosureTable.ts b/src/tree/ClosureTable/mock/MockClosureTable.ts index 6a4200b..9b66a91 100644 --- a/src/tree/ClosureTable/mock/MockClosureTable.ts +++ b/src/tree/ClosureTable/mock/MockClosureTable.ts @@ -1,15 +1,15 @@ -import { Kind, Nullable } from '@jamashita/anden/type'; +import { Kind, type Nullable } from '@jamashita/anden/type'; import { MutableAddress } from '../../../address/index.js'; import { MutableDictionary } from '../../../dictionary/index.js'; -import { TreeID } from '../../TreeID.js'; +import type { TreeID } from '../../TreeID.js'; import { ClosureTable } from '../ClosureTable.js'; -import { ClosureTableHierarchy } from '../ClosureTableHierarchy.js'; +import type { ClosureTableHierarchy } from '../ClosureTableHierarchy.js'; export class MockClosureTable extends ClosureTable { public constructor(...hierarchies: Array>) { const dictionary: MutableDictionary> = MutableDictionary.empty(); - hierarchies.forEach((hierarchy: ClosureTableHierarchy) => { + for (const hierarchy of hierarchies) { const offsprings: Nullable> = dictionary.get(hierarchy.getAncestor()); if (Kind.isNull(offsprings)) { @@ -18,11 +18,11 @@ export class MockClosureTable extends ClosureTable { address.add(hierarchy.getOffspring()); dictionary.set(hierarchy.getAncestor(), address); - return; + continue; } offsprings.add(hierarchy.getOffspring()); - }); + } super(dictionary); } diff --git a/src/tree/ClosureTable/mock/MockClosureTableHierarchies.ts b/src/tree/ClosureTable/mock/MockClosureTableHierarchies.ts index 8a0b8c4..ce631f1 100644 --- a/src/tree/ClosureTable/mock/MockClosureTableHierarchies.ts +++ b/src/tree/ClosureTable/mock/MockClosureTableHierarchies.ts @@ -1,7 +1,7 @@ import { ImmutableSequence } from '../../../sequence/index.js'; -import { TreeID } from '../../TreeID.js'; +import type { TreeID } from '../../TreeID.js'; import { ClosureTableHierarchies } from '../ClosureTableHierarchies.js'; -import { ClosureTableHierarchy } from '../ClosureTableHierarchy.js'; +import type { ClosureTableHierarchy } from '../ClosureTableHierarchy.js'; export class MockClosureTableHierarchies extends ClosureTableHierarchies { public constructor(...hierarchies: Array>) { diff --git a/src/tree/ClosureTable/mock/MockClosureTableHierarchy.ts b/src/tree/ClosureTable/mock/MockClosureTableHierarchy.ts index 8b66676..a83c0fc 100644 --- a/src/tree/ClosureTable/mock/MockClosureTableHierarchy.ts +++ b/src/tree/ClosureTable/mock/MockClosureTableHierarchy.ts @@ -1,8 +1,6 @@ -import { TreeID } from '../../TreeID.js'; +import type { TreeID } from '../../TreeID.js'; import { ClosureTableHierarchy } from '../ClosureTableHierarchy.js'; export class MockClosureTableHierarchy extends ClosureTableHierarchy { - public constructor(ancestor: K, offspring: K) { - super(ancestor, offspring); - } + // NOOP } diff --git a/src/tree/ClosureTable/mock/MockTreeIDFactory.ts b/src/tree/ClosureTable/mock/MockTreeIDFactory.ts index c74af55..80718ad 100644 --- a/src/tree/ClosureTable/mock/MockTreeIDFactory.ts +++ b/src/tree/ClosureTable/mock/MockTreeIDFactory.ts @@ -1,5 +1,5 @@ import { MockTreeID } from '../../mock/MockTreeID.js'; -import { TreeIDFactory } from '../TreeIDFactory.js'; +import type { TreeIDFactory } from '../TreeIDFactory.js'; export class MockTreeIDFactory implements TreeIDFactory { public forge(id: string): MockTreeID { diff --git a/src/tree/ReadonlyTrees.ts b/src/tree/ReadonlyTrees.ts index c90e6de..14277b9 100644 --- a/src/tree/ReadonlyTrees.ts +++ b/src/tree/ReadonlyTrees.ts @@ -1,6 +1,6 @@ -import { BinaryPredicate, ForEach, Nominative, Nullable } from '@jamashita/anden/type'; -import { Tree } from './Tree.js'; -import { TreeNode } from './TreeNode/index.js'; +import type { BinaryPredicate, ForEach, Nominative, Nullable } from '@jamashita/anden/type'; +import type { Tree } from './Tree.js'; +import type { TreeNode } from './TreeNode/index.js'; export interface ReadonlyTrees> extends Nominative { contains(value: V): boolean; diff --git a/src/tree/SerializableTree.ts b/src/tree/SerializableTree.ts index 414cc62..854c39e 100644 --- a/src/tree/SerializableTree.ts +++ b/src/tree/SerializableTree.ts @@ -1,7 +1,7 @@ -import { JSONifiable } from '@jamashita/anden/type'; +import type { JSONifiable } from '@jamashita/anden/type'; import { ATree } from './ATree.js'; -import { SerializableTreeObject } from './SerializableTreeObject.js'; -import { SerializableTreeNode, TreeNodeJSON } from './TreeNode/index.js'; +import type { SerializableTreeObject } from './SerializableTreeObject.js'; +import type { SerializableTreeNode, TreeNodeJSON } from './TreeNode/index.js'; export class SerializableTree extends ATree> implements JSONifiable { public static of(root: SerializableTreeNode): SerializableTree { diff --git a/src/tree/SerializableTreeObject.ts b/src/tree/SerializableTreeObject.ts index e6a0946..eef2231 100644 --- a/src/tree/SerializableTreeObject.ts +++ b/src/tree/SerializableTreeObject.ts @@ -1,4 +1,4 @@ -import { JSONifiable, Nominative } from '@jamashita/anden/type'; +import type { JSONifiable, Nominative } from '@jamashita/anden/type'; export interface SerializableTreeObject extends Nominative, JSONifiable { // NOOP diff --git a/src/tree/SerializableTrees.ts b/src/tree/SerializableTrees.ts index 8d125a2..7ed186d 100644 --- a/src/tree/SerializableTrees.ts +++ b/src/tree/SerializableTrees.ts @@ -1,11 +1,14 @@ -import { JSONifiable } from '@jamashita/anden/type'; -import { ImmutableAddress, MutableAddress, ReadonlyAddress } from '../address/index.js'; +import type { JSONifiable } from '@jamashita/anden/type'; +import { ImmutableAddress, MutableAddress, type ReadonlyAddress } from '../address/index.js'; import { ATrees } from './ATrees.js'; -import { SerializableTree } from './SerializableTree.js'; -import { SerializableTreeObject } from './SerializableTreeObject.js'; -import { SerializableTreeNode, TreeNodeJSON } from './TreeNode/index.js'; - -export class SerializableTrees extends ATrees, SerializableTree, MutableAddress>> implements JSONifiable> { +import type { SerializableTree } from './SerializableTree.js'; +import type { SerializableTreeObject } from './SerializableTreeObject.js'; +import type { SerializableTreeNode, TreeNodeJSON } from './TreeNode/index.js'; + +export class SerializableTrees + extends ATrees, SerializableTree, MutableAddress>> + implements JSONifiable> +{ public static empty(): SerializableTrees { return SerializableTrees.ofAddress(ImmutableAddress.empty()); } @@ -35,9 +38,9 @@ export class SerializableTrees extends ATr public toJSON(): ReadonlyArray { const json: Array = []; - this.trees.forEach((tree: SerializableTree) => { + for (const [, tree] of this.trees) { json.push(tree.toJSON()); - }); + } return json; } diff --git a/src/tree/StructurableTree.ts b/src/tree/StructurableTree.ts index e544af3..b854d50 100644 --- a/src/tree/StructurableTree.ts +++ b/src/tree/StructurableTree.ts @@ -1,10 +1,10 @@ -import { ImmutableAddress, MutableAddress } from '../address/index.js'; +import { type ImmutableAddress, MutableAddress } from '../address/index.js'; import { MutableDictionary } from '../dictionary/index.js'; import { ATree } from './ATree.js'; import { ClosureTableHierarchies } from './ClosureTable/index.js'; -import { StructurableTreeObject } from './StructurableTreeObject.js'; -import { TreeID } from './TreeID.js'; -import { StructurableTreeNode } from './TreeNode/index.js'; +import type { StructurableTreeObject } from './StructurableTreeObject.js'; +import type { TreeID } from './TreeID.js'; +import type { StructurableTreeNode } from './TreeNode/index.js'; export class StructurableTree> extends ATree> { public static of>(root: StructurableTreeNode): StructurableTree { @@ -34,8 +34,12 @@ export class StructurableTree, children: ImmutableAddress>, hierarchies: MutableDictionary>): void { - children.forEach((child: StructurableTreeNode) => { + private retrieveChildren( + node: StructurableTreeNode, + children: ImmutableAddress>, + hierarchies: MutableDictionary> + ): void { + for (const [, child] of children) { hierarchies.get(node.getTreeID())?.add(child.getTreeID()); this.retrieve(child, hierarchies); @@ -43,7 +47,7 @@ export class StructurableTree { diff --git a/src/tree/StructurableTreeObject.ts b/src/tree/StructurableTreeObject.ts index cab71df..70cdd8c 100644 --- a/src/tree/StructurableTreeObject.ts +++ b/src/tree/StructurableTreeObject.ts @@ -1,5 +1,5 @@ -import { Nominative } from '@jamashita/anden/type'; -import { TreeID } from './TreeID.js'; +import type { Nominative } from '@jamashita/anden/type'; +import type { TreeID } from './TreeID.js'; export interface StructurableTreeObject extends Nominative { getTreeID(): K; diff --git a/src/tree/StructurableTrees.ts b/src/tree/StructurableTrees.ts index 34dc93a..802c19d 100644 --- a/src/tree/StructurableTrees.ts +++ b/src/tree/StructurableTrees.ts @@ -1,21 +1,33 @@ -import { Kind, Nullable } from '@jamashita/anden/type'; -import { MutableAddress, ReadonlyAddress } from '../address/index.js'; -import { ImmutableDictionary, MutableDictionary, ReadonlyDictionary } from '../dictionary/index.js'; -import { ReadonlySequence } from '../sequence/index.js'; +import { Kind, type Nullable } from '@jamashita/anden/type'; +import { MutableAddress, type ReadonlyAddress } from '../address/index.js'; +import { ImmutableDictionary, MutableDictionary, type ReadonlyDictionary } from '../dictionary/index.js'; +import type { ReadonlySequence } from '../sequence/index.js'; import { ATrees } from './ATrees.js'; -import { ClosureTable, ClosureTableHierarchies, ClosureTableHierarchy } from './ClosureTable/index.js'; +import { type ClosureTable, ClosureTableHierarchies, type ClosureTableHierarchy } from './ClosureTable/index.js'; import { StructurableTree } from './StructurableTree.js'; -import { StructurableTreeObject } from './StructurableTreeObject.js'; +import type { StructurableTreeObject } from './StructurableTreeObject.js'; import { TreeError } from './TreeError.js'; -import { TreeID } from './TreeID.js'; +import type { TreeID } from './TreeID.js'; import { StructurableTreeNode } from './TreeNode/index.js'; -export class StructurableTrees> extends ATrees, StructurableTree, MutableDictionary>> { +export class StructurableTrees> extends ATrees< + K, + V, + StructurableTreeNode, + StructurableTree, + MutableDictionary> +> { public static empty>(): StructurableTrees { return StructurableTrees.ofDictionary(ImmutableDictionary.empty()); } - private static forgeInternal>(key: K, values: ReadonlyDictionary, table: ClosureTable, pool: MutableDictionary>, used: MutableAddress): StructurableTreeNode { + private static forgeInternal>( + key: K, + values: ReadonlyDictionary, + table: ClosureTable, + pool: MutableDictionary>, + used: MutableAddress + ): StructurableTreeNode { const value: Nullable = values.get(key); if (Kind.isNull(value)) { @@ -39,16 +51,16 @@ export class StructurableTrees> = MutableAddress.empty(); - children.forEach((k: K) => { + for (const [, k] of children) { if (k.equals(key)) { - return; + continue; } if (used.contains(k)) { - return; + continue; } address.add(StructurableTrees.forgeInternal(k, values, table, pool, used)); - }); + } const node: StructurableTreeNode = StructurableTreeNode.ofValue(value, address); @@ -61,15 +73,22 @@ export class StructurableTrees>(dictionary: ReadonlyDictionary>): StructurableTrees { + public static ofDictionary>( + dictionary: ReadonlyDictionary> + ): StructurableTrees { return StructurableTrees.ofInternal(dictionary); } - public static ofInternal>(dictionary: ReadonlyDictionary>): StructurableTrees { + public static ofInternal>( + dictionary: ReadonlyDictionary> + ): StructurableTrees { return new StructurableTrees(MutableDictionary.of(dictionary)); } - public static ofTable>(table: ClosureTable, values: ReadonlySequence): StructurableTrees { + public static ofTable>( + table: ClosureTable, + values: ReadonlySequence + ): StructurableTrees { if (table.isEmpty()) { if (values.isEmpty()) { return StructurableTrees.empty(); @@ -85,9 +104,9 @@ export class StructurableTrees> = MutableDictionary.empty(); const used: MutableAddress = MutableAddress.empty(); - table.sort().toArray().forEach((key: K) => { - StructurableTrees.forgeInternal(key, vs, table, pool, used); - }); + for (const k of table.sort().toArray()) { + StructurableTrees.forgeInternal(k, vs, table, pool, used); + } const trees: MutableDictionary> = pool.map((node: StructurableTreeNode) => { return StructurableTree.of(node); @@ -99,9 +118,9 @@ export class StructurableTrees>(sequence: ReadonlySequence): ReadonlyDictionary { const dictionary: MutableDictionary = MutableDictionary.empty(); - sequence.forEach((v: V) => { + for (const [, v] of sequence) { dictionary.set(v.getTreeID(), v); - }); + } return dictionary; } @@ -125,9 +144,9 @@ export class StructurableTrees { const hierarchies: Array> = []; - this.trees.forEach((tree: StructurableTree) => { + for (const [, tree] of this.trees) { hierarchies.push(...tree.toHierarchies().values()); - }); + } return ClosureTableHierarchies.ofArray(hierarchies); } diff --git a/src/tree/Tree.ts b/src/tree/Tree.ts index aa10d63..a0581e8 100644 --- a/src/tree/Tree.ts +++ b/src/tree/Tree.ts @@ -1,5 +1,5 @@ -import { ForEach, Nominative, Nullable, Predicate } from '@jamashita/anden/type'; -import { TreeNode } from './TreeNode/index.js'; +import type { ForEach, Nominative, Nullable, Predicate } from '@jamashita/anden/type'; +import type { TreeNode } from './TreeNode/index.js'; export interface Tree extends Nominative { contains(value: V): boolean; diff --git a/src/tree/TreeID.ts b/src/tree/TreeID.ts index 41efb33..4a938eb 100644 --- a/src/tree/TreeID.ts +++ b/src/tree/TreeID.ts @@ -1,4 +1,4 @@ -import { Nominative, Primitive } from '@jamashita/anden/type'; +import type { Nominative, Primitive } from '@jamashita/anden/type'; export interface TreeID extends Nominative { get(): Primitive; diff --git a/src/tree/TreeNode/ATreeNode.ts b/src/tree/TreeNode/ATreeNode.ts index ea19c8f..9ba36bf 100644 --- a/src/tree/TreeNode/ATreeNode.ts +++ b/src/tree/TreeNode/ATreeNode.ts @@ -1,7 +1,7 @@ import { Objet } from '@jamashita/anden/object'; -import { isEquatable, Kind, Nullable, Predicate } from '@jamashita/anden/type'; -import { MutableAddress } from '../../address/index.js'; -import { TreeNode } from './TreeNode.js'; +import { isEquatable, Kind, type Nullable, type Predicate } from '@jamashita/anden/type'; +import type { MutableAddress } from '../../address/index.js'; +import type { TreeNode } from './TreeNode.js'; export abstract class ATreeNode> extends Objet implements TreeNode { protected readonly value: V; @@ -84,11 +84,11 @@ export abstract class ATreeNode> extends return 1; } - let size: number = 1; + let size = 1; - this.children.forEach((child: T) => { + for (const child of this.children.values()) { size += child.size(); - }); + } return size; } @@ -119,8 +119,8 @@ export abstract class ATreeNode> extends private valuesInternal(values: Array): void { values.push(this.value); - this.children.forEach((child: T) => { + for (const child of this.children.values()) { child.valuesInternal(values); - }); + } } } diff --git a/src/tree/TreeNode/SerializableTreeNode.ts b/src/tree/TreeNode/SerializableTreeNode.ts index 2b75352..941e76b 100644 --- a/src/tree/TreeNode/SerializableTreeNode.ts +++ b/src/tree/TreeNode/SerializableTreeNode.ts @@ -1,20 +1,26 @@ -import { JSONifiable, ObjectLiteral } from '@jamashita/anden/type'; -import { Address, MutableAddress, ReadonlyAddress } from '../../address/index.js'; -import { SerializableTreeObject } from '../SerializableTreeObject.js'; +import type { JSONifiable, ObjectLiteral } from '@jamashita/anden/type'; +import { type Address, MutableAddress, type ReadonlyAddress } from '../../address/index.js'; +import type { SerializableTreeObject } from '../SerializableTreeObject.js'; import { ATreeNode } from './ATreeNode.js'; -import { TreeNode } from './TreeNode.js'; +import type { TreeNode } from './TreeNode.js'; export type TreeNodeJSON = Readonly<{ value: ObjectLiteral; children: ReadonlyArray; }>; -export class SerializableTreeNode extends ATreeNode> implements JSONifiable { +export class SerializableTreeNode + extends ATreeNode> + implements JSONifiable +{ public static of(node: SerializableTreeNode): SerializableTreeNode { return new SerializableTreeNode(node.getValue(), node.getChildren()); } - public static ofValue(value: V, children: ReadonlyAddress> = MutableAddress.empty()): SerializableTreeNode { + public static ofValue( + value: V, + children: ReadonlyAddress> = MutableAddress.empty() + ): SerializableTreeNode { return new SerializableTreeNode(value, children); } @@ -37,9 +43,9 @@ export class SerializableTreeNode extends public toJSON(): TreeNodeJSON { const children: Array = []; - this.children.forEach((child: SerializableTreeNode) => { + for (const [, child] of this.children) { children.push(child.toJSON()); - }); + } return { value: this.value.toJSON(), diff --git a/src/tree/TreeNode/StructurableTreeNode.ts b/src/tree/TreeNode/StructurableTreeNode.ts index a533f57..e787e82 100644 --- a/src/tree/TreeNode/StructurableTreeNode.ts +++ b/src/tree/TreeNode/StructurableTreeNode.ts @@ -1,15 +1,18 @@ -import { Address, MutableAddress, ReadonlyAddress } from '../../address/index.js'; -import { StructurableTreeObject } from '../StructurableTreeObject.js'; -import { TreeID } from '../TreeID.js'; +import { type Address, MutableAddress, type ReadonlyAddress } from '../../address/index.js'; +import type { StructurableTreeObject } from '../StructurableTreeObject.js'; +import type { TreeID } from '../TreeID.js'; import { ATreeNode } from './ATreeNode.js'; -import { TreeNode } from './TreeNode.js'; +import type { TreeNode } from './TreeNode.js'; export class StructurableTreeNode> extends ATreeNode> { public static of>(node: StructurableTreeNode): StructurableTreeNode { return StructurableTreeNode.ofValue(node.getValue(), node.getChildren()); } - public static ofValue>(value: V, children: ReadonlyAddress> = MutableAddress.empty()): StructurableTreeNode { + public static ofValue>( + value: V, + children: ReadonlyAddress> = MutableAddress.empty() + ): StructurableTreeNode { return new StructurableTreeNode(value, children); } diff --git a/src/tree/TreeNode/TreeNode.ts b/src/tree/TreeNode/TreeNode.ts index 4f6eb18..7a9c968 100644 --- a/src/tree/TreeNode/TreeNode.ts +++ b/src/tree/TreeNode/TreeNode.ts @@ -1,5 +1,5 @@ -import { Nominative, Nullable, Predicate } from '@jamashita/anden/type'; -import { Address } from '../../address/index.js'; +import type { Nominative, Nullable, Predicate } from '@jamashita/anden/type'; +import type { Address } from '../../address/index.js'; export interface TreeNode extends Nominative { append(node: TreeNode): void; diff --git a/src/tree/TreeNode/__tests__/ATreeNode.spec.ts b/src/tree/TreeNode/__tests__/ATreeNode.spec.ts index ba0039e..3c2b020 100644 --- a/src/tree/TreeNode/__tests__/ATreeNode.spec.ts +++ b/src/tree/TreeNode/__tests__/ATreeNode.spec.ts @@ -10,12 +10,10 @@ describe('ATreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); @@ -23,17 +21,15 @@ describe('ATreeNode', () => { expect(node.contains(new MockTreeObject(new MockTreeID('mock 1')))).toBe(true); }); - it('returns true if TreeNode\'s children have the value', () => { + it("returns true if TreeNode's children have the value", () => { const node: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); @@ -47,12 +43,10 @@ describe('ATreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); @@ -66,11 +60,7 @@ describe('ATreeNode', () => { const node01: MockTreeNode> = new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1'))); const node02: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ); expect(node01.equals(node01)).toBe(true); @@ -89,44 +79,25 @@ describe('ATreeNode', () => { const node03: MockTreeNode> = new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1'))); const node04: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ); const node05: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 3')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ); const node06: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 4'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 4')))])) ); const node07: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))), - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) + new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))), new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))]) ) ); const node08: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ); expect(node01.equals(node02)).toBe(false); @@ -149,42 +120,56 @@ describe('ATreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 1')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 1'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 1')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 1')) + ).toBe(true); }); - it('returns children\'s value when the TreeNode\'s children value matches', () => { + it("returns children's value when the TreeNode's children value matches", () => { const node: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 2')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 2'))).toBe(true); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 3')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 3'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 2')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 2')) + ).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 3')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 3')) + ).toBe(true); }); it('returns null when the TreeNode does not have such value', () => { @@ -192,19 +177,19 @@ describe('ATreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 4')); - })).toBeNull(); + expect( + node.find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 4')); + }) + ).toBeNull(); }); }); @@ -212,11 +197,7 @@ describe('ATreeNode', () => { it('returns false if it owns children', () => { const node: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ); expect(node.isLeaf()).toBe(false); @@ -231,24 +212,20 @@ describe('ATreeNode', () => { describe('size', () => { it('returns 1 when the TreeNode does not have children', () => { - const node: MockTreeNode> = new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 1')) - ); + const node: MockTreeNode> = new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1'))); expect(node.size()).toBe(1); }); - it('returns self + all children\'s number if TreeNode have children', () => { + it("returns self + all children's number if TreeNode have children", () => { const node: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); @@ -261,22 +238,20 @@ describe('ATreeNode', () => { it('returns JSON-like string', () => { const node01: MockTreeNode> = new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1'))); const node02: MockTreeNode> = new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 1')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) + ); + const node03: MockTreeNode> = new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))) + new MockTreeNode( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - const node03: MockTreeNode> = new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet(new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet(new Set([ - new MockTreeNode(new MockTreeObject(new MockTreeID('mock 3'))) - ]))) - ])) - ); expect(node01.toString()).toBe('{VALUE: mock 1}'); expect(node02.toString()).toBe('{VALUE: mock 1, CHILDREN: [{VALUE: mock 2}]}'); @@ -288,9 +263,7 @@ describe('ATreeNode', () => { it('returns its own value as Array', () => { const value: MockTreeObject = new MockTreeObject(new MockTreeID('mock 1')); - const node: MockTreeNode> = new MockTreeNode( - value - ); + const node: MockTreeNode> = new MockTreeNode(value); const values: Array> = [...node.values()]; @@ -309,12 +282,7 @@ describe('ATreeNode', () => { value1, MutableAddress.ofSet( new Set([ - new MockTreeNode(value2, - MutableAddress.ofSet( - new Set([ - new MockTreeNode(value3) - ]) - )), + new MockTreeNode(value2, MutableAddress.ofSet(new Set([new MockTreeNode(value3)]))), new MockTreeNode(value4), new MockTreeNode(value5) ]) diff --git a/src/tree/TreeNode/__tests__/SerializableTreeNode.spec.ts b/src/tree/TreeNode/__tests__/SerializableTreeNode.spec.ts index b83e5e9..cda3e54 100644 --- a/src/tree/TreeNode/__tests__/SerializableTreeNode.spec.ts +++ b/src/tree/TreeNode/__tests__/SerializableTreeNode.spec.ts @@ -8,11 +8,7 @@ describe('SerializableTreeNode', () => { it('copies shallowly', () => { const node01: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2'))) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')))])) ); const node02: SerializableTreeNode> = SerializableTreeNode.of(node01); @@ -23,8 +19,14 @@ describe('SerializableTreeNode', () => { describe('ofValue', () => { it('returns MutableAddress.empty() when empty children given', () => { - const node01: SerializableTreeNode> = SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.empty()); - const node02: SerializableTreeNode> = SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 1')), new MockAddress(new Set())); + const node01: SerializableTreeNode> = SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 1')), + MutableAddress.empty() + ); + const node02: SerializableTreeNode> = SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 1')), + new MockAddress(new Set()) + ); expect(node01.getChildren().isEmpty()).toBe(true); expect(node02.getChildren().isEmpty()).toBe(true); @@ -40,19 +42,11 @@ describe('SerializableTreeNode', () => { const node01: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(id1), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(id2)) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id2))])) ); const node02: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(id4)) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id4))])) ); node01.append(node02); @@ -60,10 +54,11 @@ describe('SerializableTreeNode', () => { expect(node01.size()).toBe(4); const children: MutableAddress>> = node01.getChildren(); - let i: number = 0; + let i = 0; expect(children.size()).toBe(2); + // biome-ignore lint/complexity/noForEach: children.forEach((child: SerializableTreeNode>) => { switch (i) { case 0: { @@ -90,16 +85,10 @@ describe('SerializableTreeNode', () => { const id3: MockTreeID = new MockTreeID('mock 3'); const id4: MockTreeID = new MockTreeID('mock 4'); - const node01: SerializableTreeNode> = SerializableTreeNode.ofValue( - new MockTreeObject(id1) - ); + const node01: SerializableTreeNode> = SerializableTreeNode.ofValue(new MockTreeObject(id1)); const node02: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(id4)) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id4))])) ); node01.append(node02); @@ -107,10 +96,11 @@ describe('SerializableTreeNode', () => { expect(node01.size()).toBe(3); const children: MutableAddress>> = node01.getChildren(); - let i: number = 0; + let i = 0; expect(children.size()).toBe(1); + // biome-ignore lint/complexity/noForEach: children.forEach((child: SerializableTreeNode>) => { switch (i) { case 0: { @@ -134,42 +124,56 @@ describe('SerializableTreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 1')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 1'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 1')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 1')) + ).toBe(true); }); - it('returns children\'s value when the TreeNode\'s children value matches', () => { + it("returns children's value when the TreeNode's children value matches", () => { const node: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 2')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 2'))).toBe(true); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 3')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 3'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 2')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 2')) + ).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 3')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 3')) + ).toBe(true); }); it('returns null when the TreeNode does not have such value', () => { @@ -177,19 +181,19 @@ describe('SerializableTreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 4')); - })).toBeNull(); + expect( + node.find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 4')); + }) + ).toBeNull(); }); }); @@ -197,13 +201,15 @@ describe('SerializableTreeNode', () => { it('returns SerializableTreeNodeJSON', () => { const node: SerializableTreeNode> = SerializableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet(new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet(new Set([ - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]))), - SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) - ])) + MutableAddress.ofSet( + new Set([ + SerializableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ), + SerializableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) + ]) + ) ); expect(node.toJSON()).toStrictEqual({ diff --git a/src/tree/TreeNode/__tests__/StructurableTreeNode.spec.ts b/src/tree/TreeNode/__tests__/StructurableTreeNode.spec.ts index a931b4f..ce19015 100644 --- a/src/tree/TreeNode/__tests__/StructurableTreeNode.spec.ts +++ b/src/tree/TreeNode/__tests__/StructurableTreeNode.spec.ts @@ -6,8 +6,14 @@ import { StructurableTreeNode } from '../StructurableTreeNode.js'; describe('StructurableTreeNode', () => { describe('of', () => { it('returns MutableAddress.empty() when empty children given', () => { - const node01: StructurableTreeNode> = StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.empty()); - const node02: StructurableTreeNode> = StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 1')), new MockAddress(new Set())); + const node01: StructurableTreeNode> = StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 1')), + MutableAddress.empty() + ); + const node02: StructurableTreeNode> = StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 1')), + new MockAddress(new Set()) + ); expect(node01.getChildren().isEmpty()).toBe(true); expect(node02.getChildren().isEmpty()).toBe(true); @@ -20,12 +26,10 @@ describe('StructurableTreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); @@ -45,19 +49,11 @@ describe('StructurableTreeNode', () => { const node01: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(id1), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(id2)) - ]) - ) + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(id2))])) ); const node02: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(id4)) - ]) - ) + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(id4))])) ); node01.append(node02); @@ -65,10 +61,11 @@ describe('StructurableTreeNode', () => { expect(node01.size()).toBe(4); const children: MutableAddress>> = node01.getChildren(); - let i: number = 0; + let i = 0; expect(children.size()).toBe(2); + // biome-ignore lint/complexity/noForEach: children.forEach((child: StructurableTreeNode>) => { switch (i) { case 0: { @@ -95,16 +92,10 @@ describe('StructurableTreeNode', () => { const id3: MockTreeID = new MockTreeID('mock 3'); const id4: MockTreeID = new MockTreeID('mock 4'); - const node01: StructurableTreeNode> = StructurableTreeNode.ofValue( - new MockTreeObject(id1) - ); + const node01: StructurableTreeNode> = StructurableTreeNode.ofValue(new MockTreeObject(id1)); const node02: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(id4)) - ]) - ) + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(id4))])) ); node01.append(node02); @@ -112,10 +103,11 @@ describe('StructurableTreeNode', () => { expect(node01.size()).toBe(3); const children: MutableAddress>> = node01.getChildren(); - let i: number = 0; + let i = 0; expect(children.size()).toBe(1); + // biome-ignore lint/complexity/noForEach: children.forEach((child: StructurableTreeNode>) => { switch (i) { case 0: { @@ -139,42 +131,56 @@ describe('StructurableTreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 1')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 1'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 1')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 1')) + ).toBe(true); }); - it('returns children\'s value when the TreeNode\'s children value matches', () => { + it("returns children's value when the TreeNode's children value matches", () => { const node: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 2')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 2'))).toBe(true); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 3')); - })?.getValue().getTreeID().equals(new MockTreeID('mock 3'))).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 2')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 2')) + ).toBe(true); + expect( + node + .find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 3')); + }) + ?.getValue() + .getTreeID() + .equals(new MockTreeID('mock 3')) + ).toBe(true); }); it('returns null when the TreeNode does not have such value', () => { @@ -182,33 +188,35 @@ describe('StructurableTreeNode', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]) - )) + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ) ]) ) ); - expect(node.find((v: MockTreeObject) => { - return v.getTreeID().equals(new MockTreeID('mock 4')); - })).toBeNull(); + expect( + node.find((v: MockTreeObject) => { + return v.getTreeID().equals(new MockTreeID('mock 4')); + }) + ).toBeNull(); }); }); describe('getTreeID', () => { - it('returns value\'s TreeID', () => { + it("returns value's TreeID", () => { const node: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]))), - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) - ])) + MutableAddress.ofSet( + new Set([ + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ), + StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) + ]) + ) ); expect(node.getTreeID().get()).toBe('mock 1'); @@ -219,13 +227,15 @@ describe('StructurableTreeNode', () => { it('returns true when the value is contained in the tree node', () => { const node: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]))), - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) - ])) + MutableAddress.ofSet( + new Set([ + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ), + StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) + ]) + ) ); expect(node.has(new MockTreeID('mock 1'))).toBe(true); @@ -237,13 +247,15 @@ describe('StructurableTreeNode', () => { it('returns false when the value is not contained in the tree node', () => { const node: StructurableTreeNode> = StructurableTreeNode.ofValue( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet(new Set([ - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3'))) - ]))), - StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) - ])) + MutableAddress.ofSet( + new Set([ + StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock 2')), + MutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 3')))])) + ), + StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock 4'))) + ]) + ) ); expect(node.has(new MockTreeID('mock 5'))).toBe(false); diff --git a/src/tree/TreeNode/mock/MockTreeNode.ts b/src/tree/TreeNode/mock/MockTreeNode.ts index 57d1ad2..31e48b2 100644 --- a/src/tree/TreeNode/mock/MockTreeNode.ts +++ b/src/tree/TreeNode/mock/MockTreeNode.ts @@ -1,9 +1,9 @@ -import { Address, MutableAddress, ReadonlyAddress } from '../../../address/index.js'; -import { SerializableTreeObject } from '../../SerializableTreeObject.js'; -import { StructurableTreeObject } from '../../StructurableTreeObject.js'; -import { TreeID } from '../../TreeID.js'; +import { type Address, MutableAddress, type ReadonlyAddress } from '../../../address/index.js'; +import type { SerializableTreeObject } from '../../SerializableTreeObject.js'; +import type { StructurableTreeObject } from '../../StructurableTreeObject.js'; +import type { TreeID } from '../../TreeID.js'; import { ATreeNode } from '../ATreeNode.js'; -import { TreeNode } from '../TreeNode.js'; +import type { TreeNode } from '../TreeNode.js'; interface MockTreeObject extends StructurableTreeObject, SerializableTreeObject { // NOOP diff --git a/src/tree/Trees.ts b/src/tree/Trees.ts index ae2af24..f401c3e 100644 --- a/src/tree/Trees.ts +++ b/src/tree/Trees.ts @@ -1,5 +1,5 @@ -import { ReadonlyTrees } from './ReadonlyTrees.js'; -import { Tree } from './Tree.js'; +import type { ReadonlyTrees } from './ReadonlyTrees.js'; +import type { Tree } from './Tree.js'; export interface Trees> extends ReadonlyTrees { add(tree: E): Trees; diff --git a/src/tree/__tests__/SerializableTree.spec.ts b/src/tree/__tests__/SerializableTree.spec.ts index 74539ad..8d84977 100644 --- a/src/tree/__tests__/SerializableTree.spec.ts +++ b/src/tree/__tests__/SerializableTree.spec.ts @@ -1,4 +1,4 @@ -import { SpyInstance } from 'vitest'; +import type { SpyInstance } from 'vitest'; import { MockTreeID } from '../mock/MockTreeID.js'; import { MockTreeObject } from '../mock/MockTreeObject.js'; import { SerializableTree } from '../SerializableTree.js'; diff --git a/src/tree/__tests__/SerializableTrees.spec.ts b/src/tree/__tests__/SerializableTrees.spec.ts index ed8a5a6..9da47fd 100644 --- a/src/tree/__tests__/SerializableTrees.spec.ts +++ b/src/tree/__tests__/SerializableTrees.spec.ts @@ -17,15 +17,9 @@ describe('SerializableTrees', () => { it('add one tree into empty trees', () => { const id1: MockTreeID = new MockTreeID('tree id 1'); - const tree1: SerializableTree> = SerializableTree.of( - SerializableTreeNode.ofValue( - new MockTreeObject(id1) - ) - ); + const tree1: SerializableTree> = SerializableTree.of(SerializableTreeNode.ofValue(new MockTreeObject(id1))); - const trees: SerializableTrees> = SerializableTrees.ofAddress( - MutableAddress.empty() - ); + const trees: SerializableTrees> = SerializableTrees.ofAddress(MutableAddress.empty()); expect(trees.isEmpty()).toBe(true); @@ -33,6 +27,7 @@ describe('SerializableTrees', () => { expect(trees.isEmpty()).toBe(false); expect(trees.size()).toBe(1); + // biome-ignore lint/complexity/noForEach: trees.forEach((obj: MockTreeObject) => { expect(obj.getTreeID()).toBe(id1); }); @@ -46,71 +41,36 @@ describe('SerializableTrees', () => { const id5: MockTreeID = new MockTreeID('tree id 5'); const id6: MockTreeID = new MockTreeID('tree id 6'); const id7: MockTreeID = new MockTreeID('tree id 7'); - const ids: Array = [ - id1, - id2, - id3, - id4, - id5, - id6, - id7 - ]; + const ids: Array = [id1, id2, id3, id4, id5, id6, id7]; const tree1: SerializableTree> = SerializableTree.of( SerializableTreeNode.ofValue( new MockTreeObject(id1), MutableAddress.ofSet( new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id2) - ), + SerializableTreeNode.ofValue(new MockTreeObject(id2)), SerializableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id4) - ) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id4))])) ) ]) ) ) ); const tree2: SerializableTree> = SerializableTree.of( - SerializableTreeNode.ofValue( - new MockTreeObject(id5), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id6) - ) - ]) - ) - ) - ); - const tree3: SerializableTree> = SerializableTree.of( - SerializableTreeNode.ofValue( - new MockTreeObject(id7) - ) + SerializableTreeNode.ofValue(new MockTreeObject(id5), MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id6))]))) ); + const tree3: SerializableTree> = SerializableTree.of(SerializableTreeNode.ofValue(new MockTreeObject(id7))); - const trees: SerializableTrees> = SerializableTrees.ofAddress( - MutableAddress.ofSet( - new Set([ - tree1, - tree2 - ]) - ) - ); - let i: number = 0; + const trees: SerializableTrees> = SerializableTrees.ofAddress(MutableAddress.ofSet(new Set([tree1, tree2]))); + let i = 0; expect(trees.size()).toBe(2); trees.add(tree3); expect(trees.size()).toBe(3); + // biome-ignore lint/complexity/noForEach: trees.forEach((obj: MockTreeObject) => { expect(obj.getTreeID()).toBe(ids[i]); i++; @@ -133,50 +93,21 @@ describe('SerializableTrees', () => { new MockTreeObject(id1), MutableAddress.ofSet( new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id2) - ), + SerializableTreeNode.ofValue(new MockTreeObject(id2)), SerializableTreeNode.ofValue( new MockTreeObject(id3), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id4) - ) - ]) - ) + MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id4))])) ) ]) ) ) ); const tree2: SerializableTree> = SerializableTree.of( - SerializableTreeNode.ofValue( - new MockTreeObject(id5), - MutableAddress.ofSet( - new Set([ - SerializableTreeNode.ofValue( - new MockTreeObject(id6) - ) - ]) - ) - ) - ); - const tree3: SerializableTree> = SerializableTree.of( - SerializableTreeNode.ofValue( - new MockTreeObject(id7) - ) + SerializableTreeNode.ofValue(new MockTreeObject(id5), MutableAddress.ofSet(new Set([SerializableTreeNode.ofValue(new MockTreeObject(id6))]))) ); + const tree3: SerializableTree> = SerializableTree.of(SerializableTreeNode.ofValue(new MockTreeObject(id7))); - const trees: SerializableTrees> = SerializableTrees.ofAddress( - MutableAddress.ofSet( - new Set([ - tree1, - tree2, - tree3 - ]) - ) - ); + const trees: SerializableTrees> = SerializableTrees.ofAddress(MutableAddress.ofSet(new Set([tree1, tree2, tree3]))); expect(trees.toJSON()).toStrictEqual([ { diff --git a/src/tree/__tests__/StructurableTree.spec.ts b/src/tree/__tests__/StructurableTree.spec.ts index ebacb15..dba2a10 100644 --- a/src/tree/__tests__/StructurableTree.spec.ts +++ b/src/tree/__tests__/StructurableTree.spec.ts @@ -1,6 +1,6 @@ -import { SpyInstance } from 'vitest'; +import type { SpyInstance } from 'vitest'; import { MutableAddress } from '../../address/index.js'; -import { ClosureTableHierarchies } from '../ClosureTable/ClosureTableHierarchies.js'; +import type { ClosureTableHierarchies } from '../ClosureTable/ClosureTableHierarchies.js'; import { MockTreeID } from '../mock/MockTreeID.js'; import { MockTreeObject } from '../mock/MockTreeObject.js'; import { StructurableTree } from '../StructurableTree.js'; @@ -9,7 +9,9 @@ import { StructurableTreeNode } from '../TreeNode/StructurableTreeNode.js'; describe('StructurableTree', () => { describe('getTreeID', () => { it('delegates its root instance', () => { - const root: StructurableTreeNode> = StructurableTreeNode.ofValue(new MockTreeObject(new MockTreeID('mock'))); + const root: StructurableTreeNode> = StructurableTreeNode.ofValue( + new MockTreeObject(new MockTreeID('mock')) + ); const spy: SpyInstance = vi.spyOn(root, 'getTreeID'); diff --git a/src/tree/__tests__/StructurableTrees.spec.ts b/src/tree/__tests__/StructurableTrees.spec.ts index 3823cd6..f67bd87 100644 --- a/src/tree/__tests__/StructurableTrees.spec.ts +++ b/src/tree/__tests__/StructurableTrees.spec.ts @@ -1,9 +1,9 @@ -import { Nullable } from '@jamashita/anden/type'; +import type { Nullable } from '@jamashita/anden/type'; import { ImmutableAddress } from '../../address/index.js'; import { ImmutableDictionary } from '../../dictionary/index.js'; import { MutableSequence } from '../../sequence/index.js'; import { ClosureTable } from '../ClosureTable/ClosureTable.js'; -import { ClosureTableHierarchies } from '../ClosureTable/ClosureTableHierarchies.js'; +import type { ClosureTableHierarchies } from '../ClosureTable/ClosureTableHierarchies.js'; import { MockClosureTableHierarchies } from '../ClosureTable/mock/MockClosureTableHierarchies.js'; import { MockClosureTableHierarchy } from '../ClosureTable/mock/MockClosureTableHierarchy.js'; import { MockTreeID } from '../mock/MockTreeID.js'; @@ -35,9 +35,7 @@ describe('StructurableTrees', () => { const id: MockTreeID = new MockTreeID('id 1'); const table: ClosureTable = ClosureTable.empty(); - const values: MutableSequence> = MutableSequence.ofArray([ - new MockTreeObject(id) - ]); + const values: MutableSequence> = MutableSequence.ofArray([new MockTreeObject(id)]); expect(() => { StructurableTrees.ofTable(table, values); @@ -47,11 +45,7 @@ describe('StructurableTrees', () => { it('throws TreeError when empty Dictionary> given', () => { const id: MockTreeID = new MockTreeID('id 1'); - const table: ClosureTable = ClosureTable.of( - new MockClosureTableHierarchies( - new MockClosureTableHierarchy(id, id) - ) - ); + const table: ClosureTable = ClosureTable.of(new MockClosureTableHierarchies(new MockClosureTableHierarchy(id, id))); const values: MutableSequence> = MutableSequence.empty(); expect(() => { @@ -63,14 +57,8 @@ describe('StructurableTrees', () => { const id1: MockTreeID = new MockTreeID('id 1'); const id2: MockTreeID = new MockTreeID('id 2'); - const table: ClosureTable = ClosureTable.of( - new MockClosureTableHierarchies( - new MockClosureTableHierarchy(id1, id1) - ) - ); - const values: MutableSequence> = MutableSequence.ofArray([ - new MockTreeObject(id2) - ]); + const table: ClosureTable = ClosureTable.of(new MockClosureTableHierarchies(new MockClosureTableHierarchy(id1, id1))); + const values: MutableSequence> = MutableSequence.ofArray([new MockTreeObject(id2)]); expect(() => { StructurableTrees.ofTable(table, values); @@ -80,14 +68,8 @@ describe('StructurableTrees', () => { it('returns one simplest flat Tree', () => { const id: MockTreeID = new MockTreeID('id 1'); - const table: ClosureTable = ClosureTable.of( - new MockClosureTableHierarchies( - new MockClosureTableHierarchy(id, id) - ) - ); - const values: MutableSequence> = MutableSequence.ofArray([ - new MockTreeObject(id) - ]); + const table: ClosureTable = ClosureTable.of(new MockClosureTableHierarchies(new MockClosureTableHierarchy(id, id))); + const values: MutableSequence> = MutableSequence.ofArray([new MockTreeObject(id)]); const trees: StructurableTrees> = StructurableTrees.ofTable(table, values); @@ -106,15 +88,9 @@ describe('StructurableTrees', () => { const id2: MockTreeID = new MockTreeID('id 2'); const table: ClosureTable = ClosureTable.of( - new MockClosureTableHierarchies( - new MockClosureTableHierarchy(id1, id1), - new MockClosureTableHierarchy(id2, id2) - ) + new MockClosureTableHierarchies(new MockClosureTableHierarchy(id1, id1), new MockClosureTableHierarchy(id2, id2)) ); - const values: MutableSequence> = MutableSequence.ofArray([ - new MockTreeObject(id1), - new MockTreeObject(id2) - ]); + const values: MutableSequence> = MutableSequence.ofArray([new MockTreeObject(id1), new MockTreeObject(id2)]); const trees: StructurableTrees> = StructurableTrees.ofTable(table, values); @@ -187,7 +163,7 @@ describe('StructurableTrees', () => { expect(root1.getTreeID()).toBe(id1); expect(root1.getChildren().size()).toBe(2); - let i: number = 0; + let i = 0; for (const [, v] of root1.getChildren()) { switch (i) { @@ -259,14 +235,10 @@ describe('StructurableTrees', () => { const id1: MockTreeID = new MockTreeID('tree id 1'); const tree1: StructurableTree> = StructurableTree.of( - StructurableTreeNode.ofValue( - new MockTreeObject(id1) - ) + StructurableTreeNode.ofValue(new MockTreeObject(id1)) ); - const trees: StructurableTrees> = StructurableTrees.ofDictionary( - ImmutableDictionary.empty() - ); + const trees: StructurableTrees> = StructurableTrees.ofDictionary(ImmutableDictionary.empty()); expect(trees.isEmpty()).toBe(true); @@ -274,6 +246,7 @@ describe('StructurableTrees', () => { expect(trees.isEmpty()).toBe(false); expect(trees.size()).toBe(1); + // biome-ignore lint/complexity/noForEach: trees.forEach((obj: MockTreeObject) => { expect(obj.getTreeID()).toBe(id1); }); @@ -287,33 +260,17 @@ describe('StructurableTrees', () => { const id5: MockTreeID = new MockTreeID('tree id 5'); const id6: MockTreeID = new MockTreeID('tree id 6'); const id7: MockTreeID = new MockTreeID('tree id 7'); - const ids: Array = [ - id1, - id2, - id3, - id4, - id5, - id6, - id7 - ]; + const ids: Array = [id1, id2, id3, id4, id5, id6, id7]; const tree1: StructurableTree> = StructurableTree.of( StructurableTreeNode.ofValue( new MockTreeObject(id1), ImmutableAddress.ofSet( new Set([ - StructurableTreeNode.ofValue( - new MockTreeObject(id2) - ), + StructurableTreeNode.ofValue(new MockTreeObject(id2)), StructurableTreeNode.ofValue( new MockTreeObject(id3), - ImmutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue( - new MockTreeObject(id4) - ) - ]) - ) + ImmutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(id4))])) ) ]) ) @@ -322,19 +279,11 @@ describe('StructurableTrees', () => { const tree2: StructurableTree> = StructurableTree.of( StructurableTreeNode.ofValue( new MockTreeObject(id5), - ImmutableAddress.ofSet( - new Set([ - StructurableTreeNode.ofValue( - new MockTreeObject(id6) - ) - ]) - ) + ImmutableAddress.ofSet(new Set([StructurableTreeNode.ofValue(new MockTreeObject(id6))])) ) ); const tree3: StructurableTree> = StructurableTree.of( - StructurableTreeNode.ofValue( - new MockTreeObject(id7) - ) + StructurableTreeNode.ofValue(new MockTreeObject(id7)) ); const trees: StructurableTrees> = StructurableTrees.ofDictionary( @@ -345,13 +294,14 @@ describe('StructurableTrees', () => { ]) ) ); - let i: number = 0; + let i = 0; expect(trees.size()).toBe(2); trees.add(tree3); expect(trees.size()).toBe(3); + // biome-ignore lint/complexity/noForEach: trees.forEach((obj: MockTreeObject) => { expect(obj.getTreeID()).toBe(ids[i]); i++; @@ -404,14 +354,8 @@ describe('StructurableTrees', () => { it('returns one-length array when no no-children one tree given', () => { const id1: MockTreeID = new MockTreeID('id 1'); - const table: ClosureTable = ClosureTable.of( - new MockClosureTableHierarchies( - new MockClosureTableHierarchy(id1, id1) - ) - ); - const values: MutableSequence> = MutableSequence.ofArray([ - new MockTreeObject(id1) - ]); + const table: ClosureTable = ClosureTable.of(new MockClosureTableHierarchies(new MockClosureTableHierarchy(id1, id1))); + const values: MutableSequence> = MutableSequence.ofArray([new MockTreeObject(id1)]); const trees: StructurableTrees> = StructurableTrees.ofTable(table, values); const hierarchies: ClosureTableHierarchies = trees.toHierarchies(); diff --git a/src/tree/__tests__/Tree.spec.ts b/src/tree/__tests__/Tree.spec.ts index 51f3db9..e772c06 100644 --- a/src/tree/__tests__/Tree.spec.ts +++ b/src/tree/__tests__/Tree.spec.ts @@ -1,9 +1,9 @@ -import { SpyInstance } from 'vitest'; +import type { SpyInstance } from 'vitest'; import { MutableAddress } from '../../address/index.js'; +import { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; import { MockTree } from '../mock/MockTree.js'; import { MockTreeID } from '../mock/MockTreeID.js'; import { MockTreeObject } from '../mock/MockTreeObject.js'; -import { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; describe('Tree', () => { describe('contains', () => { @@ -40,41 +40,31 @@ describe('Tree', () => { const tree04: MockTree> = new MockTree( new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))])) ) ); const tree05: MockTree> = new MockTree( new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ) ); const tree06: MockTree> = new MockTree( new MockTreeNode( new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))])) ) ); const tree07: MockTree> = new MockTree( new MockTreeNode( new MockTreeObject(new MockTreeID('mock 2')), - MutableAddress.ofSet( - new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2')))])) ) ); const tree08: MockTree> = new MockTree( new MockTreeNode( new MockTreeObject(new MockTreeID('mock 1')), - MutableAddress.ofSet( - new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 1')))])) ) ); @@ -119,32 +109,20 @@ describe('Tree', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 2')) - ), + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))), new MockTreeNode( new MockTreeObject(new MockTreeID('mock 3')), MutableAddress.ofSet( new Set([ new MockTreeNode( new MockTreeObject(new MockTreeID('mock 5')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 7')) - ) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 7')))])) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 6')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 6'))) ]) ) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 4')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 4'))) ]) ) ) @@ -163,32 +141,20 @@ describe('Tree', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 2')) - ), + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))), new MockTreeNode( new MockTreeObject(new MockTreeID('mocc 3')), MutableAddress.ofSet( new Set([ new MockTreeNode( new MockTreeObject(new MockTreeID('mock 5')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 7')) - ) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 7')))])) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 6')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 6'))) ]) ) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 4')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 4'))) ]) ) ) @@ -219,10 +185,11 @@ describe('Tree', () => { }); describe('forEach', () => { - it('iterates root\'s value when the tree only has root', () => { + it("iterates root's value when the tree only has root", () => { const obj: MockTreeObject = new MockTreeObject(new MockTreeID('mock 1')); const tree: MockTree> = new MockTree(new MockTreeNode(obj)); + // biome-ignore lint/complexity/noForEach: tree.forEach((v: MockTreeObject) => { expect(v).toBe(obj); }); @@ -237,54 +204,29 @@ describe('Tree', () => { const obj6: MockTreeObject = new MockTreeObject(new MockTreeID('mock 6')); const obj7: MockTreeObject = new MockTreeObject(new MockTreeID('mock 7')); - const objs: Array> = [ - obj1, - obj2, - obj3, - obj5, - obj7, - obj6, - obj4 - ]; + const objs: Array> = [obj1, obj2, obj3, obj5, obj7, obj6, obj4]; const tree: MockTree> = new MockTree( new MockTreeNode( obj1, MutableAddress.ofSet( new Set([ - new MockTreeNode( - obj2 - ), + new MockTreeNode(obj2), new MockTreeNode( obj3, MutableAddress.ofSet( - new Set([ - new MockTreeNode( - obj5, - MutableAddress.ofSet( - new Set([ - new MockTreeNode( - obj7 - ) - ]) - ) - ), - new MockTreeNode( - obj6 - ) - ]) + new Set([new MockTreeNode(obj5, MutableAddress.ofSet(new Set([new MockTreeNode(obj7)]))), new MockTreeNode(obj6)]) ) ), - new MockTreeNode( - obj4 - ) + new MockTreeNode(obj4) ]) ) ) ); - let i: number = 0; + let i = 0; + // biome-ignore lint/complexity/noForEach: tree.forEach((v: MockTreeObject) => { expect(v).toBe(objs[i]); i++; @@ -342,32 +284,20 @@ describe('Tree', () => { new MockTreeObject(new MockTreeID('mock 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 2')) - ), + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 2'))), new MockTreeNode( new MockTreeObject(new MockTreeID('mock 3')), MutableAddress.ofSet( new Set([ new MockTreeNode( new MockTreeObject(new MockTreeID('mock 5')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 7')) - ) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mock 7')))])) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 6')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 6'))) ]) ) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mock 4')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mock 4'))) ]) ) ) @@ -386,32 +316,20 @@ describe('Tree', () => { new MockTreeObject(new MockTreeID('mocc 1')), MutableAddress.ofSet( new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mocc 2')) - ), + new MockTreeNode(new MockTreeObject(new MockTreeID('mocc 2'))), new MockTreeNode( new MockTreeObject(new MockTreeID('mocc 3')), MutableAddress.ofSet( new Set([ new MockTreeNode( new MockTreeObject(new MockTreeID('mocc 5')), - MutableAddress.ofSet( - new Set([ - new MockTreeNode( - new MockTreeObject(new MockTreeID('mocc 7')) - ) - ]) - ) + MutableAddress.ofSet(new Set([new MockTreeNode(new MockTreeObject(new MockTreeID('mocc 7')))])) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mocc 6')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mocc 6'))) ]) ) ), - new MockTreeNode( - new MockTreeObject(new MockTreeID('mocc 4')) - ) + new MockTreeNode(new MockTreeObject(new MockTreeID('mocc 4'))) ]) ) ) diff --git a/src/tree/__tests__/Trees.spec.ts b/src/tree/__tests__/Trees.spec.ts index 162be85..ed02e23 100644 --- a/src/tree/__tests__/Trees.spec.ts +++ b/src/tree/__tests__/Trees.spec.ts @@ -1,6 +1,6 @@ import { MockValueObject } from '@jamashita/anden/object'; -import { Nullable } from '@jamashita/anden/type'; -import { SpyInstance } from 'vitest'; +import type { Nullable } from '@jamashita/anden/type'; +import type { SpyInstance } from 'vitest'; import { MockAddress } from '../../address/index.js'; import { MockDictionary } from '../../dictionary/index.js'; import { MockTree } from '../mock/MockTree.js'; @@ -13,17 +13,9 @@ describe('Trees', () => { describe('contains', () => { it('delegates its retaining tree', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const spy: SpyInstance = vi.spyOn(tree, 'contains'); @@ -38,17 +30,9 @@ describe('Trees', () => { describe('equals', () => { it('returns true when the same instance given', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -57,17 +41,9 @@ describe('Trees', () => { it('returns false when the different class instance given', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -76,17 +52,9 @@ describe('Trees', () => { it('delegates its retaining dictionary', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -95,13 +63,7 @@ describe('Trees', () => { const spy: SpyInstance = vi.spyOn(dictionary, 'equals'); - trees.equals(new MockTrees( - new MockDictionary( - new Map([ - [id, new MockTree(new MockTreeNode(new MockTreeObject(id)))] - ]) - ) - )); + trees.equals(new MockTrees(new MockDictionary(new Map([[id, new MockTree(new MockTreeNode(new MockTreeObject(id)))]])))); expect(spy.mock.calls).toHaveLength(1); }); @@ -113,22 +75,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -152,22 +101,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -193,22 +129,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -232,22 +155,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -272,28 +182,11 @@ describe('Trees', () => { const id1: MockTreeID = new MockTreeID('tree id 1'); const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const ids: Array = [ - id1, - id2, - id3 - ]; - - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const ids: Array = [id1, id2, id3]; + + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -303,10 +196,10 @@ describe('Trees', () => { ]) ); - const trees: MockTrees> = new MockTrees(dictionary); - let i: number = 0; + let i = 0; + // biome-ignore lint/complexity/noForEach: trees.forEach((o: MockTreeObject) => { expect(o.getTreeID()).toBe(ids[i]); i++; @@ -317,17 +210,9 @@ describe('Trees', () => { describe('get', () => { it('delegates its retaining dictionary', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -345,17 +230,9 @@ describe('Trees', () => { describe('isEmpty', () => { it('delegates its retaining dictionary', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -373,17 +250,9 @@ describe('Trees', () => { describe('size', () => { it('delegates its retaining dictionary', () => { const id: MockTreeID = new MockTreeID('tree id'); - const tree: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id) - ) - ); + const tree: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id))); - const dictionary: MockDictionary>> = new MockDictionary( - new Map([ - [id, tree] - ]) - ); + const dictionary: MockDictionary>> = new MockDictionary(new Map([[id, tree]])); const trees: MockTrees> = new MockTrees(dictionary); @@ -404,22 +273,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -443,22 +299,9 @@ describe('Trees', () => { const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -483,28 +326,11 @@ describe('Trees', () => { const id1: MockTreeID = new MockTreeID('tree id 1'); const id2: MockTreeID = new MockTreeID('tree id 2'); const id3: MockTreeID = new MockTreeID('tree id 3'); - const ids: Array = [ - id1, - id2, - id3 - ]; - - const tree1: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id1) - ) - ); + const ids: Array = [id1, id2, id3]; + + const tree1: MockTree> = new MockTree(new MockTreeNode(new MockTreeObject(id1))); const tree2: MockTree> = new MockTree( - new MockTreeNode( - new MockTreeObject(id2), - new MockAddress( - new Set([ - new MockTreeNode( - new MockTreeObject(id3) - ) - ]) - ) - ) + new MockTreeNode(new MockTreeObject(id2), new MockAddress(new Set([new MockTreeNode(new MockTreeObject(id3))]))) ); const dictionary: MockDictionary>> = new MockDictionary( @@ -515,7 +341,7 @@ describe('Trees', () => { ); const trees: MockTrees> = new MockTrees(dictionary); - let i: number = 0; + let i = 0; for (const o of trees.values()) { expect(o.getTreeID()).toBe(ids[i]); diff --git a/src/tree/mock/MockTree.ts b/src/tree/mock/MockTree.ts index eadb6cb..6ad9e9b 100644 --- a/src/tree/mock/MockTree.ts +++ b/src/tree/mock/MockTree.ts @@ -1,15 +1,13 @@ import { ATree } from '../ATree.js'; -import { SerializableTreeObject } from '../SerializableTreeObject.js'; -import { StructurableTreeObject } from '../StructurableTreeObject.js'; -import { TreeID } from '../TreeID.js'; -import { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; +import type { SerializableTreeObject } from '../SerializableTreeObject.js'; +import type { StructurableTreeObject } from '../StructurableTreeObject.js'; +import type { TreeID } from '../TreeID.js'; +import type { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; interface MockTreeObject extends StructurableTreeObject, SerializableTreeObject { // NOOP } export class MockTree> extends ATree> { - public constructor(root: MockTreeNode) { - super(root); - } + // NOOP } diff --git a/src/tree/mock/MockTreeID.ts b/src/tree/mock/MockTreeID.ts index 36791b8..c96efcf 100644 --- a/src/tree/mock/MockTreeID.ts +++ b/src/tree/mock/MockTreeID.ts @@ -1,6 +1,6 @@ import { ValueObject } from '@jamashita/anden/object'; -import { Equatable, Primitive } from '@jamashita/anden/type'; -import { TreeID } from '../TreeID.js'; +import type { Equatable, Primitive } from '@jamashita/anden/type'; +import type { TreeID } from '../TreeID.js'; export class MockTreeID extends ValueObject implements TreeID { private readonly id: string; diff --git a/src/tree/mock/MockTreeObject.ts b/src/tree/mock/MockTreeObject.ts index 53b883f..0bb3617 100644 --- a/src/tree/mock/MockTreeObject.ts +++ b/src/tree/mock/MockTreeObject.ts @@ -1,8 +1,8 @@ import { ValueObject } from '@jamashita/anden/object'; -import { Equatable, ObjectLiteral, Primitive } from '@jamashita/anden/type'; -import { SerializableTreeObject } from '../SerializableTreeObject.js'; -import { StructurableTreeObject } from '../StructurableTreeObject.js'; -import { TreeID } from '../TreeID.js'; +import type { Equatable, ObjectLiteral, Primitive } from '@jamashita/anden/type'; +import type { SerializableTreeObject } from '../SerializableTreeObject.js'; +import type { StructurableTreeObject } from '../StructurableTreeObject.js'; +import type { TreeID } from '../TreeID.js'; export class MockTreeObject extends ValueObject implements StructurableTreeObject, SerializableTreeObject { private readonly id: K; diff --git a/src/tree/mock/MockTrees.ts b/src/tree/mock/MockTrees.ts index 56806a3..2ce72c8 100644 --- a/src/tree/mock/MockTrees.ts +++ b/src/tree/mock/MockTrees.ts @@ -1,11 +1,17 @@ -import { MutableDictionary, ReadonlyDictionary } from '../../dictionary/index.js'; +import { MutableDictionary, type ReadonlyDictionary } from '../../dictionary/index.js'; import { ATrees } from '../ATrees.js'; -import { TreeID } from '../TreeID.js'; -import { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; -import { MockTree } from './MockTree.js'; -import { MockTreeObject } from './MockTreeObject.js'; +import type { TreeID } from '../TreeID.js'; +import type { MockTreeNode } from '../TreeNode/mock/MockTreeNode.js'; +import type { MockTree } from './MockTree.js'; +import type { MockTreeObject } from './MockTreeObject.js'; -export class MockTrees> extends ATrees, MockTree, MutableDictionary>> { +export class MockTrees> extends ATrees< + K, + V, + MockTreeNode, + MockTree, + MutableDictionary> +> { public constructor(trees: ReadonlyDictionary>) { super(MutableDictionary.of(trees)); }