From d96091e5c631a5e855005ee965adb8c70fb69a90 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 26 Jul 2022 23:12:24 -0400 Subject: [PATCH] Added HardwareCalibrationReport.cs and Tests. Indent and Split tests --- BenchtopParser/HardwareCalibrationReport.cs | 39 +++++++++++ .../HardwareCalibrationReport_Tests.cs | 64 +++++++++++++++++++ ...Config_Tests.cs => ProgramConfig_Tests.cs} | 2 +- ...ify_Tests.cs => TransducerVerify_Tests.cs} | 2 +- 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 BenchtopParser/HardwareCalibrationReport.cs create mode 100644 BenchtopParserTests/HardwareCalibrationReport_Tests.cs rename BenchtopParserTests/{Program_Config_Tests.cs => ProgramConfig_Tests.cs} (98%) rename BenchtopParserTests/{Transducer_Verify_Tests.cs => TransducerVerify_Tests.cs} (97%) diff --git a/BenchtopParser/HardwareCalibrationReport.cs b/BenchtopParser/HardwareCalibrationReport.cs new file mode 100644 index 0000000..1c1e3b0 --- /dev/null +++ b/BenchtopParser/HardwareCalibrationReport.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BenchtopParser { + public class HardwareCalibrationReport { + public Dictionary Transducers = new(); + public int Indent = 45; // Default 26 from seeing files, overridden later in SetIndent for safety + + /// Split the string, and clean up whitespace, returns the Name and Value + public string[] SplitLine(string line) { + return new[] { + line[..Indent].Trim(), + line[(Indent)..] + }; + } + public void SetIndent(string line) { + const int endOfCurrentTransducerKey = 10; // "Transducer".Length calculation + + int leadingSpaces = line.TakeWhile(c => c == ' ').Count(); + string restOfLine = line[(leadingSpaces + endOfCurrentTransducerKey)..]; + int additionalSpaces = restOfLine.TakeWhile(c => c == ' ').Count(); + Indent = leadingSpaces + endOfCurrentTransducerKey + additionalSpaces; + string endOfLine = line[Indent..]; + Console.Write(endOfLine); + } + + public HardwareCalibrationReport() + { + + } + public HardwareCalibrationReport(string fileText) + { + + } + } +} diff --git a/BenchtopParserTests/HardwareCalibrationReport_Tests.cs b/BenchtopParserTests/HardwareCalibrationReport_Tests.cs new file mode 100644 index 0000000..5f1b04e --- /dev/null +++ b/BenchtopParserTests/HardwareCalibrationReport_Tests.cs @@ -0,0 +1,64 @@ +namespace BenchtopParserTests { + public class HardwareCalibrationReport_Tests { + public String HardwareCalibrationReportValue; + [SetUp] + public void Setup() { + HardwareCalibrationReportValue = File.ReadAllText( + Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Hardware Calibration Report.txt") + ); + } + + [Test] + public void Test_HardwareCalibrationReport() { + BenchtopParser.HardwareCalibrationReport tv = new(HardwareCalibrationReportValue); + Assert.That(tv.Transducers[1].Id, Is.EqualTo(1)); + Assert.That(tv.Transducers[1].Name, Is.EqualTo("CTS D34-442 115PSIA")); + } + + [Test] + public void Test_HardwareCalibrationReport_Throw_InvalidProgram() { + Exception ex = Assert.Throws(delegate { new BenchtopParser.HardwareCalibrationReport("broken"); }); + Assert.That(ex.Message, Is.EqualTo("Invalid Transducer Verify Report, please provide a Transducer Verify Report file data")); + } + + [Test] + public void Test_HardwareCalibrationReport_SetIndent() { + BenchtopParser.HardwareCalibrationReport tv = new(); + tv.SetIndent(" Transducer Custom"); + Assert.That(tv.Indent, Is.EqualTo(45)); + + tv.SetIndent(" Transducer Custom"); + Assert.That(tv.Indent, Is.EqualTo(41)); + + tv.SetIndent(" TransducerCustom"); + Assert.That(tv.Indent, Is.EqualTo(12)); + } + + [Test] + public void Test_HardwareCalibrationReport_SplitLine() { + BenchtopParser.HardwareCalibrationReport tv = new(); + string[] split; + + string context = " Transducer Custom"; + tv.SetIndent(context); + split = tv.SplitLine(context); + Assert.That(tv.Indent, Is.EqualTo(45)); + Assert.That(split[0], Is.EqualTo("Transducer")); + Assert.That(split[1], Is.EqualTo("Custom")); + + context = " Transducer Custom"; + tv.SetIndent(context); + split = tv.SplitLine(context); + Assert.That(tv.Indent, Is.EqualTo(41)); + Assert.That(split[0], Is.EqualTo("Transducer")); + Assert.That(split[1], Is.EqualTo("Custom")); + + context = " TransducerCustom"; + tv.SetIndent(context); + split = tv.SplitLine(context); + Assert.That(tv.Indent, Is.EqualTo(12)); + Assert.That(split[0], Is.EqualTo("Transducer")); + Assert.That(split[1], Is.EqualTo("Custom")); + } + } +} \ No newline at end of file diff --git a/BenchtopParserTests/Program_Config_Tests.cs b/BenchtopParserTests/ProgramConfig_Tests.cs similarity index 98% rename from BenchtopParserTests/Program_Config_Tests.cs rename to BenchtopParserTests/ProgramConfig_Tests.cs index 4dfed12..59c5580 100644 --- a/BenchtopParserTests/Program_Config_Tests.cs +++ b/BenchtopParserTests/ProgramConfig_Tests.cs @@ -1,5 +1,5 @@ namespace BenchtopParserTests { - public class Program_Config_Tests { + public class ProgramConfig_Tests { public String ProgramConfigValue; [SetUp] diff --git a/BenchtopParserTests/Transducer_Verify_Tests.cs b/BenchtopParserTests/TransducerVerify_Tests.cs similarity index 97% rename from BenchtopParserTests/Transducer_Verify_Tests.cs rename to BenchtopParserTests/TransducerVerify_Tests.cs index ec20a95..9170e4e 100644 --- a/BenchtopParserTests/Transducer_Verify_Tests.cs +++ b/BenchtopParserTests/TransducerVerify_Tests.cs @@ -1,5 +1,5 @@ namespace BenchtopParserTests { - public class Transducer_Verify_Tests { + public class TransducerVerify_Tests { public String TransducerVerifyValue; [SetUp] public void Setup() {