Added HardwareCalibrationReport.cs and Tests. Indent and Split tests

This commit is contained in:
Tyrel Souza 2022-07-26 23:12:24 -04:00
parent f8b773da1c
commit d96091e5c6
4 changed files with 105 additions and 2 deletions

View File

@ -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<int, Transducer> 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)
{
}
}
}

View File

@ -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<Exception>(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"));
}
}
}

View File

@ -1,5 +1,5 @@
namespace BenchtopParserTests {
public class Program_Config_Tests {
public class ProgramConfig_Tests {
public String ProgramConfigValue;
[SetUp]

View File

@ -1,5 +1,5 @@
namespace BenchtopParserTests {
public class Transducer_Verify_Tests {
public class TransducerVerify_Tests {
public String TransducerVerifyValue;
[SetUp]
public void Setup() {