add stub for TransducerVerify, wrap up most of ProgramConfig - needs more tests
This commit is contained in:
parent
86bbb3067b
commit
f71dc856fb
@ -1,10 +1,10 @@
|
||||
namespace BenchtopParser {
|
||||
public class Parser {
|
||||
public static List<I28.ProgramConfig> I28_ProgramConfig(String program_config) {
|
||||
List<I28.ProgramConfig> program_configs = new List<I28.ProgramConfig>();
|
||||
I28.ProgramConfig? current = null;
|
||||
public class I28 {
|
||||
public static Dictionary<String, ProgramConfig> Load_ProgramConfig(String program_config_value) {
|
||||
Dictionary<String, ProgramConfig> program_configs = new Dictionary<String, ProgramConfig>();
|
||||
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();
|
||||
if (config_line.Count() < 2) {
|
||||
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
|
||||
if (config_line[0].StartsWith("Start,")) {
|
||||
// initialize programconfig
|
||||
current = new I28.ProgramConfig();
|
||||
current = new ProgramConfig();
|
||||
continue;
|
||||
}
|
||||
if (config_line[0].StartsWith("Stop,")) {
|
||||
// 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;
|
||||
}
|
||||
var config = config_line[0].Split(",", 2).ToList();
|
||||
@ -41,7 +45,7 @@
|
||||
var data = programnumber_group_data[2];
|
||||
if (data.StartsWith("=")) { continue; /* comment line */ }
|
||||
|
||||
var lineConfig = new I28.Configuration();
|
||||
var lineConfig = new Configuration();
|
||||
lineConfig.unit = config_line[1];
|
||||
lineConfig.type = config_line[2]; //a, c, f, i
|
||||
var name_value = data.Split("=");
|
||||
@ -51,9 +55,9 @@
|
||||
// Deal with this group logic
|
||||
var group = programnumber_group_data[1];
|
||||
if (current != null && !current.Group.ContainsKey(group)) {
|
||||
current.Group.Add(group, new List<I28.Configuration> { lineConfig });
|
||||
} else if (current != null ) {
|
||||
current.Group[group].Add(lineConfig);
|
||||
current.Group.Add(group, new Dictionary<String, Configuration> { { lineConfig.name, lineConfig } });
|
||||
} else if (current != null) {
|
||||
current.Group[group].Add(lineConfig.name, lineConfig);
|
||||
} else {
|
||||
throw new Exception("Config list is null, something broke");
|
||||
}
|
||||
@ -62,6 +66,12 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,12 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BenchtopParser {
|
||||
public class I28 {
|
||||
public class ProgramConfig {
|
||||
public String? ProgramNumber { get; set; }
|
||||
public Dictionary<String,List<Configuration>> Group { get; set; }
|
||||
public Dictionary<String, Dictionary<String, Configuration>> Group { get; set; }
|
||||
|
||||
public ProgramConfig() {
|
||||
this.Group = new Dictionary<String,List<Configuration>>();
|
||||
this.Group = new Dictionary<String, Dictionary<String, Configuration>>();
|
||||
}
|
||||
}
|
||||
public class Configuration {
|
||||
@ -21,7 +20,4 @@ namespace BenchtopParser {
|
||||
public String? unit { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
10
BenchtopParser/TransducerVerify.cs
Normal file
10
BenchtopParser/TransducerVerify.cs
Normal 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 {
|
||||
}
|
||||
}
|
32
BenchtopParserTests/I28_Program_Config_Tests.cs
Normal file
32
BenchtopParserTests/I28_Program_Config_Tests.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user