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