Beispiel #1
0
        public void MoneyHash()
        {
            Assert.IsFalse(_moneda12CHF.Equals(null));
            Moneda equal = new Moneda(12, Divisa.CHF);

            Assert.AreEqual(_moneda12CHF.GetHashCode(), equal.GetHashCode());
        }
Beispiel #2
0
        public void SimpleSubtract()
        {
            // [14 CHF] - [12 CHF] == [2 CHF]
            Moneda expected = new Moneda(2, Divisa.CHF);

            Assert.AreEqual(expected, _moneda14CHF.Restar(_moneda12CHF));
        }
Beispiel #3
0
        public void SimpleNegate()
        {
            // [14 CHF] negate == [-14 CHF]
            Moneda expected = new Moneda(-14, Divisa.CHF);

            Assert.AreEqual(expected, _moneda14CHF.Negar());
        }
Beispiel #4
0
        public void SimpleAdd()
        {
            // [12 CHF] + [14 CHF] == [26 CHF]
            Moneda expected = new Moneda(26, Divisa.CHF);

            Assert.AreEqual(expected, _moneda12CHF.Agregar(_moneda14CHF));
        }
Beispiel #5
0
        public void SimpleMultiply()
        {
            // [14 CHF] *2 == [28 CHF]
            Moneda expected = new Moneda(28, Divisa.CHF);

            Assert.AreEqual(expected, _moneda14CHF.Multiplicar(2));
        }
Beispiel #6
0
        public void Normalize2()
        {
            // {[12 CHF][7 USD]} - [12 CHF] == [7 USD]
            Moneda expected = new Moneda(7, Divisa.USD);

            Assert.AreEqual(expected, _monedero1.Restar(_moneda12CHF));
        }
Beispiel #7
0
 public IMoneda AgregarMoneda(Moneda m)
 {
     if (m.Divisa.Equals(Divisa))
     {
         return(new Moneda(Cantidad + m.Cantidad, Divisa));
     }
     return(new Monedero(this, m));
 }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public void MoneyEquals()
        {
            //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(_moneda12CHF.Equals(null));
            Moneda equalMoney = new Moneda(12, Divisa.CHF);

            Assert.IsTrue(_moneda12CHF.Equals(_moneda12CHF));
            Assert.IsTrue(_moneda12CHF.Equals(equalMoney));
            Assert.IsFalse(_moneda12CHF.Equals(_moneda14CHF));
        }
Beispiel #12
0
 public override bool Equals(Object anObject)
 {
     if (EnCeros)
     {
         if (anObject is IMoneda)
         {
             return(((IMoneda)anObject).EnCeros);
         }
     }
     if (anObject is Moneda)
     {
         Moneda aMoney = (Moneda)anObject;
         return(aMoney.Divisa.Equals(Divisa) &&
                Cantidad == aMoney.Cantidad);
     }
     return(false);
 }
Beispiel #13
0
        private void AppendMoney(Moneda aMoney)
        {
            IMoneda old = FindMoney(aMoney.Divisa);

            if (old == null)
            {
                fMonies.Add(aMoney);
                return;
            }
            fMonies.Remove(old);
            IMoneda sum = old.Agregar(aMoney);

            if (sum.EnCeros)
            {
                return;
            }
            fMonies.Add(sum);
        }
Beispiel #14
0
        private bool Contains(Moneda aMoney)
        {
            Moneda m = FindMoney(aMoney.Divisa);

            return(m.Cantidad == aMoney.Cantidad);
        }
Beispiel #15
0
 public IMoneda AgregarMoneda(Moneda m)
 {
     return((new Monedero(m, this)).Simplify());
 }
Beispiel #16
0
 public Monedero(Moneda m, Monedero bag)
 {
     AppendMoney(m);
     AppendBag(bag);
 }
Beispiel #17
0
 public Monedero(Moneda m1, Moneda m2)
 {
     AppendMoney(m1);
     AppendMoney(m2);
 }