示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //instantiate sensor
            weatherSensors = new SensorSubject();

            //Instantiate observers, pass in subject and listbox.
            AverageWeatherObserver = new AverageReadingObserver(lbaverage, weatherSensors);
            CurrentWeatherObserver = new CurrentReadingsObserver(lbcurrent, weatherSensors);
            ForcasterObserver = new ForcastObserver(lbforecast,weatherSensors);
        }
示例#2
0
        public void CuttentTempObserver_DisplayOutput_HumidINputShouldEqualOutput()
        {
            SensorSubject testSubject = new SensorSubject();

            ListBox testListbox = new ListBox();

            CurrentReadingsObserver CReadOb = new CurrentReadingsObserver(testListbox, testSubject);

            testSubject.InputTrigger("10", " 20", "30");

            String output = testListbox.Items[1].ToString();

            String expectedOutput = "Humidity:\t20.00";

            Assert.AreEqual(expectedOutput, output);
        }
示例#3
0
        public SensorObserver(ListBox outputDisplay, SensorSubject subject)
        {
            //Set reffentce to subject, display and then add this object to the subjects observer list.
            sensorSubject = subject;

            dataDisplay = outputDisplay;

            sensorSubject.addObserver(this);

            //Allocate memory for computer and data readings.
            currentDatareadingBar = 0;
            currentDatareadingHumid = 0;
            currentDataReadingTemp = 0;

            currentComputedBar = 0;
            currentComputedHumid = 0;
            currentComputedTemp = 0;
        }
示例#4
0
        public void AverageConditionObserver_DisplayOutput_TempAverageOutputShouldBeAverageOFInputs()
        {
            SensorSubject testSubject = new SensorSubject();
            ListBox testListbox = new ListBox();

            AverageReadingObserver testAverageObserver  = new AverageReadingObserver(testListbox, testSubject);

            testSubject.InputTrigger("10", " 20", "30");
            testListbox.Items.Clear();
            testSubject.InputTrigger("10", " 20", "30");
            testListbox.Items.Clear();
            testSubject.InputTrigger("30", " 20", "10");

            String output = testListbox.Items[0].ToString();

            String expectedOutput = "Temperature:\t16.67";

            Assert.AreEqual(expectedOutput, output);
        }
 public CurrentReadingsObserver(ListBox outputDisplay, SensorSubject subject)
     : base(outputDisplay, subject)
 {
 }
 // Average reading observer, revieves data from sunject , performas aver age calculation and displays to list box.
 public AverageReadingObserver(ListBox outputDisplay, SensorSubject subject)
     : base(outputDisplay, subject)
 {
     runCount = 0;
 }
示例#7
0
        public void ForcastConditionObserver_DisplayOutput_MediumPressureIndicatewetWeather()
        {
            SensorSubject testSubject = new SensorSubject();
            ListBox testListbox = new ListBox();

            ForcastObserver testAverageObserver = new ForcastObserver(testListbox, testSubject);

            testSubject.InputTrigger("10", " 20", "1000");

            String output = testListbox.Items[0].ToString();

            String expectedOutput = "Wet weather coming";

            Assert.AreEqual(expectedOutput, output);
        }