コード例 #1
0
 //Constructor
 public AverageObserver(ListBox lb, WeatherSubject subject)
     : base(lb, subject)
 {
     // Initialise variables
     runningTemp     = 0;
     runningHumidity = 0;
     runningPressure = 0;
     avgCount        = 0;
 }
コード例 #2
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
ファイル: Form1.cs プロジェクト: dec-k/IN710-keigdl1
        public Form1()
        {
            InitializeComponent();

            //Instantiate sub+obs
            ws = new WeatherSubject();
            tObs = new TemperatureObserver(lbTemp, ws);
            aObs = new AverageObserver(lbAverages, ws);
            fObs = new ForeCastObserver(lbForecast, ws);
        }
コード例 #4
0
        //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
ファイル: UnitTest1.cs プロジェクト: dec-k/IN710-keigdl1
        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
ファイル: UnitTest1.cs プロジェクト: dec-k/IN710-keigdl1
        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
ファイル: UnitTest1.cs プロジェクト: dec-k/IN710-keigdl1
        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
ファイル: UnitTest1.cs プロジェクト: dec-k/IN710-keigdl1
        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 = "";
 }