Cypress.Commands.add('isNotInViewport', element => { cy.get(element).then($el => { // we won't have horizontal scollbar const rect = $el[0].getBoundingClientRect(); if (rect.top < 0) { expect(rect.bottom).to.be.lessThan(0); } else { expect(rect.top).to.be.at.least(0); } }); });
it('predict', () => { const recognizer = createFaceRecognizer() const trainFaces = loadTrainFaces() recognizer.addFaces(trainFaces.sheldon, 'sheldon') recognizer.addFaces(trainFaces.raj, 'raj') const testFaces = loadTestFaces() function getPrediction(predictions, className) { const prediction = predictions.find(p => p.className === className) expect(prediction).to.not.be.undefined return prediction } const p1 = recognizer.predict(testFaces.sheldon) expect(p1).to.be.an('array').lengthOf(2) expect(p1.map(p => p.className)).to.contain('sheldon') expect(p1.map(p => p.className)).to.contain('raj') expect(getPrediction(p1, 'sheldon').distance).to.be.lessThan(getPrediction(p1, 'raj').distance) const p2 = recognizer.predict(testFaces.raj) expect(p2).to.be.an('array').lengthOf(2) expect(p2.map(p => p.className)).to.contain('sheldon') expect(p2.map(p => p.className)).to.contain('raj') expect(getPrediction(p2, 'raj').distance).to.be.lessThan(getPrediction(p2, 'sheldon').distance) })
describe('LogLevel', () => { it('log levels should be sorted', () => { LogLevel.OFF.should.be.lessThan(LogLevel.TRACE); LogLevel.TRACE.should.be.lessThan(LogLevel.DEBUG); LogLevel.DEBUG.should.be.lessThan(LogLevel.INFO); LogLevel.INFO.should.be.lessThan(LogLevel.WARN); LogLevel.WARN.should.be.lessThan(LogLevel.ERROR); LogLevel.ERROR.should.be.lessThan(LogLevel.CRITICAL); }); });
describe('Object with primitives serialization/deserialization', function() { let serializedTestObject, deserializedTestObject; it('Serialize object', function () { serializedTestObject = testObject.serialize(serializer); }); it('Deserialize object', function () { deserializedTestObject = serializer.deserialize(serializedTestObject.dataBuffer); deserializedTestObject.byteOffset.should.equal(1 + 4 + 4 + 2 + 1 + 1); //float precision is capped (deserializedTestObject.obj.float32 - testObject.float32).should.be.lessThan(0.00000001); deserializedTestObject.obj.int32.should.be.equal(testObject.int32); deserializedTestObject.obj.int16.should.be.equal(testObject.int16); deserializedTestObject.obj.int8.should.be.equal(testObject.int8); deserializedTestObject.obj.uint8.should.be.equal(testObject.uint8); }); });
it('should be able to set negative drift', function () { simulator = new OpenBCISimulator(portName, { drift: -1 }); expect(simulator.options.drift).to.be.lessThan(0); });
it('removes expired values on attempted retrieval', async () => { const store = new MemoryStore(); await store.set('key', 'value', { ttl: 10 }); const spy = sinon.spy(store._store, 'delete'); expect(await store.get('key')).to.equal('value'); const item = store._store.get('key'); expect(item.expiration).to.be.greaterThan(Date.now()); clock.tick(20); expect(item.expiration).to.be.lessThan(Date.now()); expect(await store.get('key')).to.be.undefined; expect(spy.calledOnceWith('key')).to.be.true; });
it('if expirationPoll option is provided, removes expired values even when not retrieved', async () => { const store = new MemoryStore({ expirationPoll: 5 }); expect(store._interval).to.be.ok; const spy = sinon.spy(store._store, 'delete'); await store.set('key', 'value', { ttl: 10 }); expect(await store.get('key')).to.equal('value'); const item = store._store.get('key'); expect(item.expiration).to.be.greaterThan(Date.now()); clock.tick(20); expect(item.expiration).to.be.lessThan(Date.now()); expect(store._store.size).to.equal(0); expect(spy.calledOnceWith('key')).to.be.true; });
it('does not expire values in the background, by default', async () => { const store = new MemoryStore(); expect(store._interval).to.be.undefined; await store.set('key', 'value', { ttl: 10 }); expect(await store.get('key')).to.equal('value'); const item = store._store.get('key'); expect(item.expiration).to.be.greaterThan(Date.now()); clock.tick(20); expect(item.expiration).to.be.lessThan(Date.now()); expect(store._store.size).to.equal(1); });
l('w', 'test', 'four') await $sleep(0) expect(fs.readdirSync(d.name).length).lessThan(4) })
expect(oneSecondAgo).to.be.lessThan(now); expect(now).to.not.be.below(oneSecondAgo); expect(oneSecondAfter).to.not.be.below(oneSecondAgo);
}); simulator.once('data', function (buffer) { expect(buffer.length).to.be.lessThan(bufferSize); done(); });
it('should be able to make the internal clock of the simulator run slow', () => { let ourBoard1 = new Cyton({ simulatorInternalClockDrift: -1 }); expect(ourBoard1.options.simulatorInternalClockDrift).to.be.lessThan(0); // Verify multi case support let ourBoard2 = new Cyton({ simulatorinternalclockdrift: -1 }); expect(ourBoard2.options.simulatorInternalClockDrift).to.be.lessThan(0); });