more refactor
This commit is contained in:
parent
92937985f6
commit
e8a49bf831
@ -93,9 +93,9 @@ function parseSection(section, accuracy) {
|
|||||||
// Create an object to store the data for each transducer
|
// Create an object to store the data for each transducer
|
||||||
const transducerInfo = {
|
const transducerInfo = {
|
||||||
Accuracy: accuracy,
|
Accuracy: accuracy,
|
||||||
"Part Number": partNumber,
|
|
||||||
Value: value,
|
Value: value,
|
||||||
Unit: unit,
|
Unit: unit,
|
||||||
|
"Part Number": partNumber,
|
||||||
"Limit ABS": value * accuracy * 1000,
|
"Limit ABS": value * accuracy * 1000,
|
||||||
"Transducer Name": transducerName,
|
"Transducer Name": transducerName,
|
||||||
"Transducer Type": transducerType,
|
"Transducer Type": transducerType,
|
||||||
@ -119,7 +119,7 @@ function parseSection(section, accuracy) {
|
|||||||
return transducerInfo;
|
return transducerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function parseTransducer(content, accuracy) {
|
function parseTransducer(content, accuracy) {
|
||||||
if (!content.includes("Transducer Verify Report")) {
|
if (!content.includes("Transducer Verify Report")) {
|
||||||
throw new Error("Not a Transducer Verify Report")
|
throw new Error("Not a Transducer Verify Report")
|
||||||
}
|
}
|
||||||
@ -138,3 +138,7 @@ export default function parseTransducer(content, accuracy) {
|
|||||||
|
|
||||||
return transducerData;
|
return transducerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function ParseTransducer(content, accuracy) {
|
||||||
|
return parseTransducer(content, accuracy);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
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) {
|
||||||
@ -25,7 +25,7 @@ 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) {
|
||||||
@ -44,7 +44,7 @@ describe("Test for all files", () => {
|
|||||||
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"]) {
|
||||||
@ -61,13 +61,13 @@ describe("Testing actual calculations", () => {
|
|||||||
describe("Testing Errors", () => {
|
describe("Testing Errors", () => {
|
||||||
test("Not a Transducer Verify Report", () => {
|
test("Not a Transducer Verify Report", () => {
|
||||||
const e = () => {
|
const e = () => {
|
||||||
parseTransducer("I am a Fish", 0.05)
|
ParseTransducer("I am a Fish", 0.05)
|
||||||
}
|
}
|
||||||
expect(e).toThrowError(Error("Not a Transducer Verify Report"))
|
expect(e).toThrowError(Error("Not a Transducer Verify Report"))
|
||||||
})
|
})
|
||||||
test("Unknown Unit", () => {
|
test("Unknown Unit", () => {
|
||||||
const e = () => {
|
const e = () => {
|
||||||
parseTransducer(`|| Transducer Verify Report ||\nTRANSDUCER1\n===============================================================\nTransducer 1 CTS D34-442 115FigNewtons`, 0);
|
ParseTransducer(`|| Transducer Verify Report ||\nTRANSDUCER1\n===============================================================\nTransducer 1 CTS D34-442 115FigNewtons`, 0);
|
||||||
}
|
}
|
||||||
expect(e).toThrowError(Error("Unknown Type of Test, do not know unit: FigNewtons"))
|
expect(e).toThrowError(Error("Unknown Type of Test, do not know unit: FigNewtons"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user