Example #1
0
 private void AppendBag(Monedero aBag)
 {
     foreach (Moneda m in aBag.fMonies)
     {
         AppendMoney(m);
     }
 }
Example #2
0
        public override bool Equals(Object anObject)
        {
            if (EnCeros)
            {
                if (anObject is IMoneda)
                {
                    return(((IMoneda)anObject).EnCeros);
                }
            }

            if (anObject is Monedero)
            {
                Monedero aMoneyBag = (Monedero)anObject;
                if (aMoneyBag.fMonies.Count != fMonies.Count)
                {
                    return(false);
                }

                foreach (Moneda m in fMonies)
                {
                    if (!aMoneyBag.Contains(m))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Example #3
0
        public void BagSimpleAdd()
        {
            // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]}
            Moneda[] bag      = { new Moneda(26, Divisa.CHF), new Moneda(7, Divisa.USD) };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _monedero1.Agregar(_moneda14CHF));
        }
Example #4
0
        public void BagSumAdd()
        {
            // {[12 CHF][7 USD]} + {[14 CHF][21 USD]} == {[26 CHF][28 USD]}
            Moneda[] bag      = { new Moneda(26, Divisa.CHF), new Moneda(28, Divisa.USD) };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _monedero1.Agregar(_monedero2));
        }
Example #5
0
        public void BagSubtract()
        {
            // {[12 CHF][7 USD]} - {[14 CHF][21 USD] == {[-2 CHF][-14 USD]}
            Moneda[] bag      = { new Moneda(-2, Divisa.CHF), new Moneda(-14, Divisa.USD) };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _monedero1.Restar(_monedero2));
        }
Example #6
0
        public void BagNegate()
        {
            // {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]}
            Moneda[] bag      = { new Moneda(-12, Divisa.CHF), new Moneda(-7, Divisa.USD) };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _monedero1.Negar());
        }
Example #7
0
        public void MixedSimpleAdd()
        {
            // [12 CHF] + [7 USD] == {[12 CHF][7 USD]}
            Moneda[] bag      = { _moneda12CHF, _moneda7USD };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _moneda12CHF.Agregar(_moneda7USD));
        }
Example #8
0
        public void Normalize4()
        {
            // [12 CHF] - {[12 CHF][3 USD]} == [-3 USD]
            Moneda[] s1       = { new Moneda(12, Divisa.CHF), new Moneda(3, Divisa.USD) };
            Monedero ms1      = new Monedero(s1);
            Moneda   expected = new Moneda(-3, Divisa.USD);

            Assert.AreEqual(expected, _moneda12CHF.Restar(ms1));
        }
Example #9
0
        public void Normalize3()
        {
            // {[12 CHF][7 USD]} - {[12 CHF][3 USD]} == [4 USD]
            Moneda[] s1       = { new Moneda(12, Divisa.CHF), new Moneda(3, Divisa.USD) };
            Monedero ms1      = new Monedero(s1);
            Moneda   expected = new Moneda(4, Divisa.USD);

            Assert.AreEqual(expected, _monedero1.Restar(ms1));
        }
Example #10
0
        public void BagMultiply()
        {
            // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]}
            Moneda[] bag      = { new Moneda(24, Divisa.CHF), new Moneda(14, Divisa.USD) };
            Monedero expected = new Monedero(bag);

            Assert.AreEqual(expected, _monedero1.Multiplicar(2));
            Assert.AreEqual(_monedero1, _monedero1.Multiplicar(1));
            Assert.IsTrue(_monedero1.Multiplicar(0).EnCeros);
        }
Example #11
0
        protected void SetUp()
        {
            _moneda12CHF = new Moneda(12, Divisa.CHF);
            _moneda14CHF = new Moneda(14, Divisa.CHF);
            _moneda7USD  = new Moneda(7, Divisa.USD);
            _moneda21USD = new Moneda(21, Divisa.USD);

            _monedero1 = new Monedero(_moneda12CHF, _moneda7USD);
            _monedero2 = new Monedero(_moneda14CHF, _moneda21USD);
        }
Example #12
0
        public IMoneda Negar()
        {
            Monedero result = new Monedero();

            foreach (Moneda m in fMonies)
            {
                result.AppendMoney((Moneda)m.Negar());
            }
            return(result);
        }
Example #13
0
        public void Normalize()
        {
            Moneda[] bag      = { new Moneda(26, Divisa.CHF), new Moneda(28, Divisa.CHF), new Moneda(6, Divisa.CHF) };
            Monedero Monedero = new Monedero(bag);

            Moneda[] expected = { new Moneda(60, Divisa.CHF) };
            // note: expected is still a Monedero
            Monedero expectedBag = new Monedero(expected);

            Assert.AreEqual(expectedBag, Monedero);
        }
Example #14
0
        public IMoneda Multiplicar(int factor)
        {
            Monedero result = new Monedero();

            if (factor != 0)
            {
                foreach (Moneda m in fMonies)
                {
                    result.AppendMoney((Moneda)m.Multiplicar(factor));
                }
            }
            return(result);
        }
Example #15
0
        public void MonederoEquals()
        {
            //NOTE: Normally we use Assert.AreEqual to test whether two
            // objects are equal. But here we are testing the Monedero.Equals()
            // method itself, so using AreEqual would not serve the purpose.
            Assert.IsFalse(_monedero1.Equals(null));

            Assert.IsTrue(_monedero1.Equals(_monedero1));
            Monedero equal = new Monedero(new Moneda(12, Divisa.CHF), new Moneda(7, Divisa.USD));

            Assert.IsTrue(_monedero1.Equals(equal));
            Assert.IsTrue(!_monedero1.Equals(_moneda12CHF));
            Assert.IsTrue(!_moneda12CHF.Equals(_monedero1));
            Assert.IsTrue(!_monedero1.Equals(_monedero2));
        }
Example #16
0
 public IMoneda AgregarMonedero(Monedero s)
 {
     return((new Monedero(s, this)).Simplify());
 }
Example #17
0
 public Monedero(Monedero m1, Monedero m2)
 {
     AppendBag(m1);
     AppendBag(m2);
 }
Example #18
0
 public Monedero(Moneda m, Monedero bag)
 {
     AppendMoney(m);
     AppendBag(bag);
 }
Example #19
0
        public void MonederoHash()
        {
            Monedero equal = new Monedero(new Moneda(12, Divisa.CHF), new Moneda(7, Divisa.USD));

            Assert.AreEqual(_monedero1.GetHashCode(), equal.GetHashCode());
        }
Example #20
0
 public IMoneda AgregarMonedero(Monedero s)
 {
     return(s.AgregarMoneda(this));
 }