UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

96 lines 4.24 kB
// SPDX-License-Identifier: Apache-2.0 import { expect } from 'chai'; import { MutableFacadeArray } from '../../../../../src/business/runtime-state/collection/mutable-facade-array.js'; import { StringFacade } from '../../../../../src/business/runtime-state/facade/string-facade.js'; describe('MutableFacadeArray', () => { let myArray; // returns a StringConstructor beforeEach(() => { myArray = new MutableFacadeArray(StringFacade, ((stringValue) => stringValue), []); }); it('should add a new element', () => { const stringFacade = new StringFacade('test'); myArray.add(stringFacade); expect(myArray.length).to.equal(1); expect(myArray.get(0)).to.equal(stringFacade); }); it('should addAll elements', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.addAll(stringFacade1, stringFacade2); expect(myArray.length).to.equal(2); expect(myArray.get(0)).to.equal(stringFacade1); expect(myArray.get(1)).to.equal(stringFacade2); }); it('set should update an element', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.add(stringFacade1); myArray.set(0, stringFacade2); expect(myArray.get(0)).to.equal(stringFacade2); }); it('indexOf should return the index of an element', () => { const stringFacade = new StringFacade('test'); myArray.add(stringFacade); const index = myArray.indexOf(stringFacade); expect(index).to.equal(0); }); it('some should return true if at least one element matches the predicate', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.add(stringFacade1); myArray.add(stringFacade2); const result = myArray.some((value) => value.toString() === 'test1'); expect(result).to.be.true; }); it('filter should return elements matching the predicate', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); const stringFacade3 = new StringFacade('other'); myArray.add(stringFacade1); myArray.add(stringFacade2); myArray.add(stringFacade3); const result = myArray.filter((value) => value.toString().startsWith('test')); expect(result).to.deep.equal([stringFacade1, stringFacade2]); }); it('map should return an array of mapped values', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.add(stringFacade1); myArray.add(stringFacade2); const result = myArray.map((value) => value.toString()); expect(result).to.deep.equal(['test1', 'test2']); }); it('remove should remove an element', () => { const stringFacade = new StringFacade('test'); myArray.add(stringFacade); myArray.remove(stringFacade); expect(myArray.length).to.equal(0); }); it('includes should return true if the element is in the array', () => { const stringFacade = new StringFacade('test'); myArray.add(stringFacade); const result = myArray.includes(stringFacade); expect(result).to.be.true; }); it('clear should remove all elements', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.add(stringFacade1); myArray.add(stringFacade2); myArray.clear(); expect(myArray.length).to.equal(0); }); it('should iterate over elements', () => { const stringFacade1 = new StringFacade('test1'); const stringFacade2 = new StringFacade('test2'); myArray.add(stringFacade1); myArray.add(stringFacade2); const result = []; for (const element of myArray) { result.push(element); } expect(result).to.deep.equal([stringFacade1, stringFacade2]); }); }); //# sourceMappingURL=mutable-facade-array.test.js.map