This commit is contained in:
Tyrel Souza 2023-10-20 11:52:00 -04:00
parent 9cd2c8c29d
commit 61b2958b8b
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E

View File

@ -1,61 +1,59 @@
import {tr} from "date-fns/locale";
const fs = require('fs');
const path = require('path');
import parseTransducer from "../Transducer"
function readFiles(dir) {
const files = [];
const files = [];
fs.readdirSync(dir).forEach(filename => {
const name = path.parse(filename).name;
const ext = path.parse(filename).ext;
const filepath = path.resolve(dir, filename);
const stat = fs.statSync(filepath);
const isFile = stat.isFile();
fs.readdirSync(dir).forEach(filename => {
const name = path.parse(filename).name;
const ext = path.parse(filename).ext;
const filepath = path.resolve(dir, filename);
const stat = fs.statSync(filepath);
const isFile = stat.isFile();
if (isFile) {
const content = fs.readFileSync(filepath, 'utf8');
files.push({ filepath, name, ext, stat, content });
}
});
return files;
if (isFile) {
const content = fs.readFileSync(filepath, 'utf8');
files.push({filepath, name, ext, stat, content});
}
});
return files;
}
describe("Test for all files", () => {
let files = readFiles("src/parsers/__tests__/transducer_verify/");
for (const file of files) {
test(`Can parse ${file.name}`, () => {
const transducers = parseTransducer(file.content, 0.05)
let files = readFiles("src/parsers/__tests__/transducer_verify/");
for (const file of files) {
test(`Can parse ${file.name}`, () => {
const transducers = parseTransducer(file.content, 0.05)
expect(transducers.length).toBeGreaterThan(0)
for (const transducer of transducers) {
expect(transducer).toHaveProperty("Part Number")
expect(transducer).toHaveProperty("Transducer Name")
expect(transducer).toHaveProperty("Gauge Reading")
expect(transducer).toHaveProperty("Master Value")
expect(transducers.length).toBeGreaterThan(0)
for (const transducer of transducers) {
expect(transducer).toHaveProperty("Part Number")
expect(transducer).toHaveProperty("Transducer Name")
expect(transducer).toHaveProperty("Gauge Reading")
expect(transducer).toHaveProperty("Master Value")
expect(transducer["Gauge Reading"].length).toBeGreaterThan(1);
expect(transducer["Master Value"].length).toBe(transducer["Gauge Reading"].length);
}
});
}
expect(transducer["Gauge Reading"].length).toBeGreaterThan(1);
expect(transducer["Master Value"].length).toBe(transducer["Gauge Reading"].length);
}
});
}
});
describe("Testing actual calculations", () => {
test("It can detect if out of tolerance", () => {
const content = fs.readFileSync("src/parsers/__tests__/transducer_verify/Blackbelt with flow 220601_143736 Transducer Verify.txt", 'utf8');
const transducers = parseTransducer(content, 0.05);
for (const transducer of transducers) {
let anyOOT = false;
for (const gauge of transducer["Gauge Reading"]) {
if (!gauge["In Range"]) {
anyOOT = true;
expect(gauge["Out Of Tolerance"]).toBeGreaterThan(0)
test("It can detect if out of tolerance", () => {
const content = fs.readFileSync("src/parsers/__tests__/transducer_verify/Blackbelt with flow 220601_143736 Transducer Verify.txt", 'utf8');
const transducers = parseTransducer(content, 0.05);
for (const transducer of transducers) {
let anyOOT = false;
for (const gauge of transducer["Gauge Reading"]) {
if (!gauge["In Range"]) {
anyOOT = true;
expect(gauge["Out Of Tolerance"]).toBeGreaterThan(0)
}
}
expect(anyOOT).toBeTruthy();
}
}
expect(anyOOT).toBeTruthy();
}
})
})
});