[InlineData("Freezing", TemperatureDirection.Decreasing, 2, 0, true)] // decreasing threshold, decreasing temperature public void HitsTemperatureThresholdTest(string thresholdName, TemperatureDirection temperatureDirection, double previousTemperature, double thresholdTemperature, bool hitsTemperatureThreshold) { // Arrange List <TemperatureThreshold> temperatureThresholdList = new List <TemperatureThreshold> { new TemperatureThreshold { Name = thresholdName, Temperature = new Temperature(thresholdTemperature), Tolerance = new Temperature(0.5), Direction = temperatureDirection } }; Thermometer thermometer = new Thermometer(); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(previousTemperature); // Act thermometer.Temperature = new Temperature(thresholdTemperature); // Assert Assert.Equal(hitsTemperatureThreshold, thermometer.IsAtTemperatureThreshold); if (thermometer.IsAtTemperatureThreshold) { string expectedThresholdName = thresholdName; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); } }
public TemperatureThreshold(string name, Temperature temperature, Temperature tolerance, TemperatureDirection direction) { Name = name; Temperature = temperature; Tolerance = tolerance; Direction = direction; }
public static List <TemperatureThreshold> CreateTemperatureThresholds(TemperatureDirection temperatureDirection) { List <TemperatureThreshold> temperatureThresholdList = new List <TemperatureThreshold> { new TemperatureThreshold { Name = "Freezing", Temperature = new Temperature(0), Tolerance = new Temperature(0.5), Direction = temperatureDirection }, new TemperatureThreshold { Name = "Room Temperature", Temperature = new Temperature(20), Tolerance = new Temperature(0.5), Direction = temperatureDirection }, new TemperatureThreshold { Name = "Boiling", Temperature = new Temperature(100), Tolerance = new Temperature(0.5), Direction = temperatureDirection } }; return(temperatureThresholdList); }
public TemperatureThreshold(string name, double temperature, double tolerance, TemperatureDirection direction) { Name = name; Temperature = temperature; Tolerance = tolerance; Direction = direction; IsAtThreshold = false; }
public Machine(string machineName) { this.currentMetric = Metric.Celsius; this.currentDirection = TemperatureDirection.Stable; rnd = new Random(); this.temperature = rnd.Next(minimumTemperature, maximumTemperature); this.machineName = machineName; }
public Machine(float startingTemperature, string machineName) { this.currentMetric = Metric.Celsius; this.currentDirection = TemperatureDirection.Stable; this.temperature = startingTemperature; rnd = new Random(); this.machineName = machineName; }
//public bool IsAtTemperatureThreshold //{ // get // { // foreach (TemperatureThreshold temperatureThreshold in _temperatureThresholdList) // { // Temperature.ResetToleranceToDefault(); // bool previouslyAtThisThreshold = temperatureThreshold == CurrentTemperatureThreshold; // // If previously at this threshold, then set "wider" tolerance for this threshold to reduce fluctuations // if (previouslyAtThisThreshold) // { // Temperature.Tolerance = temperatureThreshold.Tolerance; // } // if (_temperature == temperatureThreshold.Temperature) // { // if (previouslyAtThisThreshold) // { // _eventHandlerFiredForTemperatureThreshold = true; // return true; // } // TemperatureDirection temperatureDirection = _temperature >= _previousTemperature ? TemperatureDirection.Increasing : TemperatureDirection.Decreasing; // bool isSameTemperatureDirection = temperatureDirection == temperatureThreshold.Direction; // if (isSameTemperatureDirection) // { // CurrentTemperatureThreshold = temperatureThreshold; // _eventHandlerFiredForTemperatureThreshold = false; // } // return isSameTemperatureDirection; // } // } // return false; // } //} public bool PassedThroughTemperatureThreshold(TemperatureThreshold temperatureThreshold) { Temperature thresholdTemperature = temperatureThreshold.Temperature; TemperatureDirection thresholdDirection = temperatureThreshold.Direction; bool passedThroughThreshold = _previousTemperature <= thresholdTemperature && thresholdTemperature <= _temperature; bool rightDirection = _previousTemperature <= _temperature && thresholdDirection == TemperatureDirection.Increasing; return(passedThroughThreshold && rightDirection); }
public static void HandleThermometerThresholdReached(object sender, TemperatureThresholdEventArgs temperatureThresholdEventArgs) { TemperatureThreshold temperatureThreshold = temperatureThresholdEventArgs.TemperatureThreshold; string name = temperatureThreshold.Name; Temperature temperature = temperatureThreshold.Temperature; TemperatureDirection direction = temperatureThreshold.Direction; string message = $"Reached temperature threshold: {name}, temperature = {temperature:F1}, Direction = {direction}"; WriteLine(message); }
private void HandleTemperatureThresholdReached(object sender, TemperatureThresholdEventArgs e) { TemperatureThreshold temperatureThreshold = e.TemperatureThreshold; _name = temperatureThreshold.Name; _temperature = temperatureThreshold.Temperature; _tolerance = temperatureThreshold.Tolerance; _direction = temperatureThreshold.Direction; _eventHandlerCalledCount++; }
public float ReadTemperature() { float delta = (float)rnd.NextDouble(); float sign = 1; if ((this.temperature <= minimumTemperature) && ((this.currentDirection == TemperatureDirection.Decreasing) || (this.currentDirection == TemperatureDirection.Bouncing)) || ((this.temperature >= maximumTemperature) && ((this.currentDirection == TemperatureDirection.Increasing) || (this.currentDirection == TemperatureDirection.Bouncing)))) { this.currentDirection = TemperatureDirection.Stable; } switch (this.currentDirection) { case TemperatureDirection.Bouncing: sign = (rnd.Next(2) == 0) ? 1 : -1; break; case TemperatureDirection.Increasing: delta = (float)rnd.NextDouble(); sign = 1; break; case TemperatureDirection.Decreasing: sign = -1; break; case TemperatureDirection.Stable: delta = 0; break; } this.temperature = temperature + (delta * sign); this.temperatureReadTimestamp = DateTime.Now; this.temperatureReadId = this.machineName + "_" + this.temperatureReadTimestamp.ToString("yyyyMMddHH:mm:ss.ffff"); if (currentMetric == Metric.Celsius) { return(this.temperature); } else { return(this.temperature); } }
public Regulate(IThermometer thermometer, IHeater heater, double minTemp, double maxTemp) { Thermometer = thermometer; Heater = heater; MinTemp = minTemp; MaxTemp = maxTemp; for (; ;) { while (Thermometer.Read() > MinTemp) { Wait(); } Heater.Engage(); TemperatureDirection = TemperatureDirection.Rising; while (Thermometer.Read() < MaxTemp) { Wait(); } Heater.Disengage(); TemperatureDirection = TemperatureDirection.Falling; } }