More tests

Validate that known settings are requested with the correct type passed to GetValue
Put in tests for extruder_count
This commit is contained in:
Lars Brubaker 2016-07-13 09:36:33 -07:00
parent edbc590642
commit 0df8886bef
2 changed files with 67 additions and 11 deletions

View file

@ -422,11 +422,43 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
#region Migrate to LayeredProfile
static Dictionary<string, Type> expectedMappingTypes = new Dictionary<string, Type>()
{
[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<T>(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.");
}
}
}
///<summary>
///Returns the first matching value discovered while enumerating the settings layers
///</summary>
public T GetValue<T>(string settingsKey) where T : IConvertible
{
#if DEBUG
ValidateType<T>(settingsKey);
#endif
if (typeof(T) == typeof(bool))
{
return (T)(object)(this.GetValue(settingsKey) == "1");

View file

@ -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<double>(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<double>(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<double>(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<double>(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<double>(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<int>(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<double>(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<int>(SettingsKey.extruder_count), 2);
}
// shared temp
{
string[] settings = new string[] { SettingsKey.extruder_count, "2", SettingsKey.extruders_share_temperature, "1" };
Assert.AreEqual(GettProfile(settings).GetValue<int>(SettingsKey.extruder_count), 1);
}
}
}