public void AttachedOverrideMetadataCallbackTest() { ElementA element1 = new ElementA(); ElementB element2 = new ElementB(); ElementC element3 = new ElementC(); ElementD element4 = new ElementD(); int changeIndex = 1; int value2AChangedIndex = 0; int value2BChangedIndex = 0; int value2CChangedIndex = 0; int value2DChangedIndex = 0; ElementA.Value2ChangedA += (sender, e) => value2AChangedIndex = changeIndex++; ElementB.Value2ChangedB += (sender, e) => value2BChangedIndex = changeIndex++; ElementC.Value2ChangedC += (sender, e) => value2CChangedIndex = changeIndex++; ElementD.Value2ChangedD += (sender, e) => value2DChangedIndex = changeIndex++; element1.SetValue(ElementA.Value2Property, 100); Assert.AreEqual(1, value2AChangedIndex); Assert.AreEqual(0, value2BChangedIndex); Assert.AreEqual(0, value2CChangedIndex); Assert.AreEqual(0, value2DChangedIndex); element2.SetValue(ElementA.Value2Property, 100); Assert.AreEqual(2, value2AChangedIndex); Assert.AreEqual(3, value2BChangedIndex); Assert.AreEqual(0, value2CChangedIndex); Assert.AreEqual(0, value2DChangedIndex); element3.SetValue(ElementA.Value2Property, 100); Assert.AreEqual(4, value2AChangedIndex); Assert.AreEqual(5, value2BChangedIndex); Assert.AreEqual(6, value2CChangedIndex); Assert.AreEqual(0, value2DChangedIndex); element4.SetValue(ElementA.Value2Property, 100); Assert.AreEqual(7, value2AChangedIndex); Assert.AreEqual(5, value2BChangedIndex); Assert.AreEqual(6, value2CChangedIndex); Assert.AreEqual(8, value2DChangedIndex); }
public void OverrideMetadataDefaultValueTest() { ElementA element1 = new ElementA(); ElementB element2 = new ElementB(); ElementC element3 = new ElementC(); ElementD element4 = new ElementD(); int propertyChangedCount = 0; element1.PropertyChanged += (sender, e) => propertyChangedCount++; element2.PropertyChanged += (sender, e) => propertyChangedCount++; element3.PropertyChanged += (sender, e) => propertyChangedCount++; element4.PropertyChanged += (sender, e) => propertyChangedCount++; Assert.AreEqual(1, element1.GetValue(ElementA.Value1Property)); Assert.AreEqual(2, element2.GetValue(ElementA.Value1Property)); Assert.AreEqual(3, element3.GetValue(ElementA.Value1Property)); Assert.AreEqual(4, element4.GetValue(ElementA.Value1Property)); Assert.AreEqual(1, element1.GetValue(ElementA.Value2Property)); Assert.AreEqual(2, element2.GetValue(ElementA.Value2Property)); Assert.AreEqual(3, element3.GetValue(ElementA.Value2Property)); Assert.AreEqual(4, element4.GetValue(ElementA.Value2Property)); element1.SetValue(ElementA.Value1Property, 1); element2.SetValue(ElementA.Value1Property, 2); element3.SetValue(ElementA.Value1Property, 3); element4.SetValue(ElementA.Value1Property, 4); Assert.AreEqual(0, propertyChangedCount); element1.SetValue(ElementA.Value1Property, 100); Assert.AreEqual(1, propertyChangedCount); element1.SetValue(ElementA.Value2Property, 1); element2.SetValue(ElementA.Value2Property, 2); element3.SetValue(ElementA.Value2Property, 3); element4.SetValue(ElementA.Value2Property, 4); Assert.AreEqual(1, propertyChangedCount); element1.SetValue(ElementA.Value2Property, 100); Assert.AreEqual(2, propertyChangedCount); }
public double CalculateResult(double inputValue, double dt, EmelentP p, ElementI i, ElementD d, int iteration, double maxOutputValue, double minOutputValue) { double proportionalElementResult = p.CalculateResult(inputValue); inputSum += inputValue; double integratingElementValue = i.CalculateResult(inputValue, p, dt, inputSum); double derivativeElementValue = 0d; if (iteration != 0) { derivativeElementValue = d.CalculateResult(inputValue, p, dt, lastInputValue); } double controllerOutputValue = proportionalElementResult + integratingElementValue + derivativeElementValue; lastInputValue = inputValue; if (controllerOutputValue > maxOutputValue) { return(maxOutputValue); } if (controllerOutputValue < minOutputValue) { return(minOutputValue); } return(controllerOutputValue); }