From e8a49bf831357c1bd08beed8a585a4d96aab2df2 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Oct 2023 14:23:55 -0400 Subject: [PATCH] more refactor --- benchtop-fe/src/parsers/Transducer.js | 8 ++++++-- .../src/parsers/__tests__/parseTransducer.test.js | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/benchtop-fe/src/parsers/Transducer.js b/benchtop-fe/src/parsers/Transducer.js index 70d439f..66679a9 100644 --- a/benchtop-fe/src/parsers/Transducer.js +++ b/benchtop-fe/src/parsers/Transducer.js @@ -93,9 +93,9 @@ function parseSection(section, accuracy) { // Create an object to store the data for each transducer const transducerInfo = { Accuracy: accuracy, - "Part Number": partNumber, Value: value, Unit: unit, + "Part Number": partNumber, "Limit ABS": value * accuracy * 1000, "Transducer Name": transducerName, "Transducer Type": transducerType, @@ -119,7 +119,7 @@ function parseSection(section, accuracy) { return transducerInfo; } -export default function parseTransducer(content, accuracy) { +function parseTransducer(content, accuracy) { if (!content.includes("Transducer Verify Report")) { throw new Error("Not a Transducer Verify Report") } @@ -137,4 +137,8 @@ export default function parseTransducer(content, accuracy) { } return transducerData; +} + +export default function ParseTransducer(content, accuracy) { + return parseTransducer(content, accuracy); } \ No newline at end of file diff --git a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js index 9b9b049..cf7e73c 100644 --- a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js +++ b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -import parseTransducer from "../Transducer" +import ParseTransducer from "../Transducer" function readFiles(dir) { @@ -25,7 +25,7 @@ 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) + const transducers = ParseTransducer(file.content, 0.05) expect(transducers.length).toBeGreaterThan(0) for (const transducer of transducers) { @@ -44,7 +44,7 @@ describe("Test for all files", () => { 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); + const transducers = ParseTransducer(content, 0.05); for (const transducer of transducers) { let anyOOT = false; for (const gauge of transducer["Gauge Reading"]) { @@ -61,13 +61,13 @@ describe("Testing actual calculations", () => { describe("Testing Errors", () => { test("Not a Transducer Verify Report", () => { 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")) }) test("Unknown Unit", () => { 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"))