UNPKG

@corvina/device-client

Version:
65 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../common/types"); const simulation_1 = require("./simulation"); describe('BaseSimulator', () => { it('should initialize with the correct tag', () => { const simulator = new simulation_1.BaseSimulator('test-tag'); expect(simulator.tag).toBe('test-tag'); }); it('should handle boolean tags', async () => { process.env.SIMULATION_MS = '1'; let readValue = false; const dataSimulator = new simulation_1.DataSimulator('tag1', 'boolean', async (t, v, ts) => { readValue = !!v; return false; }, { type: types_1.SimulationType.CONST, value: true, }); await new Promise((resolve) => setTimeout(resolve, 1000)); expect(readValue).toBe(true); simulation_1.DataSimulator.clear(); }); it('booleans with noise', async () => { process.env.SIMULATION_MS = '1'; let readValue = true; let flipped = 0; const dataSimulator = new simulation_1.DataSimulator('tag1', 'boolean', async (t, v, ts) => { if ((!!v) != readValue) { readValue = !!v; flipped++; } return false; }, { type: types_1.SimulationType.CONST, value: true, noise: { type: types_1.NoiseSimulationType.ABSOLUTE, amplitude: 100, } }); await new Promise((resolve) => setTimeout(resolve, 1000)); expect(flipped).toBeGreaterThan(0); simulation_1.DataSimulator.clear(); }); it('should simulate arrays', async () => { process.env.SIMULATION_MS = '1'; let readValue; const dataSimulator = new simulation_1.DataSimulator('tag1', 'doublearray', async (t, v, ts) => { readValue = v; return false; }, { type: types_1.SimulationType.CONST, value: true, noise: { type: types_1.NoiseSimulationType.ABSOLUTE, amplitude: 100, } }); await new Promise((resolve) => setTimeout(resolve, 1000)); expect(Object.getPrototypeOf(readValue)).toBe(Object.getPrototypeOf([])); simulation_1.DataSimulator.clear(); }); }); //# sourceMappingURL=simulation.test.js.map