Exemple #1
0
        public void ElementDivideRandom()
        {
            System.Random _rand = new System.Random();
            for (int i = 0; i < 100000; i++)   // Faire 100.000 tests aléatoires
            {
                int quantityStart    = _rand.Next(0, int.MaxValue);
                int quantityToRemove = _rand.Next(int.MinValue, int.MaxValue);

                ResourceElement elem1 = new ResourceElement(ResourceElement.ResourceType.Water, station, quantityStart, 200);
                ResourceElement elem2 = elem1.Split(quantityToRemove);

                if (quantityToRemove < 0)   // cas si qte impossible
                {
                    Assert.AreEqual(null, elem2);
                    Assert.AreEqual(quantityStart, elem1.Quantity);
                }
                else if (quantityToRemove > quantityStart)     //cas si qte trop grande
                {
                    Assert.AreEqual(null, elem2);
                    Assert.AreEqual(quantityStart, elem1.Quantity);
                }
                else if (quantityToRemove == quantityStart)         //cas si qte egale
                {
                    Assert.AreEqual(quantityStart, elem2.Quantity); // elem2 est une copie de elem1
                    Assert.AreEqual(0, elem1.Quantity);
                }
                else
                {
                    Assert.AreEqual(quantityToRemove, elem2.Quantity);
                    Assert.AreEqual(quantityStart - quantityToRemove, elem1.Quantity);
                }
            }
        }
Exemple #2
0
        public void ElementDivide()
        {
            //enlever 25 resource a elem1 pour creer elem2
            ResourceElement elem1 = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 200);
            ResourceElement elem2 = elem1.Split(25);

            Assert.AreEqual(25, elem2.Quantity);
            Assert.AreEqual(75, elem1.Quantity);
            Assert.AreEqual(ResourceElement.ResourceType.Water, elem2.Type);
            Assert.AreEqual(station, elem2.Station);
            Assert.AreEqual(200, elem2.DateProd);
        }
Exemple #3
0
        public void ElementDivideError()
        {
            ResourceElement elem1 = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 200);

            //cas si qte trop grande
            ResourceElement elem2 = elem1.Split(200);

            Assert.AreEqual(null, elem2);
            Assert.AreEqual(100, elem1.Quantity);

            //cas si qte impossible
            ResourceElement elem4 = elem1.Split(-1);

            Assert.AreEqual(null, elem4);
            Assert.AreEqual(100, elem1.Quantity);

            //cas si qte egale
            ResourceElement elem3 = elem1.Split(100);

            Assert.AreEqual(100, elem3.Quantity); // elem3 est une copie de elem1
            Assert.AreEqual(0, elem1.Quantity);
        }