Newer
Older
import { detectTemperatureShift } from '../lib/sensiplan'
describe.only('sensiplan', () => {
describe('detect temperature shift', () => {
describe('regular rule', () => {
it('reports lower temperature status before shift', function () {
const lowerTemps = [36.7, 36.57, 36.47, 36.49, 36.57]
const status = detectTemperatureShift(lowerTemps)
expect(status).to.eql({ detected: false })
})
it('detects temperature shift correctly', function () {
const tempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift)
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
detected: true,
rules: { regular: true }
it('detects no temperature shift when there are no 6 low temps', function () {
const tempShift = [36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift)
expect(status).to.eql({ detected: false })
})
it('detects no temperature shift if the shift is not high enough', function () {
const tempShift = [36.57, 36.7, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.8]
const status = detectTemperatureShift(tempShift)
expect(status).to.eql({ detected: false })
it('detects missing temperature shift correctly', function () {
const noTempShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
const status = detectTemperatureShift(noTempShift)
expect(status).to.eql({ detected: false })
it('detects shift after an earlier one was invalid', function () {
const temps = [36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4, 36.7, 36.8, 36.9]
const status = detectTemperatureShift(temps)
expect(status).to.eql({
low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4],
ltl: 36.6,
high: [36.7, 36.8, 36.9],
detected: true,
rules: { regular: true }
})
})
it('detects 2 consecutive invalid shifts', function () {
const temps = [36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4, 36.6, 36.6, 36.7]
const status = detectTemperatureShift(temps)
expect(status).to.eql({ detected: false })
})
describe('1st exception rule', () => {
it('detects temperature shift', function () {
const firstException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.63]
const status = detectTemperatureShift(firstException)
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
detected: true,
rules: { firstException: true }
it('detects missing temperature shift correctly', function () {
const firstExceptionNoShift = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77, 36.57]
const status = detectTemperatureShift(firstExceptionNoShift)
expect(status).to.eql({ detected: false })
it('detects missing temperature shift with not enough high temps', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.77]
const status = detectTemperatureShift(temps)
expect(status).to.eql({ detected: false })
})
it('detects shift after an earlier one was invalid', function () {
const temps = [36.4, 36.4, 36.4, 36.4, 36.4, 36.4, 36.6, 36.6, 36.4, 36.4, 36.7, 36.7, 36.7, 36.7]
const status = detectTemperatureShift(temps)
expect(status).to.eql({
low: [36.4, 36.4, 36.6, 36.6, 36.4, 36.4],
ltl: 36.6,
high: [36.7, 36.7, 36.7, 36.7],
detected: true,
rules: { firstException: true }
})
})
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
describe('2nd exception rule', () => {
it('detects temperature shift with exception temp eql ltl', function () {
const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.6, 36.8]
const status = detectTemperatureShift(secondException)
expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.6, 36.8],
detected: true,
rules: { secondException: true }
})
})
it('detects temperature shift with exception temp lower than ltl', function () {
const secondException = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4, 36.8]
const status = detectTemperatureShift(secondException)
expect(status).to.eql({
low: [36.55, 36.45, 36.5, 36.55, 36.6, 36.55],
ltl: 36.6,
high: [36.8, 36.85, 36.4, 36.8],
detected: true,
rules: { secondException: true }
})
})
it('detects missing temperature shift correctly', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4, 36.77, 36.77]
const status = detectTemperatureShift(temps)
expect(status).to.eql({ detected: false })
})
it('detects missing temperature shift when not enough high temps', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4]
const status = detectTemperatureShift(temps)
expect(status).to.eql({ detected: false })
})
it('detects shift after an earlier one was invalid', function () {
const temps = [36.7, 36.57, 36.47, 36.49, 36.57, 36.62, 36.55, 36.8, 36.86, 36.4, 36.77, 36.9, 36.9, 36.86, 37.04]
const status = detectTemperatureShift(temps)
expect(status).to.eql({
low: [36.6, 36.55, 36.8, 36.85, 36.4, 36.75],
ltl: 36.85,
high: [36.9, 36.9, 36.85, 37.05],
detected: true,
rules: { secondException: true }
})
})
})