public void testCurrencies() { CHFCurrency chf = new CHFCurrency(); EURCurrency euro = new EURCurrency(); CHFCurrency chf2 = new CHFCurrency(); Assert.IsTrue(chf.Name == "Swiss franc"); Assert.IsTrue(chf.code == "CHF"); Assert.AreEqual(chf.numericCode, 756); Assert.AreEqual(chf.symbol, "SwF"); Assert.AreEqual(chf.fractionSymbol, string.Empty); Assert.AreEqual(chf.fractionsPerUnit, 100); Assert.AreEqual(chf.rounding.getType, Rounding.Type.None); Assert.IsInstanceOfType(chf.triangulationCurrency, typeof(Currency)); Assert.IsTrue(chf.triangulationCurrency.IsEmpty); Assert.IsFalse(euro == chf); Assert.IsTrue(euro != chf); Assert.IsFalse(chf2 != chf); Assert.IsTrue(chf2 == chf); }
public void testSmartLookup() { Currency EUR = new EURCurrency(), USD = new USDCurrency(), GBP = new GBPCurrency(), CHF = new CHFCurrency(), SEK = new SEKCurrency(), JPY = new JPYCurrency(); ExchangeRateManager rateManager = ExchangeRateManager.Instance; rateManager.clear(); ExchangeRate eur_usd1 = new ExchangeRate(EUR, USD, 1.1983); ExchangeRate eur_usd2 = new ExchangeRate(USD, EUR, 1.0 / 1.2042); rateManager.add(eur_usd1, new Date(4, Month.August, 2004)); rateManager.add(eur_usd2, new Date(5, Month.August, 2004)); ExchangeRate eur_gbp1 = new ExchangeRate(GBP, EUR, 1.0 / 0.6596); ExchangeRate eur_gbp2 = new ExchangeRate(EUR, GBP, 0.6612); rateManager.add(eur_gbp1, new Date(4, Month.August, 2004)); rateManager.add(eur_gbp2, new Date(5, Month.August, 2004)); ExchangeRate usd_chf1 = new ExchangeRate(USD, CHF, 1.2847); ExchangeRate usd_chf2 = new ExchangeRate(CHF, USD, 1.0 / 1.2774); rateManager.add(usd_chf1, new Date(4, Month.August, 2004)); rateManager.add(usd_chf2, new Date(5, Month.August, 2004)); ExchangeRate chf_sek1 = new ExchangeRate(SEK, CHF, 0.1674); ExchangeRate chf_sek2 = new ExchangeRate(CHF, SEK, 1.0 / 0.1677); rateManager.add(chf_sek1, new Date(4, Month.August, 2004)); rateManager.add(chf_sek2, new Date(5, Month.August, 2004)); ExchangeRate jpy_sek1 = new ExchangeRate(SEK, JPY, 14.5450); ExchangeRate jpy_sek2 = new ExchangeRate(JPY, SEK, 1.0 / 14.6110); rateManager.add(jpy_sek1, new Date(4, Month.August, 2004)); rateManager.add(jpy_sek2, new Date(5, Month.August, 2004)); Money m1 = 100000.0 * USD; Money m2 = 100000.0 * EUR; Money m3 = 100000.0 * GBP; Money m4 = 100000.0 * CHF; Money m5 = 100000.0 * SEK; Money m6 = 100000.0 * JPY; Money.conversionType = Money.ConversionType.NoConversion; // two-rate chain ExchangeRate usd_sek = rateManager.lookup(USD, SEK, new Date(4, Month.August, 2004)); Money calculated = usd_sek.exchange(m1); Money expected = new Money(m1.value * usd_chf1.rate / chf_sek1.rate, SEK); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } usd_sek = rateManager.lookup(SEK, USD, new Date(5, Month.August, 2004)); calculated = usd_sek.exchange(m5); expected = new Money(m5.value * usd_chf2.rate / chf_sek2.rate, USD); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // three-rate chain ExchangeRate eur_sek = rateManager.lookup(EUR, SEK, new Date(4, Month.August, 2004)); calculated = eur_sek.exchange(m2); expected = new Money(m2.value * eur_usd1.rate * usd_chf1.rate / chf_sek1.rate, SEK); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } eur_sek = rateManager.lookup(SEK, EUR, new Date(5, Month.August, 2004)); calculated = eur_sek.exchange(m5); expected = new Money(m5.value * eur_usd2.rate * usd_chf2.rate / chf_sek2.rate, EUR); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // four-rate chain ExchangeRate eur_jpy = rateManager.lookup(EUR, JPY, new Date(4, Month.August, 2004)); calculated = eur_jpy.exchange(m2); expected = new Money(m2.value * eur_usd1.rate * usd_chf1.rate * jpy_sek1.rate / chf_sek1.rate, JPY); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } eur_jpy = rateManager.lookup(JPY, EUR, new Date(5, Month.August, 2004)); calculated = eur_jpy.exchange(m6); expected = new Money(m6.value * jpy_sek2.rate * eur_usd2.rate * usd_chf2.rate / chf_sek2.rate, EUR); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // five-rate chain ExchangeRate gbp_jpy = rateManager.lookup(GBP, JPY, new Date(4, Month.August, 2004)); calculated = gbp_jpy.exchange(m3); expected = new Money(m3.value * eur_gbp1.rate * eur_usd1.rate * usd_chf1.rate * jpy_sek1.rate / chf_sek1.rate, JPY); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } gbp_jpy = rateManager.lookup(JPY, GBP, new Date(5, Month.August, 2004)); calculated = gbp_jpy.exchange(m6); expected = new Money(m6.value * jpy_sek2.rate * eur_usd2.rate * usd_chf2.rate * eur_gbp2.rate / chf_sek2.rate, GBP); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CHFCurrency obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public void testSmartLookup() { Currency EUR = new EURCurrency(), USD = new USDCurrency(), GBP = new GBPCurrency(), CHF = new CHFCurrency(), SEK = new SEKCurrency(), JPY = new JPYCurrency(); ExchangeRateManager rateManager = ExchangeRateManager.Instance; rateManager.clear(); ExchangeRate eur_usd1 = new ExchangeRate(EUR, USD, 1.1983); ExchangeRate eur_usd2 = new ExchangeRate(USD, EUR, 1.0/1.2042); rateManager.Add(eur_usd1, new Date(4,Month.August,2004)); rateManager.Add(eur_usd2, new Date(5,Month.August,2004)); ExchangeRate eur_gbp1 = new ExchangeRate(GBP, EUR, 1.0 / 0.6596); ExchangeRate eur_gbp2 = new ExchangeRate(EUR, GBP, 0.6612); rateManager.Add(eur_gbp1, new Date(4,Month.August,2004)); rateManager.Add(eur_gbp2, new Date(5,Month.August,2004)); ExchangeRate usd_chf1 = new ExchangeRate(USD, CHF, 1.2847); ExchangeRate usd_chf2 = new ExchangeRate(CHF, USD, 1.0 / 1.2774); rateManager.Add(usd_chf1, new Date(4,Month.August,2004)); rateManager.Add(usd_chf2, new Date(5,Month.August,2004)); ExchangeRate chf_sek1 = new ExchangeRate(SEK, CHF, 0.1674); ExchangeRate chf_sek2 = new ExchangeRate(CHF, SEK, 1.0 / 0.1677); rateManager.Add(chf_sek1, new Date(4,Month.August,2004)); rateManager.Add(chf_sek2, new Date(5,Month.August,2004)); ExchangeRate jpy_sek1 = new ExchangeRate(SEK, JPY, 14.5450); ExchangeRate jpy_sek2 = new ExchangeRate(JPY, SEK, 1.0 / 14.6110); rateManager.Add(jpy_sek1, new Date(4,Month.August,2004)); rateManager.Add(jpy_sek2, new Date(5,Month.August,2004)); Money m1 = 100000.0 * USD; Money m2 = 100000.0 * EUR; Money m3 = 100000.0 * GBP; Money m4 = 100000.0 * CHF; Money m5 = 100000.0 * SEK; Money m6 = 100000.0 * JPY; Money.conversionType = Money.ConversionType.NoConversion; // two-rate chain ExchangeRate usd_sek = rateManager.lookup(USD, SEK, new Date(4,Month.August,2004)); Money calculated = usd_sek.exchange(m1); Money expected = new Money(m1.value*usd_chf1.rate/chf_sek1.rate, SEK); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } usd_sek = rateManager.lookup(SEK, USD, new Date(5,Month.August,2004)); calculated = usd_sek.exchange(m5); expected = new Money(m5.value*usd_chf2.rate/chf_sek2.rate, USD); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // three-rate chain ExchangeRate eur_sek = rateManager.lookup(EUR, SEK,new Date(4,Month.August,2004)); calculated = eur_sek.exchange(m2); expected = new Money(m2.value*eur_usd1.rate*usd_chf1.rate/chf_sek1.rate, SEK); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } eur_sek = rateManager.lookup(SEK, EUR, new Date(5,Month.August,2004)); calculated = eur_sek.exchange(m5); expected = new Money(m5.value*eur_usd2.rate*usd_chf2.rate/chf_sek2.rate, EUR); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // four-rate chain ExchangeRate eur_jpy = rateManager.lookup(EUR, JPY,new Date(4,Month.August,2004)); calculated = eur_jpy.exchange(m2); expected = new Money(m2.value*eur_usd1.rate*usd_chf1.rate*jpy_sek1.rate/chf_sek1.rate, JPY); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } eur_jpy = rateManager.lookup(JPY, EUR, new Date(5,Month.August,2004)); calculated = eur_jpy.exchange(m6); expected = new Money(m6.value*jpy_sek2.rate*eur_usd2.rate*usd_chf2.rate/chf_sek2.rate, EUR); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } // five-rate chain ExchangeRate gbp_jpy = rateManager.lookup(GBP, JPY,new Date(4,Month.August,2004)); calculated = gbp_jpy.exchange(m3); expected = new Money(m3.value*eur_gbp1.rate*eur_usd1.rate*usd_chf1.rate*jpy_sek1.rate/chf_sek1.rate, JPY); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } gbp_jpy = rateManager.lookup(JPY, GBP, new Date(5,Month.August,2004)); calculated = gbp_jpy.exchange(m6); expected = new Money(m6.value*jpy_sek2.rate*eur_usd2.rate*usd_chf2.rate*eur_gbp2.rate/chf_sek2.rate, GBP); if (!Utils.close(calculated, expected)) { Assert.Fail("Wrong result: expected: " + expected + " calculated: " + calculated); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CHFCurrency obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }