From 0df8886bef3fe4096ffd4b3e7acf85bb0ad77583 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 13 Jul 2016 09:36:33 -0700 Subject: [PATCH] More tests Validate that known settings are requested with the correct type passed to GetValue Put in tests for extruder_count --- .../Settings/SettingsProfile.cs | 32 +++++++++++++ .../MatterControl/SettingsParseTests.cs | 46 ++++++++++++++----- 2 files changed, 67 insertions(+), 11 deletions(-) diff --git a/SlicerConfiguration/Settings/SettingsProfile.cs b/SlicerConfiguration/Settings/SettingsProfile.cs index f2e2f8707..f69f26151 100644 --- a/SlicerConfiguration/Settings/SettingsProfile.cs +++ b/SlicerConfiguration/Settings/SettingsProfile.cs @@ -422,11 +422,43 @@ namespace MatterHackers.MatterControl.SlicerConfiguration #region Migrate to LayeredProfile + static Dictionary expectedMappingTypes = new Dictionary() + { + [SettingsKey.extruders_share_temperature] = typeof(int), + [SettingsKey.extruder_count] = typeof(int), + [SettingsKey.extruders_share_temperature] = typeof(bool), + [SettingsKey.has_heated_bed] = typeof(bool), + [SettingsKey.nozzle_diameter] = typeof(double), + [SettingsKey.bed_temperature] = typeof(double), + }; + + void ValidateType(string settingsKey) + { + if(expectedMappingTypes.ContainsKey(settingsKey)) + { + if(expectedMappingTypes[settingsKey] != typeof(T)) + { + throw new Exception("You must request the correct type of this settingsKey."); + } + } + + if(settingsKey.Contains("%")) + { + if(typeof(T) != typeof(double)) + { + throw new Exception("To get processing of a % you must request the type as double."); + } + } + } + /// ///Returns the first matching value discovered while enumerating the settings layers /// public T GetValue(string settingsKey) where T : IConvertible { +#if DEBUG + ValidateType(settingsKey); +#endif if (typeof(T) == typeof(bool)) { return (T)(object)(this.GetValue(settingsKey) == "1"); diff --git a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs index 7a2ab5930..c02c41f42 100644 --- a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs @@ -18,22 +18,46 @@ namespace MatterControl.Tests.MatterControl [Test] public void SupportInterfaceMaterialAssignedToExtruderOne() { - // percent first layer extrusion width + // first_layer_extrusion_width { - string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, "%150", SettingsKey.nozzle_diameter, ".4" }; - Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .6, .0001); + // percent first layer extrusion width + { + string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, "%150", SettingsKey.nozzle_diameter, ".4" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .6, .0001); + } + + // absolute first layer extrusion width + { + string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, ".75", SettingsKey.nozzle_diameter, ".4" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .75, .0001); + } + + // 0 first layer extrusion width + { + string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, "0", SettingsKey.nozzle_diameter, ".4" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .4, .0001); + } } - // absolute first layer extrusion width + // extruder_count { - string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, ".75", SettingsKey.nozzle_diameter, ".4" }; - Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .75, .0001); - } + // normal single + { + string[] settings = new string[] { SettingsKey.extruder_count, "1", SettingsKey.extruders_share_temperature, "0" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.extruder_count), 1); + } - // 0 first layer extrusion width - { - string[] settings = new string[] { SettingsKey.first_layer_extrusion_width, "0", SettingsKey.nozzle_diameter, ".4" }; - Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.first_layer_extrusion_width), .4, .0001); + // normal multiple + { + string[] settings = new string[] { SettingsKey.extruder_count, "2", SettingsKey.extruders_share_temperature, "0" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.extruder_count), 2); + } + + // shared temp + { + string[] settings = new string[] { SettingsKey.extruder_count, "2", SettingsKey.extruders_share_temperature, "1" }; + Assert.AreEqual(GettProfile(settings).GetValue(SettingsKey.extruder_count), 1); + } } }