Example #1
0
        public void makeSubscription(int car)
        {
            Contract.Requires(car != 0);
            //Cars can't have two subscriptions and the list needs room to add cars...

            //For all subscribers, none can equal the car
            Contract.Requires(Contract.ForAll(0, SubscriberList.Length, i => !SubscriberList[i].Equals(car)), ": That car is already subscribed.");
            Contract.Requires(SubscriberList.Contains(0), ": No more space on the subsciber list");

            Contract.Ensures(SubscriberList.Contains(car));
            Contract.Ensures(Contract.ForAll(0, SubscriberList.Length, i => SubscriberList[i].Equals(Contract.OldValue(SubscriberList[i])) ||
                                             SubscriberList[i].Equals(car)));
        }
Example #2
0
        public void enterReservedArea(int car)
        {
            Contract.Requires(car != 0, ": The car can't be 0");
            Contract.Requires(car < 1000, ": The car can't be greater than 999");

            //The car needs a subscription and the car park can't contain duplicates..
            Contract.Requires(SubscriberList.Contains(car), ": The car doesn't have a subscription.");
            Contract.Requires(Contract.ForAll(0, Spaces.Length, i => !Spaces[i].Equals(car)), ": The car park can't contain duplicate cars.");

            Contract.Requires(CarParkIsOpen, ": The car park is closed");

            //Requires that the barrier is down and the number of remaining spaces is equal to the number of cars that are
            //subscribed to a reserved space.
            //OR
            //The the car park isn't full.
            Contract.Requires(BarrierIsOpen == false && Spaces.Length - NumberParked - IDIOT_SPACES >= SubscriberList.Length ||
                              Spaces.Length - NumberParked - IDIOT_SPACES - SubscribersParked > 0, ": The car park is full.");

            //Ensures that the array contains the car and that the rest of the array is unchanged.
            Contract.Ensures(Spaces.Contains(car));
            Contract.Ensures(Contract.ForAll(0, Spaces.Length, i => Spaces[i].Equals(Contract.OldValue(Spaces[i])) ||
                                             Spaces[i].Equals(car)));
        }