new split line, split line tests, indent tests, separators, instrument struct, Setinstrument test
This commit is contained in:
parent
d96091e5c6
commit
ad278e13c9
@ -5,8 +5,9 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BenchtopParser {
|
||||
public class HardwareCalibrationReport {
|
||||
public Dictionary<int, Transducer> Transducers = new();
|
||||
public class HardwareCalibrationReport
|
||||
{
|
||||
public InstrumentInfo Instrument;
|
||||
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
|
||||
@ -16,6 +17,12 @@ namespace BenchtopParser {
|
||||
line[(Indent)..]
|
||||
};
|
||||
}
|
||||
public string[] SplitLine(int indent, string line) {
|
||||
return new[] {
|
||||
line[..indent].Trim(),
|
||||
line[(indent)..]
|
||||
};
|
||||
}
|
||||
public void SetIndent(string line) {
|
||||
const int endOfCurrentTransducerKey = 10; // "Transducer".Length calculation
|
||||
|
||||
@ -29,11 +36,52 @@ namespace BenchtopParser {
|
||||
|
||||
public HardwareCalibrationReport()
|
||||
{
|
||||
|
||||
Instrument = new InstrumentInfo("UNSET", "DATA", "12:00:00", "12/31/1969");
|
||||
}
|
||||
public HardwareCalibrationReport(string fileText)
|
||||
{
|
||||
const string l0Separator = "===============================================================";
|
||||
const string l1Separator = "===========================================================";
|
||||
|
||||
List<string> documentLines = fileText.Split(new string[] { Environment.NewLine }, StringSplitOptions.TrimEntries).ToList();
|
||||
SetInstrumentInfo(documentLines);
|
||||
if (documentLines[0] != "|| Hardware Calibration Report ||")
|
||||
{
|
||||
throw new Exception("Invalid Hardware Calibration Report, please provide a Hardware Calibration Report file data");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInstrumentInfo(List<string> documentLines)
|
||||
{
|
||||
if (documentLines[0] != "|| Instrument Info ||")
|
||||
{
|
||||
throw new Exception(
|
||||
"Invalid Hardware Calibration Report, please provide a Hardware Calibration Report file data");
|
||||
}
|
||||
|
||||
string instrumentName = SplitLine(39, documentLines[2])[1];
|
||||
string serialNumber = SplitLine(39, documentLines[3])[1];
|
||||
string time = SplitLine(39, documentLines[4])[1];
|
||||
string date = SplitLine(39, documentLines[5])[1];
|
||||
Instrument = new(instrumentName, serialNumber, time, date);
|
||||
for (int i = 0; i <= 7; i++)
|
||||
{
|
||||
documentLines.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct InstrumentInfo
|
||||
{
|
||||
public InstrumentInfo(string name, string serialNumber, string time, string date)
|
||||
{
|
||||
Name = name;
|
||||
SerialNumber = serialNumber;
|
||||
Time = Convert.ToDateTime($"{date} {time}");
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string SerialNumber { get; }
|
||||
public DateTime Time { get; }
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,10 @@ namespace BenchtopParser {
|
||||
|
||||
public class ProgramConfig {
|
||||
public Dictionary<String, Program> Programs = new();
|
||||
public ProgramConfig(string programConfigValue) {
|
||||
public ProgramConfig(string fileText) {
|
||||
Program? current = null;
|
||||
|
||||
foreach (string line in programConfigValue.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
||||
foreach (string line in fileText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
||||
List<string> configLine = line.Split("\t").ToList();
|
||||
if (configLine.Count < 2) {
|
||||
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
|
||||
|
@ -28,9 +28,9 @@ namespace BenchtopParser {
|
||||
public TransducerVerify() {
|
||||
}
|
||||
|
||||
public TransducerVerify(string transducerVerifyValue) {
|
||||
public TransducerVerify(string fileText) {
|
||||
const string separator = "===============================================================";
|
||||
List<string> documentLines = transducerVerifyValue.Split(new string[] { Environment.NewLine }, StringSplitOptions.TrimEntries).ToList();
|
||||
List<string> documentLines = fileText.Split(new string[] { Environment.NewLine }, StringSplitOptions.TrimEntries).ToList();
|
||||
|
||||
// Check if proper document
|
||||
string title = documentLines[0];
|
||||
|
@ -1,24 +1,35 @@
|
||||
namespace BenchtopParserTests {
|
||||
public class HardwareCalibrationReport_Tests {
|
||||
public String HardwareCalibrationReportValue;
|
||||
private List<string> DocumentLines;
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
HardwareCalibrationReportValue = File.ReadAllText(
|
||||
Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Hardware Calibration Report.txt")
|
||||
);
|
||||
DocumentLines = HardwareCalibrationReportValue.Split(new string[] { Environment.NewLine }, StringSplitOptions.TrimEntries).ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_HardwareCalibrationReport_SetInstrumentInfo() {
|
||||
DocumentLines.RemoveRange(7, DocumentLines.Count-8); // trim extra not needed for test
|
||||
|
||||
BenchtopParser.HardwareCalibrationReport hcr = new();
|
||||
Assert.That(hcr.Instrument.Name, Is.EqualTo("UNSET"));
|
||||
|
||||
hcr.SetInstrumentInfo(DocumentLines);
|
||||
Assert.That(hcr.Instrument.Name, Is.EqualTo("Chassis2 Adult"));
|
||||
}
|
||||
|
||||
[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"));
|
||||
BenchtopParser.HardwareCalibrationReport hcr = new(HardwareCalibrationReportValue);
|
||||
}
|
||||
|
||||
[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"));
|
||||
Assert.That(ex.Message, Is.EqualTo("Invalid Hardware Calibration Report, please provide a Hardware Calibration Report file data"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
Loading…
Reference in New Issue
Block a user