private static void TestObserverPattern() { WeatherData weatherData = new WeatherData(); TemperatureReporter temperatureReporter = new TemperatureReporter(); CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); CurrentTemperatureDisplay currentTemperatureDisplay = new CurrentTemperatureDisplay(temperatureReporter); Temperature t = new Temperature { Temp = 80 }; temperatureReporter.TemperatureChanged(t); t.Temp = 82; temperatureReporter.TemperatureChanged(t); Console.WriteLine(currentTemperatureDisplay.Display()); t.Temp = 78; temperatureReporter.TemperatureChanged(t); Console.WriteLine(currentTemperatureDisplay.Display()); weatherData.SetMeasurements(80, 65, 30.4); weatherData.SetMeasurements(82, 70, 29.2); weatherData.SetMeasurements(78, 90, 29.2); Console.WriteLine(currentConditionsDisplay.Display()); Console.WriteLine(statisticsDisplay.Display()); Console.WriteLine(forecastDisplay.Display()); Console.WriteLine(heatIndexDisplay.Display()); }
static void Main(string[] args) { var wheatherData = new WheatherData(); wheatherData.Temperature = 15.25f; wheatherData.Pressure = 25.25f; wheatherData.Humidity = 28.11f; var conditionDisplay = new CurrentConditionDisplay(wheatherData); var statisticsDisplay = new StatisticsDisplay(wheatherData); var heatIndexDisplay = new HeatIndexDisplay(wheatherData); wheatherData.Humidity = 32.11f; wheatherData.RemoveObserver(statisticsDisplay); wheatherData.Pressure = 35.99f; wheatherData.RegisterObserver(statisticsDisplay); wheatherData.Humidity = 11.11f; wheatherData.Pressure = 11.22f; wheatherData.Pressure = 11.22f; wheatherData.Pressure = 22.22f; wheatherData.Temperature = -115.25f; }
static void Main(string[] args) { var wheatherData = new WheatherData { Temperature = 15.25f, Pressure = 25.25f, Humidity = 28.11f }; var conditionDisplay = new CurrentConditionDisplay(wheatherData); var statisticsDisplay = new StatisticsDisplay(wheatherData); var heatIndexDisplay = new HeatIndexDisplay(wheatherData); wheatherData.Humidity = 32.11f; wheatherData.WheatherDataChanged -= statisticsDisplay.Update; wheatherData.Pressure = 35.99f; wheatherData.WheatherDataChanged += statisticsDisplay.Update; wheatherData.Humidity = 11.11f; wheatherData.Pressure = 11.22f; wheatherData.Pressure = 11.22f; wheatherData.Pressure = 22.22f; wheatherData.Temperature = -115.25f; }
public ObserverWeatherDataUnitTest() { _weatherData = new WeatherData(); _currentConditionsDisplay = new CurrentConditionsDisplay(_weatherData); _forcastDisplay = new ForcastDisplay(_weatherData); _statisticsDisplay = new StatisticsDisplay(_weatherData); _heatIndexDisplay = new HeatIndexDisplay(_weatherData); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); }
public void WhenCreateHeatIndexDisplayAndCallSetMeasurementsMethodExpectDisplayMethodReturnHeatIndexMessage() { var weatherData = new WeatherData(); var heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 50, 80); Assert.AreEqual("Heat index is: 81,07396", heatIndexDisplay.Display()); }
static void Main(string[] args) { var weatherData = new WeatherData(); var currentDisplay = new CurrentConditionsDisplay(weatherData); var heatDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4F); weatherData.SetMeasurements(82, 70, 29.2F); weatherData.SetMeasurements(78, 90, 29.2F); }
public void UpdateObservers() { WeatherData wd = new WeatherData(); IObserver fd = new ForecastDisplay(wd); IObserver sd = new StatisticsDisplay(wd); IObserver ccd = new CurrentConditionsDisplay(wd); IObserver hi = new HeatIndexDisplay(wd); wd.SetMeasurements(5.5f, 200f, 0.05f); }
public void weather_data_updates_heatindex_correctly() { var wd = new WeatherData(); var heatdisplay = new HeatIndexDisplay(wd); wd.SetMeasurements(80, 65, 30.4f); Assert.AreEqual("Heat index is 82.95535", heatdisplay.Display()); wd.SetMeasurements(78, 90, 29.2f); Assert.AreEqual("Heat index is 83.64967", heatdisplay.Display()); }
static void Main(string[] args) { var weatherData = new WeatherData(); var currentConditionsDisplay = new CurrentConditionasDisplay(weatherData); var heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurement(80, 45,34); weatherData.SetMeasurement(56, 33, 23); weatherData.SetMeasurement(11, 45, 55); Console.ReadKey(); }
public void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); }
public static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionDisplay currentDisplay = new CurrentConditionDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 29.2f); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionDisplay currentCondition = new CurrentConditionDisplay(weatherData); HeatIndexDisplay heatIndex = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); Console.ReadKey(); }
static void Main(string[] args) { var data = new WeatherData(); var display1 = new CurrentConditionsDisplay(data); var display2 = new ForecastDisplay(data); var display3 = new StatisticsDisplay(data); var display4 = new HeatIndexDisplay(data); data.SetMeasurements(21.3f, 23.1f, 52.4f); data.SetMeasurements(42.3f, 33.1f, 52.4f); data.SetMeasurements(19.3f, 63.1f, 52.4f); data.SetMeasurements(80.0f, 0.4f, 0f); }
private static void ObserverPattern() { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 29.2f); }
public void Test_WeatherStationHeatIndex() { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); var result = statisticsDisplay.Display(); }
static void Main(string[] args) { var weatherData = new WeatherData(); var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); var forecastDisplay = new ForecastDisplay(weatherData); var statisticsDisplay = new StatisticsDisplay(weatherData); var heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.MeasurmentsChanged( new WeatherMeasurements() { Temperature = new Temperature() { TemperatureType = Temperature.TemperatureTypeEnum.Fahrenheit, Value = 80 }, Humidty = 65.0, Pressure = 30.4d } ); weatherData.MeasurmentsChanged( new WeatherMeasurements() { Temperature = new Temperature() { TemperatureType = Temperature.TemperatureTypeEnum.Fahrenheit, Value = 82 }, Humidty = 70.0, Pressure = 27.2d } ); weatherData.MeasurmentsChanged( new WeatherMeasurements() { Temperature = new Temperature() { TemperatureType = Temperature.TemperatureTypeEnum.Fahrenheit, Value = 78 }, Humidty = 90.0, Pressure = 29.2d } ); }
static void Main(string[] args) { Model.WeatherData weather = new Model.WeatherData(); var currentConditionsDisplay = new CurrentConditionDisplay(weather); var statisticsDisplay = new StatisticsDisplay(weather); var forecastDisplay = new ForecastDisplay(weather); var heatIndex = new HeatIndexDisplay(weather); weather.SetMeasurements(20, 10, 45); weather.SetMeasurements(32, 60, 100); statisticsDisplay = null; forecastDisplay.UnregisterObserver(); weather.SetMeasurements(14, 80, 89); Console.ReadKey(); }
public void weather_data_updates_observers_correctly() { var wd = new WeatherData(); var conditions = new CurrentConditionsDisplay(wd); var heat = new HeatIndexDisplay(wd); var stats = new StatisticsDisplay(wd); var forecast = new ForecastDisplay(wd); wd.SetMeasurements(80, 65, 30.4f); Assert.AreEqual("Current Conditions: 80 celsius and humidity 65", conditions.Display()); Assert.AreEqual("Heat index is 82.95535", heat.Display()); Assert.AreEqual("Avg/Max/Min Temperature: 80/80/80", stats.Display()); Assert.AreEqual("Improving weather on the way!", forecast.Display()); wd.SetMeasurements(78, 90, 29.2f); Assert.AreEqual("Current Conditions: 78 celsius and humidity 90", conditions.Display()); Assert.AreEqual("Heat index is 83.64967", heat.Display()); Assert.AreEqual("Avg/Max/Min Temperature: 79/80/78", stats.Display()); Assert.AreEqual("Weather is getting bad!", forecast.Display()); }
public static void Main(string[] args) { WeatherMonitor monitor = new WeatherMonitor(); ForecastDisplay forecast = new ForecastDisplay(); CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(); StatisticsDisplay statistics = new StatisticsDisplay(); HeatIndexDisplay heatIndex = new HeatIndexDisplay(); monitor.SetMeasurments(new WeatherData(80, 65, 30.4f)); forecast.Subscribe(monitor); currentConditions.Subscribe(monitor); statistics.Subscribe(monitor); heatIndex.Subscribe(monitor); monitor.SetMeasurments(new WeatherData(82, 70, 29.2f)); statistics.Unsubscribe(); monitor.SetMeasurments(new WeatherData(78, 90, 29.2f)); monitor.SetMeasurments(null); //weatherData.SetMeasurments(82, 70, 29.2f); //weatherData.SetMeasurments(78, 90, 29.2f); Console.ReadLine(); }