public static void Main(String[] args) { Thermometer t = new Thermometer(); t.Reading += new Handler(PrintReading); t.Reading += new Handler(CountReading); }
static void InitializeObjects() { AppConfigData config = new AppConfigData(); lcdScreen = new LcdScreen(config.LcdRsPinNumber, config.LcdEPinNumber, config.LcdData0PinNumber, config.LcdData1PinNumber, config.LcdData2PinNumber, config.LcdData3PinNumber, config.LcdData4PinNumber, config.LcdData5PinNumber, config.LcdData6PinNumber, config.LcdData7PinNumber ); alarm = new Alarm(new Diode(config.DiodePinNumber), new Buzzer(config.BuzzerPinNumber), new Button(config.ButtonPinNumber)); thermometer = new Thermometer(config.DevicesDirectoryPath, config.ThermometerAddress, config.ContentFileName); dhtSensor = new DHT(config.DHTSensorPinNumber); dhtData = new DHTData(); temperatureThreshold = config.TemperatureThreshold; }
public void HitAllTemperatureThresholdsDecreasingTest() { // Arrange Thermometer thermometer = new Thermometer(); List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(110); // Act thermometer.Temperature = new Temperature(100); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); string expectedThresholdName = "Boiling"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(20); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); expectedThresholdName = "Room Temperature"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(0); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); expectedThresholdName = "Freezing"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); }
public void TemperatureThresholdEventHandlerFiresTest() { // Arrange Thermometer thermometer = new Thermometer(); List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.TemperatureThresholdReached += HandleTemperatureThresholdReached; thermometer.Temperature = new Temperature(2); _eventHandlerCalledCount = 0; // Act thermometer.Temperature = new Temperature(0); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); const string expectedThresholdName = "Freezing"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); Assert.Equal(_eventHandlerCalledCount, 1); Assert.Equal(expectedThresholdName, _name); // todo Need value comparison not reference compariosn (or override equality) Assert.Equal(new Temperature(0), _temperature); Assert.Equal(new Temperature(.5), _tolerance); Assert.Equal(TemperatureDirection.Decreasing, _direction); }
/// <summary> /// Entry point of the program. /// </summary> public static void Main() { Thermometer thermometer = new Thermometer(); Console.WriteLine(MessageWelcome); string command; bool exit = false; do { Console.Write("\n" + Prompt + " "); command = Console.ReadLine(); if (command == CommandAverage) { Console.WriteLine(thermometer.AverageTemperature); } else if (command == CommandCurrent) { Console.WriteLine(thermometer.Temperature); } else if (command == CommandExit) { exit = true; } else { Console.WriteLine(CommandAverage + "\t\t" + MessageAverage); Console.WriteLine(CommandCurrent + "\t\t" + MessageCurrent); Console.WriteLine(CommandExit + "\t\t" + MessageExit); Console.WriteLine(CommandHelp + "\t\t" + MessageHelp); } } while (!exit); }
[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 void RemainsAtDecreasingThresholdWithDecreasingTemperatureTest() { // Arrange Thermometer thermometer = new Thermometer(); List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(2); // Act thermometer.Temperature = new Temperature(0); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); // Act thermometer.Temperature = new Temperature(-.1); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); // Act thermometer.Temperature = new Temperature(-.2); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); }
public override void OnNext(Thermometer currentResponse) { string message = string.Format(Name + ": The temperature is {0}°{1} at {2:g}", currentResponse.Temperature, Request.Unit.ToString(), currentResponse.ObservationTime); Console.WriteLine(message); log.Debug(message); }
public override void OnNext(Thermometer currentResponse) { string message = string.Format(Name + ": The threshold {0}°{1} was reached at {2:g}", Request.Threshold, Request.Unit.ToString(), currentResponse.ObservationTime); Console.WriteLine(message); log.Debug(message); }
public void ConstructorTest(Unit unit) { var thermometer = new Thermometer(unit); Assert.Equal(unit, thermometer.ThermometerUnit); Assert.Equal(unit, thermometer.Temperature.Unit); Assert.Equal(0.0m, thermometer.Temperature.Value); }
public void Read_Valid_Temperature() { Thermometer thermometer = new Thermometer(); thermometer.FreezingPoint = -20; thermometer.BoilingPoint = 20; Assert.IsNotNull(thermometer.ReadTemperature(random.Next(-10, 10))); }
void Start() { currentLocation = transform.position; zeroRotation = Quaternion.Euler(0f,0f,0f); thermometer = GameObject.Find ("Thermometer").GetComponent<Thermometer> (); currentState = "Solid"; childParticles = (Instantiate (SolidParticlePrefab, currentLocation, zeroRotation) as GameObject); childParticles.transform.parent = this.gameObject.transform; }
static void Main(string[] args) { var thermometer = new Thermometer(20); Console.WriteLine(thermometer); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public void HitsFreezingThresholdWhenTemperatureIsDeceasingTest() { // Arrange Thermometer thermometer = new Thermometer(); List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(2); const string expectedThresholdName = "Freezing"; // Act thermometer.Temperature = new Temperature(.5); // Assert Assert.False(thermometer.IsAtTemperatureThreshold); // Act thermometer.Temperature = new Temperature(.4); // Assert Assert.False(thermometer.IsAtTemperatureThreshold); // Act thermometer.Temperature = new Temperature(0); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(-.4); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(+.4); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(-.5); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(+.5); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); }
/// <summary> /// Try to parse the line and instantiate sensor from any defined. /// </summary> /// <param name="line"></param> /// <param name="sensor"></param> /// <returns></returns> public bool TryGetSensor(string line, out ISensor sensor) { sensor = null; var record = line.Split(Constants.Separator); if (record.Length != 2) { Console.WriteLine($"Invalid data record format: '{record}'. Expected: 'recordType recordName'"); return(false); } var success = Enum.TryParse(record[0], true, out SensorType parsed); if (!success) { Console.WriteLine( $"Unable to parse sensor type from record. Available values: '{string.Join(", ", Enum.GetValues<SensorType>())}', Got: '{record[0]}"); return(false); } try { //TODO consider reflection and loading all the sensors form the given folder (stretch) switch (parsed) { case SensorType.Thermometer: sensor = new Thermometer(record[1], double.Parse(_referenceValues[1])); return(true); case SensorType.Humidity: sensor = new Humidity(record[1], double.Parse(_referenceValues[2]), 1.0); return(true); case SensorType.Monoxide: sensor = new Monoxide(record[1], int.Parse(_referenceValues[3]), 3); return(true); default: return(false); } } catch (FormatException e) { Console.WriteLine($"Invalid format of a reference value for sensor of type: {parsed}. \n{e}"); return(false); } catch (IndexOutOfRangeException e) { Console.WriteLine( $"Not enough reference values provided for given sensor types. Expected: '{Enum.GetValues<SensorType>().Length}', Got: {_referenceValues.Length - 1}\n{e}"); return(false); } }
public void Improved() { var minTemp = 0.0; var maxTemp = 1.0; var thermometer = new Thermometer(); var heater = new Heater(); var fbi = new FurnaceImprovedBase(); fbi.Regulate(thermometer, heater, minTemp, maxTemp); }
public void Read_valid_Custom_ThresPoint() { Thermometer thermometer = new Thermometer(); thermometer.FreezingPoint = 20; thermometer.BoilingPoint = -20; thermometer.CustomThresholdPoint = 12; var temperature = thermometer.ReadTemperature(12, ThresholdPoint.CustomPoint); Assert.AreEqual(temperature.Status, ThresholdPoint.CustomPoint); }
public async Task <Thermometer> Put(string session, int id, [FromBody] Thermometer device) { string openId = await GetOpenId(session); if (openId == null) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(null); } return(await db.UpdateThermometer(openId, id, device.Name)); }
protected override void Initialize() { room = new Room(this); room.temperature = 25; room.humidity = 40; _controlCenter = new ControlCenter(this, 25.0, 40.0); _cooler = new Cooler(this); _heater = new Heater(this); _humidifier = new Humidifier(this); _hygrometer = new Hygrometer(this); _thermometer = new Thermometer(this); }
/* * Create list of temperatures and set main unit for thermometer object */ private bool handleFileData() { if (fileData == null) { MessageBox.Show("No input data", "No input", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } thermometer = new Thermometer(); thermometer.setTemperatures(fileData.Item1); thermometer.setMainUnit(fileData.Item2); return(true); }
public void HandleTemperatureChangedWithSameUnit(Unit unit) { var thermometer = new Thermometer(unit); thermometer.UpdateTemperature(new Temperature(10.5m, unit)); Assert.Equal(10.5m, thermometer.Temperature.Value); Assert.Equal(unit, thermometer.Temperature.Unit); thermometer.UpdateTemperature(new Temperature(5.5m, unit)); Assert.Equal(5.5m, thermometer.Temperature.Value); Assert.Equal(unit, thermometer.Temperature.Unit); }
protected override void ImplementUserControl() { Thermometer thermometer = new Thermometer(); thermometer.Location = new System.Drawing.Point(172, 45); thermometer.Name = "thermometer"; thermometer.Size = new System.Drawing.Size(72, 184); thermometer.TabIndex = 0; controlHandle = thermometer; InitControl(controlHandle); initContextMenuStrip(); }
public override void OnNext(Thermometer currentResponse) { Console.WriteLine(Name + ": The temperature is {0}°{1} at {2:g}", currentResponse.Temperature, Request.Unit.ToString(), currentResponse.ObservationTime); if (first) { lastResponse = currentResponse; first = false; } else { Console.WriteLine(Name + ": Temperature change is {0}°{1} in {2:g}", currentResponse.Temperature - lastResponse.Temperature, Request.Unit.ToString(), currentResponse.ObservationTime.ToUniversalTime() - lastResponse.ObservationTime.ToUniversalTime()); } }
public void Regulate(Thermometer thermometer, Heater heater, double minTemp, double maxTemp) { while (true) { while (thermometer.Read() > minTemp) { FakeUtils.Wait(1); } heater.Engage(); while (thermometer.Read() < maxTemp) { FakeUtils.Wait(1); } heater.Disengage(); } }
private static void TestObserver() { var temp = new Thermometer(); var fun = new Fan(temp); var heater = new Heater(temp); temp.UpTemp(new Temperature(-3)); Console.WriteLine("-------------------"); temp.UpTemp(new Temperature(30)); Console.WriteLine("-------------------"); heater.OnCompleted(); temp.UpTemp(new Temperature(15)); Console.WriteLine("-------------------"); }
public void TemperatureFlucturationWithIncreasingAndDecreasingTemperaturesTest() { // Arrange List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); Thermometer thermometer = new Thermometer(); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(2.0); const string expectedThresholdName = "Freezing"; // Act thermometer.Temperature = new Temperature(0.0); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(-0.1); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(0.0); // increasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(-0.1); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); // Act thermometer.Temperature = new Temperature(0.2); // increasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); }
public void HitsRoomTemperatureThresholdWhenTemperatureIsDeceasingTest() { // Arrange Thermometer thermometer = new Thermometer(); List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(22); // Act thermometer.Temperature = new Temperature(20); // decreasing temperature // Assert Assert.True(thermometer.IsAtTemperatureThreshold); const string expectedThresholdName = "Room Temperature"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); }
public void ConvertFahrenheitTemperatureTest() { // Arrange List <TemperatureThreshold> temperatureThresholdList = TestUtils.CreateTemperatureThresholds(TemperatureDirection.Decreasing); Thermometer thermometer = new Thermometer(); thermometer.SetTemperatureThresholds(temperatureThresholdList); thermometer.Temperature = new Temperature(40, TemperatureType.Fahrenheit); // Act thermometer.Temperature = new Temperature(32, TemperatureType.Fahrenheit); // Assert Assert.True(thermometer.IsAtTemperatureThreshold); const string expectedThresholdName = "Freezing"; Assert.Equal(expectedThresholdName, thermometer.CurrentTemperatureThreshold.Name); }
public async Task <Thermometer> Post(string session, string sn, [FromBody] Thermometer device) { string openId = await GetOpenId(session); if (openId == null) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(null); } if (await db.GetThermometer(sn, openId) == null) { return(await db.AddThermometer(openId, sn, device.Name)); } else { return(null); } }
// メイン関数 static void Main(string[] args) { // 温度計を生成する Thermometer homeThermometer = new Thermometer(); // チェッカーを生成する Checker outside = new Checker(homeThermometer, 10); Checker inside = new Checker(homeThermometer, 20); // 通知者を紐付ける homeThermometer.Attach(outside); homeThermometer.Attach(inside); // 温度を変える homeThermometer.Temperature = 40; // 観測者へ通知する homeThermometer.Notify(); }
private static void ProcessTemperatureReading(XBeeIOFrame frame) { var thermometer = _thermometers.SingleOrDefault(x => x.SourceAddress == frame.SourceAddress); if (thermometer == null) { _thermometers.Add(thermometer = new Thermometer(frame.SourceAddress)); _thermometers.Sort((a, b) => a.SourceAddress.CompareTo(b.SourceAddress)); } thermometer.AddSample(frame.Analog0Sample); var top = Console.CursorTop; Console.CursorLeft = 0; Console.CursorTop = _thermometers.IndexOf(thermometer); Console.WriteLine(thermometer); Console.CursorTop = Math.Max(top, _thermometers.Count); }
private static async Task Main() { Console.WriteLine($"\nEXAMPLE 3 : PUB/SUB : PRODUCER)"); var connectionFactory = new ConnectionFactory { HostName = "localhost", UserName = "******", Password = "******" }; using var connection = connectionFactory.CreateConnection(); using var channel = connection.CreateModel(); const string QueueName = ""; const string ExchangeName = "example3_forecasts_exchange"; channel.ExchangeDeclare(exchange: ExchangeName, type: ExchangeType.Fanout); while (true) { var forecast = Thermometer.Fake().Report(); channel.BasicPublish( exchange: ExchangeName, routingKey: QueueName, body: Encoding.UTF8.GetBytes(forecast.ToJson()) ); DisplayInfo <Forecast> .For(forecast) .SetExchange(ExchangeName) .SetQueue(QueueName) .SetRoutingKey(QueueName) .SetVirtualHost(connectionFactory.VirtualHost) .Display(Color.Cyan); await Task.Delay(millisecondsDelay : 3000); } }
static void Main(string[] args) { Thermometer thermometer = new Thermometer(); ThermometerDisplay display1 = new ThermometerDisplay(1, thermometer); ThermometerDisplay display2 = new ThermometerDisplay(2, thermometer); ThermometerDisplay display3 = new ThermometerDisplay(3, thermometer); thermometer.AddObserver(display1); thermometer.AddObserver(display2); thermometer.AddObserver(display3); thermometer.ReadTemperature(); thermometer.RemoveObserver(display1); thermometer.ReadTemperature(); thermometer.AddObserver(display1); thermometer.ReadTemperature(); thermometer.ReadTemperature(); thermometer.ReadTemperature(); }