public void CheckChange0Inserted()
        {
            string doc =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>20</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>50</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>10</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>20</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>10</Ammount>
              </Coin>
              </Root>";
            CoinManager coinMan = new CoinManager(XDocument.Parse(doc));

                bool result = coinMan.CheckChange(0, 0);
                Assert.IsTrue(result);
        }
示例#2
0
 public void AddCoin761()
 {
     CoinManager coinManager;
     coinManager = new CoinManager();
     this.AddCoin(coinManager, Coin.Kr2, 2);
     Assert.IsNotNull((object)coinManager);
 }
示例#3
0
 public void AddCoin911()
 {
     CoinManager coinManager;
     coinManager = new CoinManager();
     this.AddCoin(coinManager, Coin.Ore50, 1);
     Assert.IsNotNull((object)coinManager);
 }
示例#4
0
文件: Form1.cs 项目: haljin/robust
        public Form1()
        {
            InitializeComponent();
            machine = new VendMachine();
            prepareOutOfStockLights();

            CoinManager coins = new CoinManager();
            coins.EjectCoin(Coin.Ore50, 1, new LinkedList<Coin>());
        }
示例#5
0
 public VendMachine(XDocument stockDoc, XDocument coinDoc)
 {
     state = State.Idle;
     StockMan = new StockManager(stockDoc);
     CoinMan = new CoinManager(coinDoc);
     SelectedProduct = null;
     InsertedValue = 0;
     CoinCase = new LinkedList<Coin>();
     ProductCase = new LinkedList<Product>();
 }
示例#6
0
 public VendMachine()
 {
     state = State.Idle;
     StockMan = new StockManager();
     CoinMan = new CoinManager();
     SelectedProduct = null;
     InsertedValue = 0;
     CoinCase = new LinkedList<Coin>();
     ProductCase = new LinkedList<Product>();
 }
示例#7
0
 // Scenario: Database is null
 // Expected outcome: Constructor throws exception
 public void ConstructorTest2()
 {
     string doc = null;
     try
     {
         CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
         Assert.Fail();
     }
     catch (Exception)
     { }
 }
 public void EjectCoin502()
 {
     CoinManager coinManager;
     LinkedList<Coin> linkedList;
     LinkedList<Coin> linkedList1;
     coinManager = new CoinManager();
     Coin[] @is = new Coin[0];
     linkedList = new LinkedList<Coin>((IEnumerable<Coin>)@is);
     linkedList1 = new LinkedList<Coin>((IEnumerable<Coin>)linkedList);
     this.EjectCoin(coinManager, Coin.Ore50, 1, linkedList1);
     Assert.IsNotNull((object)coinManager);
 }
示例#9
0
 public void ConstructorTest()
 {
     string doc =
         @"<?xml version=""1.0"" encoding=""utf-8"" ?>
     <Root>
     </Root>";
     try
     {
         CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
         Assert.Fail();
     }
     catch (Exception)
     { }
 }
示例#10
0
 public void AddCoinThrowsContractException830()
 {
     try
     {
         CoinManager coinManager;
         coinManager = new CoinManager();
         this.AddCoin(coinManager, Coin.Ore50, 0);
         throw
           new AssertFailedException("expected an exception of type ContractException");
     }
     catch (Exception ex)
     {
         if (!PexContract.IsContractException(ex))
             throw ex;
     }
 }
示例#11
0
        public void GetChangeCaseNull()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>10</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>1</Ammount>
              </Coin>
              </Root>";

             CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
             LinkedList<Coin> list = null;

             try
             {
                 coinMan.GiveChange(5, 5, list);
                 Assert.Fail();
             }
             catch (Exception)
             { }
        }
示例#12
0
        public void EjectCoinCaseNotEmpty()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>10</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";
            CoinManager coinMan = new CoinManager(XDocument.Parse(doc));

            LinkedList<Coin> linkedList = new LinkedList<Coin>();
            linkedList.AddLast(Coin.Kr1);
            linkedList.AddLast(Coin.Kr1);

            coinMan.EjectCoin(Coin.Kr1, 2, linkedList);

            Assert.IsNotNull(coinMan);
        }
 public void CheckChangeIncorrectPrice()
 {
     string doc =
     @"<?xml version=""1.0"" encoding=""utf-8"" ?>
     <Root>
       <Coin>
         <Type>0.5</Type>
         <Ammount>20</Ammount>
       </Coin>
       <Coin>
         <Type>1</Type>
         <Ammount>50</Ammount>
       </Coin>
       <Coin>
         <Type>2</Type>
         <Ammount>10</Ammount>
       </Coin>
       <Coin>
         <Type>5</Type>
         <Ammount>20</Ammount>
       </Coin>
       <Coin>
         <Type>10</Type>
         <Ammount>0</Ammount>
       </Coin>
       <Coin>
         <Type>20</Type>
         <Ammount>10</Ammount>
       </Coin>
       </Root>";
     CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
     try
     {
         bool result = coinMan.CheckChange(-10, 9);
         Assert.Fail();
     }
     catch (Exception)
     { }
 }
示例#14
0
        public void GetChangeCorrect()
        {
            string doc =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>20</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";

            CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
            LinkedList<Coin> list = new LinkedList<Coin>();

            coinMan.GiveChange(10, 20,list);

            decimal sum=0;
            foreach (Coin elem in list)
            {
               sum += elem.ToValue();
            }
            Assert.AreEqual(10, sum);
        }
示例#15
0
 public void EjectCoinThrowsContractException868()
 {
     try
     {
         CoinManager coinManager;
         coinManager = new CoinManager();
         this.EjectCoin(coinManager, Coin.Ore50, 1, (LinkedList<Coin>)null);
         throw
           new AssertFailedException("expected an exception of type ContractException");
     }
     catch (Exception ex)
     {
         if (!PexContract.IsContractException(ex))
             throw ex;
     }
 }
        public void CheckChangeNotEnoughSmallCoins()
        {
            string doc =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>1</Ammount>
              </Coin>
              </Root>";
            CoinManager coinMan = new CoinManager(XDocument.Parse(doc));

            bool result = coinMan.CheckChange(1, 10);

            Assert.IsFalse(result);
        }
示例#17
0
        public void EjectCoinNotEnoughCoins()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>1</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";
            CoinManager coinMan = new CoinManager(XDocument.Parse(doc));
            LinkedList<Coin> linkedList = new LinkedList<Coin>();

            try
            {
                coinMan.EjectCoin(Coin.Kr1, 2, linkedList);
                Assert.Fail();
            }
            catch (Exception)
            { }
        }