//Constructor
 public AverageObserver(ListBox lb, WeatherSubject subject)
     : base(lb, subject)
 {
     // Initialise variables
     runningTemp     = 0;
     runningHumidity = 0;
     runningPressure = 0;
     avgCount        = 0;
 }
        public Form1()
        {
            InitializeComponent();

            // Inititalise them
            sub = new WeatherSubject();
            cO  = new CurrentObserver(lbCurrent, sub);
            aO  = new AverageObserver(lbAverage, sub);
            fO  = new ForecastObserver(lbForecast, sub);
        }
예제 #3
0
        public Form1()
        {
            InitializeComponent();

            //Instantiate sub+obs
            ws = new WeatherSubject();
            tObs = new TemperatureObserver(lbTemp, ws);
            aObs = new AverageObserver(lbAverages, ws);
            fObs = new ForeCastObserver(lbForecast, ws);
        }
        //Constructor
        public WeatherObserver(ListBox lb, WeatherSubject subject)
        {
            // Inititalise variables
            currentTemp     = 0;
            currentHumidity = 0;
            currentPressure = 0;

            this.lb      = lb;
            this.subject = subject;

            // Adds Observer to the Observer list
            subject.AddObservers(this);
        }
예제 #5
0
        //Ctor
        public WeatherObserver(ListBox lb, WeatherSubject ws)
        {
            //Inititialise attributes
            cTemp = 0;
            cHumid = 0;
            cPressure = 0;

            //Bind form control to local variable (I still can't explain these lines very well)
            this.lb = lb;
            this.ws = ws;

            //Add this brand-spanking new obs to the obs list
            ws.AddObserver(this);
        }
예제 #6
0
        public void AvgObs_UpdateValues_ReturnsExpected()
        {
            //Create needed objects
            ListBox lb = new ListBox();
            WeatherSubject ws = new WeatherSubject();
            AverageObserver aObs = new AverageObserver(lb, ws);

            //Update tobs with some values
            aObs.Update(23,1,1);

            double expected = 23.00;
            double actual = aObs.CCompTemp;

            Assert.AreEqual(expected, actual);
        }
예제 #7
0
        public void ForecastObs_UpdateValues_ReturnsExpected()
        {
            //Create needed objects
            ListBox lb = new ListBox();
            WeatherSubject ws = new WeatherSubject();
            ForeCastObserver fcObs = new ForeCastObserver(lb,ws);

            //Update tobs with some values
            fcObs.Update(1, 1, 1);

            //Just test on temperature, for full code coverage id need:
            //~3 tests to cover each branch of temperature-related strings
            //*3 for the amount of forecast options (temp,humid,baro)
            string expected = "Nippy";
            string actual = fcObs.Temp;

            Assert.AreEqual(expected, actual);
        }
예제 #8
0
        public void ObserverList_AddObserver_ReturnsExpected()
        {
            //Create needed objects
            ListBox lb = new ListBox();
            WeatherSubject ws = new WeatherSubject();
            List<IWeatherObserver> obList = new List<IWeatherObserver>();

            //Make 2 observers, do not manually add these
            //Their ctor adds them to the passed subject
            ForeCastObserver fcObs1 = new ForeCastObserver(lb, ws);
            ForeCastObserver fcObs2 = new ForeCastObserver(lb, ws);

            //Expected size of list
            int expected = 2;
            int actual = ws.ObsList.Count;

            //Check observer was added to observer list properly
            Assert.AreEqual(expected, actual);
        }
예제 #9
0
        public void ObserverList_RemoveObserver_ReturnsExpected()
        {
            //Create needed objects
            ListBox lb = new ListBox();
            WeatherSubject ws = new WeatherSubject();
            List<IWeatherObserver> obList = new List<IWeatherObserver>();

            //Make 2 observers, do not manually add these
            //Their ctor adds them to the passed subject
            ForeCastObserver fcObs1 = new ForeCastObserver(lb, ws);
            ForeCastObserver fcObs2 = new ForeCastObserver(lb, ws);

            //Remove one from the list, decoupling the observer
            //this makes it essentially inactive
            ws.RemoveObserver(fcObs2);

            //Expected size of list
            int expected = 1;
            int actual = ws.ObsList.Count;

            //Check observer was added to observer list properly
            Assert.AreEqual(expected, actual);
        }
예제 #10
0
 public CurrentObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
 }
예제 #11
0
 public ForecastObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
 }
예제 #12
0
 public AveragesObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
     measureList = new List <Measurements>();
 }
예제 #13
0
 public AveragesObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
     measureList = new List<Measurements>();
 }
예제 #14
0
 //Constructor
 public CurrentObserver(ListBox lb, WeatherSubject subject)
     : base(lb, subject)
 {
 }
예제 #15
0
 public ForecastObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
 }
예제 #16
0
 public CurrentObserver(WeatherSubject weatherSubject)
     : base(weatherSubject)
 {
 }
예제 #17
0
 //Constructor
 public ForecastObserver(ListBox lb, WeatherSubject subject)
     : base(lb, subject)
 {
     weatherStr = "";
 }