/** * @license * Copyright Larry Diamond 2019 All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/larrydiamond/typescriptListsframework/LICENSE */ import {AllFieldCollectable} from "../src/AllFieldCollectable"; import {ArrayList} from "../src/ArrayList"; import {ImmutableList} from "../src/ImmutableList"; import {List} from "../src/List"; import {LinkedList} from "../src/LinkedList"; import {Test, TestBoolean, TestNumber, TestString} from 'jasts'; import {EvictingDeque} from "../src/EvictingDeque"; describe("Test Lists", function() { it("Test empty string Lists", function() { const al:ArrayList = new ArrayList (); const ll:LinkedList = new LinkedList (); const alc:ArrayList = new ArrayList (new AllFieldCollectable()); const llc:LinkedList = new LinkedList (new AllFieldCollectable()); testEmptyStringList(al); testEmptyStringList(ll); testEmptyStringList(alc); testEmptyStringList(llc); testEmptyStringList(new EvictingDeque (1000, new AllFieldCollectable())); }); it("Test empty number Lists", function() { const al:ArrayList = new ArrayList (); const ll:LinkedList = new LinkedList (); const alc:ArrayList = new ArrayList (new AllFieldCollectable()); const llc:LinkedList = new LinkedList (new AllFieldCollectable()); testEmptyNumberList(al); testEmptyNumberList(ll); testEmptyNumberList(alc); testEmptyNumberList(llc); testEmptyNumberList(new EvictingDeque (1000, new AllFieldCollectable())); }); it ("Test JSON.stringify for numbers", function () { testStringifyNumbers (new ArrayList()); testStringifyNumbers (new LinkedList()); testStringifyNumbers (new ArrayList(new AllFieldCollectable())); testStringifyNumbers (new LinkedList(new AllFieldCollectable())); testStringifyNumbers(new EvictingDeque (1000, new AllFieldCollectable())); }); it ("Test JSON.stringify for strings", function () { testStringifyStrings (new ArrayList()); testStringifyStrings (new LinkedList()); testStringifyStrings (new ArrayList(new AllFieldCollectable())); testStringifyStrings (new LinkedList(new AllFieldCollectable())); testStringifyStrings(new EvictingDeque (1000, new AllFieldCollectable())); }); }); function testEmptyStringList (list:ImmutableList) : void { expect (list.isEmpty ()).toEqual(true); expect (list.size ()).toEqual(0); } function testEmptyNumberList (list:ImmutableList) : void { expect (list.isEmpty ()).toEqual(true); expect (list.size ()).toEqual(0); } function testStringifyNumbers (list:List) : void { expect (list.add (100)).toEqual(true); expect (list.add (200)).toEqual(true); expect (list.add (300)).toEqual(true); expect (list.add (400)).toEqual(true); expect (list.add (500)).toEqual(true); expect (list.add (600)).toEqual(true); expect (list.add (700)).toEqual(true); expect (list.add (800)).toEqual(true); expect (list.add (900)).toEqual(true); expect (list.add (1000)).toEqual(true); const tmparray = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]; TestString.equals ("Number list stringify", JSON.stringify (list), JSON.stringify(tmparray)); } function testStringifyStrings (list:List) : void { expect (list.add ("Cat")).toEqual(true); expect (list.add ("Dog")).toEqual(true); expect (list.add ("Bird")).toEqual(true); expect (list.add ("Fish")).toEqual(true); const tmparray = ["Cat", "Dog", "Bird", "Fish"] TestString.equals ("String list stringify", JSON.stringify (list), JSON.stringify(tmparray)); }