add stub for TransducerVerify, wrap up most of ProgramConfig - needs more tests

This commit is contained in:
Tyrel Souza 2022-07-25 00:51:43 -04:00
parent 86bbb3067b
commit f71dc856fb
5 changed files with 67 additions and 41 deletions

View File

@ -1,10 +1,10 @@
namespace BenchtopParser { namespace BenchtopParser {
public class Parser { public class I28 {
public static List<I28.ProgramConfig> I28_ProgramConfig(String program_config) { public static Dictionary<String, ProgramConfig> Load_ProgramConfig(String program_config_value) {
List<I28.ProgramConfig> program_configs = new List<I28.ProgramConfig>(); Dictionary<String, ProgramConfig> program_configs = new Dictionary<String, ProgramConfig>();
I28.ProgramConfig? current = null; ProgramConfig? current = null;
foreach (var line in program_config.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
var config_line = line.Split("\t").ToList(); var config_line = line.Split("\t").ToList();
if (config_line.Count() < 2) { if (config_line.Count() < 2) {
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data"); throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
@ -13,12 +13,16 @@
config_line.RemoveAt(0); // Remove L column config_line.RemoveAt(0); // Remove L column
if (config_line[0].StartsWith("Start,")) { if (config_line[0].StartsWith("Start,")) {
// initialize programconfig // initialize programconfig
current = new I28.ProgramConfig(); current = new ProgramConfig();
continue; continue;
} }
if (config_line[0].StartsWith("Stop,")) { if (config_line[0].StartsWith("Stop,")) {
// Short circuit early when stop comes. // Short circuit early when stop comes.
program_configs.Add(current); if (current != null && current.ProgramNumber != null) {
program_configs.Add(current.ProgramNumber, current);
}
current = null;
// TODO: What if multiple configs how to handle start and stop?
break; break;
} }
var config = config_line[0].Split(",", 2).ToList(); var config = config_line[0].Split(",", 2).ToList();
@ -41,7 +45,7 @@
var data = programnumber_group_data[2]; var data = programnumber_group_data[2];
if (data.StartsWith("=")) { continue; /* comment line */ } if (data.StartsWith("=")) { continue; /* comment line */ }
var lineConfig = new I28.Configuration(); var lineConfig = new Configuration();
lineConfig.unit = config_line[1]; lineConfig.unit = config_line[1];
lineConfig.type = config_line[2]; //a, c, f, i lineConfig.type = config_line[2]; //a, c, f, i
var name_value = data.Split("="); var name_value = data.Split("=");
@ -51,9 +55,9 @@
// Deal with this group logic // Deal with this group logic
var group = programnumber_group_data[1]; var group = programnumber_group_data[1];
if (current != null && !current.Group.ContainsKey(group)) { if (current != null && !current.Group.ContainsKey(group)) {
current.Group.Add(group, new List<I28.Configuration> { lineConfig }); current.Group.Add(group, new Dictionary<String, Configuration> { { lineConfig.name, lineConfig } });
} else if (current != null ) { } else if (current != null) {
current.Group[group].Add(lineConfig); current.Group[group].Add(lineConfig.name, lineConfig);
} else { } else {
throw new Exception("Config list is null, something broke"); throw new Exception("Config list is null, something broke");
} }
@ -62,6 +66,12 @@
return program_configs; return program_configs;
} }
public static Dictionary<String, TransducerVerify> Load_TransducerVerify(String transducer_verify_value) {
foreach (var line in transducer_verify_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
}
return null;
}
} }
} }

View File

@ -5,13 +5,12 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BenchtopParser { namespace BenchtopParser {
public class I28 {
public class ProgramConfig { public class ProgramConfig {
public String? ProgramNumber { get; set; } public String? ProgramNumber { get; set; }
public Dictionary<String,List<Configuration>> Group { get; set; } public Dictionary<String, Dictionary<String, Configuration>> Group { get; set; }
public ProgramConfig() { public ProgramConfig() {
this.Group = new Dictionary<String,List<Configuration>>(); this.Group = new Dictionary<String, Dictionary<String, Configuration>>();
} }
} }
public class Configuration { public class Configuration {
@ -21,7 +20,4 @@ namespace BenchtopParser {
public String? unit { get; set; } public String? unit { get; set; }
} }
}
} }

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BenchtopParser {
public class TransducerVerify {
}
}

View File

@ -0,0 +1,32 @@
namespace BenchtopParserTests {
public class I28_Program_Config_Tests {
[SetUp]
public void Setup() {
}
[Test]
public void Test_ProgramConfig() {
String program_config = File.ReadAllText(
Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Program Config.txt")
);
var configs = BenchtopParser.I28.Load_ProgramConfig(program_config);
Assert.IsNotNull(configs);
// Check that group collecting works -
Assert.That(configs["P1"].Group["I"]["3"].value, Is.EqualTo("Unassigned"));
Assert.That(configs["P1"].Group["O"]["3"].value, Is.EqualTo("Test Passed"));
}
[Test]
public void Test_ProgramConfig_Throw_ErrorOrder() {
Exception ex = Assert.Throws<Exception>(delegate { BenchtopParser.I28.Load_ProgramConfig("EBAE006 L 1,P1"); });
Assert.That(ex.Message, Is.EqualTo("Setting Program Number Before Start. Error In Config"));
}
[Test]
public void Test_ProgramConfig_Throw_InvalidProgram() {
Exception ex = Assert.Throws<Exception>(delegate { BenchtopParser.I28.Load_ProgramConfig("broken"); });
Assert.That(ex.Message, Is.EqualTo("Invalid Program Config, please provide an I28 Program Config file data"));
}
}
}

View File

@ -1,22 +0,0 @@
namespace BenchtopParserTests {
public class Tests {
[SetUp]
public void Setup() {
}
[Test]
public void Test_ProgramConfig() {
String program_config = File.ReadAllText(
Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Program Config.txt")
);
var configs = BenchtopParser.Parser.I28_ProgramConfig(program_config);
Assert.IsNotNull(configs);
}
[Test]
public void Test_ProgramConfig_Throw_ErrorOrder() {
Exception ex = Assert.Throws<Exception>(delegate { BenchtopParser.Parser.I28_ProgramConfig("broken"); });
Assert.That(ex.Message, Is.EqualTo("Invalid Program Config, please provide an I28 Program Config file data"));
}
}
}