update to latest standards

This commit is contained in:
2018-07-15 16:04:27 +02:00
parent b8100f8dfc
commit 2392915959
34 changed files with 1111 additions and 1023 deletions

View File

@ -1,17 +1,17 @@
import { tap, expect } from 'tapbundle'
import { tap, expect } from '@pushrocks/tapbundle';
import { LimitedArray } from '../ts/index'
import { LimitedArray } from '../ts/index';
let testLimitedArray: LimitedArray<string>
let testLimitedArray: LimitedArray<string>;
tap.test('should create a LimitedArray', async () => {
testLimitedArray = new LimitedArray(6)
expect(testLimitedArray).to.be.instanceof(LimitedArray)
})
testLimitedArray = new LimitedArray(6);
expect(testLimitedArray).to.be.instanceof(LimitedArray);
});
tap.test('should never be longer than the set length', async () => {
testLimitedArray.addMany(['hi','this','is','quite','a','long','string',':)'])
expect(testLimitedArray.array.length).to.be.lessThan(7)
})
testLimitedArray.addMany(['hi', 'this', 'is', 'quite', 'a', 'long', 'string', ':)']);
expect(testLimitedArray.array.length).to.be.lessThan(7);
});
tap.start()
tap.start();

View File

@ -1,26 +1,26 @@
// import test framework
import { expect, tap } from 'tapbundle'
import * as events from 'events'
import * as smartq from 'smartq'
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
import * as smartq from 'smartq';
// import the module
import * as lik from '../ts/index'
import * as lik from '../ts/index';
let object1 = {}
let object2 = {}
let myLoopTracker: lik.LoopTracker<any>
let object1 = {};
let object2 = {};
let myLoopTracker: lik.LoopTracker<any>;
// tests
tap.test('should create a valid looptracker instance', async () => {
myLoopTracker = new lik.LoopTracker()
expect(myLoopTracker).to.be.instanceof(lik.LoopTracker)
})
myLoopTracker = new lik.LoopTracker();
expect(myLoopTracker).to.be.instanceof(lik.LoopTracker);
});
tap.test('should add objects once and return true', async () => {
expect(myLoopTracker.checkAndTrack(object1)).to.be.true
expect(myLoopTracker.checkAndTrack(object1)).to.be.false
expect(myLoopTracker.checkAndTrack(object2)).to.be.true
expect(myLoopTracker.checkAndTrack(object2)).to.be.false
})
expect(myLoopTracker.checkAndTrack(object1)).to.be.true;
expect(myLoopTracker.checkAndTrack(object1)).to.be.false;
expect(myLoopTracker.checkAndTrack(object2)).to.be.true;
expect(myLoopTracker.checkAndTrack(object2)).to.be.false;
});
tap.start()
tap.start();

View File

@ -1,76 +1,78 @@
// import test framework
import { expect, tap } from 'tapbundle'
import * as events from 'events'
import * as smartq from 'smartq'
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
import * as smartq from 'smartq';
// import the module
import * as lik from '../ts/index'
import * as lik from '../ts/index';
// Objectmap
interface ITestObject {
propOne: string
propTwo: string
propOne: string;
propTwo: string;
}
let testObjectmap: lik.Objectmap<ITestObject>
let testObjectmap: lik.Objectmap<ITestObject>;
let testObject1: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
};
let testObject2: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
};
tap.test('new lik.Objectmap() -> should correctly instantiate an Objectmap', async () => {
testObjectmap = new lik.Objectmap<ITestObject>()
expect(testObjectmap).be.instanceof(lik.Objectmap)
})
testObjectmap = new lik.Objectmap<ITestObject>();
expect(testObjectmap).be.instanceof(lik.Objectmap);
});
tap.test('lik.Objectmap.add() -> should correctly add an object to Objectmap', async () => {
testObjectmap.add(testObject1)
testObjectmap.add(testObject1);
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.true
expect(testObjectmap.checkForObject(testObject1)).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.false
})
expect(testObjectmap.checkForObject(testObject2)).be.false;
});
tap.test('lik.Objectmap.remove() -> should correctly remove an object to Objectmap', async () => {
testObjectmap.add(testObject2)
testObjectmap.remove(testObject1)
testObjectmap.add(testObject2);
testObjectmap.remove(testObject1);
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.false
expect(testObjectmap.checkForObject(testObject1)).be.false;
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.true
})
expect(testObjectmap.checkForObject(testObject2)).be.true;
});
tap.test('Objectmap.forEach -> should correctly run a function forEach map object', async () => {
testObjectmap.forEach(itemArg => {
expect(itemArg).to.contain('propOne')
})
})
expect(itemArg).to.have.property('propOne');
});
});
tap.test('lik.Objectmap.find() -> should correctly find an object', async () => {
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' }
testObjectmap.add(myObject)
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find(itemArg => {
return itemArg.propOne === 'helloThere';
});
// tslint:disable-next-line:no-unused-expression
expect(myObject === referenceObject).be.true
})
expect(myObject === referenceObject).be.true;
});
tap.test('lik.Objectmap.getArray() -> should return a cloned array', async () => {
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' }
testObjectmap.add(myObject)
let clonedArray = testObjectmap.getArray()
expect(clonedArray[ clonedArray.length - 1 ]).to.equal(myObject)
})
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' };
testObjectmap.add(myObject);
let clonedArray = testObjectmap.getArray();
expect(clonedArray[clonedArray.length - 1]).to.eql(myObject);
});
tap.test('should get one object and then remove it', async () => {
let originalLength = testObjectmap.getArray().length
let oneObject = testObjectmap.getOneAndRemove()
let originalLength = testObjectmap.getArray().length;
let oneObject = testObjectmap.getOneAndRemove();
// tslint:disable-next-line:no-unused-expression
expect(oneObject).not.be.null
expect(testObjectmap.getArray().length).equal(originalLength - 1)
expect(testObjectmap.getArray()).to.not.contain(oneObject)
})
expect(oneObject).not.be.null;
expect(testObjectmap.getArray().length).equal(originalLength - 1);
expect(testObjectmap.getArray()).to.not.contain(oneObject);
});
tap.start()
tap.start();

View File

@ -1,78 +1,88 @@
// import test framework
import { expect, tap } from 'tapbundle'
import * as events from 'events'
import * as smartq from 'smartq'
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
import * as smartq from 'smartq';
// import the module
import * as lik from '../ts/index'
import * as lik from '../ts/index';
// testData
let testStringmap: lik.Stringmap
let testString1 = 'testString1'
let testString2 = 'testString2'
let testString3 = 'testString3'
let testString4 = 'testString4'
let testString5 = 'testString5'
let testString6 = 'testString6'
let testStringmap: lik.Stringmap;
let testString1 = 'testString1';
let testString2 = 'testString2';
let testString3 = 'testString3';
let testString4 = 'testString4';
let testString5 = 'testString5';
let testString6 = 'testString6';
// tests
tap.test('new lik.Objectmap() -> should create an instance of Stringmap', async () => {
testStringmap = new lik.Stringmap()
expect(testStringmap).be.instanceof(lik.Stringmap)
})
testStringmap = new lik.Stringmap();
expect(testStringmap).be.instanceof(lik.Stringmap);
});
tap.test('lik.Stringmap.checkString -> should return false for an string not in Stringmap', async () => {
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString1)).be.false
})
tap.test(
'lik.Stringmap.checkString -> should return false for an string not in Stringmap',
async () => {
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString1)).be.false;
}
);
tap.test('lik.Stringmap.addString -> should add an string to Stringmap', async () => {
testStringmap.addString(testString1)
testStringmap.addString(testString2)
testStringmap.addString(testString3)
testStringmap.addString(testString1);
testStringmap.addString(testString2);
testStringmap.addString(testString3);
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString1)).be.true
expect(testStringmap.checkString(testString1)).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString2)).be.true
expect(testStringmap.checkString(testString2)).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString3)).be.true
expect(testStringmap.checkString(testString3)).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String1')).be.true
expect(testStringmap.checkMinimatch('*String1')).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String2')).be.true
expect(testStringmap.checkMinimatch('*String2')).be.true;
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String4')).be.false
})
expect(testStringmap.checkMinimatch('*String4')).be.false;
});
tap.test('lik.Stringmap.addStringArray -> should add an array of strings', async () => {
testStringmap.addStringArray([ testString4, testString5, testString6 ])
testStringmap.addStringArray([testString4, testString5, testString6]);
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String4')).be.true
})
expect(testStringmap.checkMinimatch('*String4')).be.true;
});
tap.test('lik.Stringmap.removeString -> should remove a string from Stringmap', async () => {
testStringmap.removeString(testString2)
testStringmap.removeString(testString2);
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString2)).be.false
})
expect(testStringmap.checkString(testString2)).be.false;
});
tap.test('lik.Stringmap.getStringArray() -> should return a copy of stringArray', async () => {
let clonedArray = testStringmap.getStringArray()
let clonedArray = testStringmap.getStringArray();
// tslint:disable-next-line:no-unused-expression
expect(clonedArray[ 0 ] === 'testString1').be.true
expect(clonedArray[0] === 'testString1').be.true;
// tslint:disable-next-line:no-unused-expression
expect(clonedArray[ 0 ] === testString1).be.true
})
expect(clonedArray[0] === testString1).be.true;
});
tap.test('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty', async () => {
testStringmap.registerUntilTrue(
() => { return testStringmap.checkIsEmpty() },
() => { console.log('Stringmap now is empty') }
)
})
tap.test(
'lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',
async () => {
testStringmap.registerUntilTrue(
() => {
return testStringmap.checkIsEmpty();
},
() => {
console.log('Stringmap now is empty');
}
);
}
);
tap.test('lik.Stringmap.empty() -> should remove wipe and then notify', async () => {
testStringmap.wipe()
})
testStringmap.wipe();
});
tap.start()
tap.start();

View File

@ -1,24 +1,24 @@
import { tap, expect } from 'tapbundle'
import * as lik from '../ts/index'
import { tap, expect } from '@pushrocks/tapbundle';
import * as lik from '../ts/index';
let testTree = new lik.Tree<TestClass>()
let testTree = new lik.Tree<TestClass>();
class TestClass {
constructor (public hey: string) {
constructor(public hey: string) {
// nothing here
}
}
let testInstance = new TestClass('first')
let testInstance = new TestClass('first');
tap.test('create a valid tree instance', async () => {
testTree = new lik.Tree()
expect(testTree).to.be.instanceOf(lik.Tree)
})
testTree = new lik.Tree();
expect(testTree).to.be.instanceOf(lik.Tree);
});
tap.test('should insert an object', async () => {
testTree.initialize(testInstance)
let resultArray = testTree.treeToArray(testInstance, {})
expect(resultArray).to.contain(testInstance)
})
testTree.initialize(testInstance);
let resultArray = testTree.treeToArray(testInstance, {});
expect(resultArray).to.contain(testInstance);
});
tap.start()
tap.start();

1
test/test.ts Normal file
View File

@ -0,0 +1 @@
import './test.objectmap';