Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
johntalton committed Jun 13, 2023
1 parent 7d1bc87 commit 76d515c
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "tsc",
"build:watch": "tsc --watch",
"coverage": "npm --silent run coverage:c8",
"coverage:c8": "c8 --check-coverage --reporter lcov --all --lines 75 --functions 5 --branches 85 npm --silent run test:mocha -- --no-parallel --reporter min"
"coverage:c8": "c8 --check-coverage --reporter text --reporter lcov --all --lines 70 --functions 5 --branches 70 npm --silent run test:mocha -- --no-parallel --reporter min"
},
"eslintConfig": {
"extends": [
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './defs.js'
export * from './tcs34725.js'
export * from './common.js'
export * from './converter.js'
170 changes: 170 additions & 0 deletions test/common.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { I2CScriptBus, I2CAddressedBus } from '@johntalton/and-other-delights'
import { Common } from '@johntalton/tcs34725'

import { describe, it } from 'mocha'
import { expect } from 'chai'

const bus = (script) => {
const b = new I2CScriptBus(script)
const ab = new I2CAddressedBus(b, 0x00)
return ab
}

describe('Common', () => {
describe('getId', () => {
it('gets id', async () => {
const id = await Common.getId(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([42]) } }
]))
expect(id).to.equal(42)
})

describe('getnEnable', () => {
it('gets enabled', async () => {
const id = await Common.getEnable(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([0b11011]) } }
]))
expect(id).to.deep.equal({
powerOn: true,
active: true,
interrupts: true,
wait: true
})
})
})

describe('getWaitTiming', () => {
it('gets wait timing', async () => {
const id = await Common.getWaitTiming(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([0]) } }
]))
expect(id).to.deep.equal({
wtime: 0,
count: 256
})
})
})

describe('getIntegrationTiming', () => {
it('gets integration timing', async () => {
const id = await Common.getIntegrationTiming(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([0]) } }
]))
expect(id).to.deep.equal({
_atime: 0,
integrationCycles: 256,
integrationMaxCount: 262144,
integrationTimeMs: 614.4
})
})
})

describe('getThreshold', () => {
it('gets threshold', async () => {
const id = await Common.getThreshold(bus([
{ method: 'readI2cBlock', result: { bytesRead: 4, buffer: Uint16Array.from([ 0, 0 ]) } }
]))
expect(id).to.deep.equal({
high: 0,
low: 0
})
})
})

describe('getPersistence', () => {
it('gets persistence', async () => {
const id = await Common.getPersistence(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([ 0 ]) } }
]))
expect(id).to.deep.equal({
apres: 0
})
})
})

describe('getConfig', () => {
it('gets config', async () => {
const id = await Common.getConfig(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([ 0 ]) } }
]))
expect(id).to.deep.equal({
wlong: false
})
})
})

describe('getControl', () => {
it('gets control', async () => {
const id = await Common.getControl(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([ 0 ]) } }
]))
expect(id).to.deep.equal({
again: 0
})
})
})

describe('getStatus', () => {
it('gets status', async () => {
const id = await Common.getStatus(bus([
{ method: 'readI2cBlock', result: { bytesRead: 1, buffer: Uint8Array.from([ 0 ]) } }
]))
expect(id).to.deep.equal({
valid: false,
thresholdViolation: false
})
})
})

describe('getData', () => {
it('gets data', async () => {
const id = await Common.getData(bus([
{ method: 'readI2cBlock', result: { bytesRead: 8, buffer: Uint16Array.from([
0, 0, 0, 0
]) } }
]))
expect(id).to.deep.equal({
raw: { r: 0, g: 0, b: 0, c: 0 },
ratio: { r: 0, g: 0, b: 0, c: 0 },
rgb: { r: 0, g: 0, b: 0, zero: true },
temperatureK: Number.NaN,
lux: 0
})
})
})

describe('getProfile', () => {
it('gets profile', async () => {
const id = await Common.getProfile(bus([
{ method: 'readI2cBlock', result: { bytesRead: 20, buffer: Uint8Array.from([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]) } }
]))
expect(id).to.deep.equal({
powerOn: false,
active: false,
interrupts: false,
_atime: 0,
wait: false,
integrationCycles: 256,
integrationMaxCount: 262144,
integrationTimeMs: 614.4,
threshold: {
high: 0,
low: 0
},
gain: 0,
filtering: true,
valid: false,
thresholdViolation: false,
_wlong: false,
count: 256,
waitTimeMs: 614.4,
wtime: 0
})
})
})

})
})
27 changes: 27 additions & 0 deletions test/defs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { makeCommand } from '@johntalton/tcs34725'

import { describe, it } from 'mocha'
import { expect } from 'chai'

describe('Defs', () => {
describe('makeCommand', () => {
it('undefined', () => {
expect(() => makeCommand()).to.throw()
})

it('empty not command', () => {
const cmd = makeCommand(0, 0, false)
expect(cmd).to.equal(0)
})

it('empty command', () => {
const cmd = makeCommand(0, 0, true)
expect(cmd).to.equal(128)
})

it('command', () => {
const cmd = makeCommand(1, 0, true)
expect(cmd).to.equal(129)
})
})
})

0 comments on commit 76d515c

Please sign in to comment.