//-------------------------------------------------------------------------
        public virtual void test_equals_hashCode()
        {
            CurrencyPair a1 = CurrencyPair.of(AUD, GBP);
            CurrencyPair a2 = CurrencyPair.of(AUD, GBP);
            CurrencyPair b  = CurrencyPair.of(USD, GBP);
            CurrencyPair c  = CurrencyPair.of(USD, EUR);

            assertEquals(a1.Equals(a1), true);
            assertEquals(a1.Equals(a2), true);
            assertEquals(a1.Equals(b), false);
            assertEquals(a1.Equals(c), false);

            assertEquals(b.Equals(a1), false);
            assertEquals(b.Equals(a2), false);
            assertEquals(b.Equals(b), true);
            assertEquals(b.Equals(c), false);

            assertEquals(c.Equals(a1), false);
            assertEquals(c.Equals(a2), false);
            assertEquals(c.Equals(b), false);
            assertEquals(c.Equals(c), true);

            assertEquals(a1.GetHashCode(), a2.GetHashCode());
        }
        //-------------------------------------------------------------------------
        public virtual void test_cross_CurrencyPair()
        {
            CurrencyPair gbpGbp = CurrencyPair.of(GBP, GBP);
            CurrencyPair gbpUsd = CurrencyPair.of(GBP, USD);
            CurrencyPair usdGbp = CurrencyPair.of(USD, GBP);
            CurrencyPair eurGbp = CurrencyPair.of(EUR, GBP);
            CurrencyPair eurUsd = CurrencyPair.of(EUR, USD);
            CurrencyPair usdEur = CurrencyPair.of(USD, EUR);

            assertEquals(gbpUsd.cross(gbpUsd), null);
            assertEquals(gbpUsd.cross(usdGbp), null);
            assertEquals(gbpGbp.cross(gbpUsd), null);
            assertEquals(gbpUsd.cross(gbpGbp), null);

            assertEquals(gbpUsd.cross(usdEur), eurGbp);
            assertEquals(gbpUsd.cross(eurUsd), eurGbp);
            assertEquals(usdGbp.cross(usdEur), eurGbp);
            assertEquals(usdGbp.cross(eurUsd), eurGbp);

            assertEquals(usdEur.cross(gbpUsd), eurGbp);
            assertEquals(usdEur.cross(usdGbp), eurGbp);
            assertEquals(eurUsd.cross(gbpUsd), eurGbp);
            assertEquals(eurUsd.cross(usdGbp), eurGbp);
        }
 //-----------------------------------------------------------------------
 public virtual void test_serialization()
 {
     assertSerialization(CurrencyPair.of(GBP, USD));
     assertSerialization(CurrencyPair.of(GBP, GBP));
 }
        public virtual void test_cross_CurrencyPair_null()
        {
            CurrencyPair test = CurrencyPair.of(GBP, USD);

            assertThrowsIllegalArg(() => test.cross(null));
        }
예제 #5
0
 public virtual void test_of_CurrencyPairDouble_invalid()
 {
     assertThrowsIllegalArg(() => FxRate.of(CurrencyPair.of(GBP, USD), -1.5d));
     assertThrowsIllegalArg(() => FxRate.of(CurrencyPair.of(USD, USD), 2d));
 }
        public virtual void test_isInverse_CurrencyPair_null()
        {
            CurrencyPair test = CurrencyPair.of(GBP, USD);

            assertThrowsIllegalArg(() => test.isInverse(null));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "parseBad", expectedExceptions = IllegalArgumentException.class) public void test_parse_String_bad(String input)
        public virtual void test_parse_String_bad(string input)
        {
            CurrencyPair.parse(input);
        }
예제 #8
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance from two currencies.
 /// <para>
 /// The first currency is the base and the second is the counter.
 /// The two currencies may be the same, but if they are then the rate must be one.
 ///
 /// </para>
 /// </summary>
 /// <param name="base">  the base currency </param>
 /// <param name="counter">  the counter currency </param>
 /// <param name="rate">  the conversion rate, greater than zero </param>
 /// <returns> the FX rate </returns>
 /// <exception cref="IllegalArgumentException"> if the rate is invalid </exception>
 public static FxRate of(Currency @base, Currency counter, double rate)
 {
     return(new FxRate(CurrencyPair.of(@base, counter), rate));
 }
        public virtual void streamPairsToMatrix()
        {
            // If we obtain a stream of pairs with rates we can stream them
            // This could happen if an entry set undergoes a map operation

            IDictionary <CurrencyPair, double> rates = ImmutableMap.builder <CurrencyPair, double>().put(CurrencyPair.of(GBP, USD), 1.6).put(CurrencyPair.of(EUR, USD), 1.4).put(CurrencyPair.of(CHF, AUD), 1.2).put(CurrencyPair.of(SEK, AUD), 0.1).put(CurrencyPair.of(JPY, CAD), 0.0).put(CurrencyPair.of(EUR, CHF), 1.2).put(CurrencyPair.of(JPY, USD), 0.008).build();

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            FxMatrix matrix = rates.SetOfKeyValuePairs().Select(e => Pair.of(e.Key, e.Value * 1.01)).collect(pairsToFxMatrix());

            assertThat(matrix.fxRate(GBP, USD)).isEqualTo(1.616);
            assertThat(matrix.fxRate(EUR, USD)).isEqualTo(1.414);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "parseGood") public void test_parse_String_good(String input, Currency super, Currency counter)
        public virtual void test_parse_String_good(string input, Currency @base, Currency counter)
        {
            assertEquals(CurrencyPair.parse(input), CurrencyPair.of(@base, counter));
        }
        public virtual void streamEntriesToMatrix()
        {
            // If we obtain a stream of rates we can collect to an fx matrix
            IDictionary <CurrencyPair, double> rates = ImmutableMap.builder <CurrencyPair, double>().put(CurrencyPair.of(GBP, USD), 1.6).put(CurrencyPair.of(EUR, USD), 1.4).put(CurrencyPair.of(CHF, AUD), 1.2).put(CurrencyPair.of(SEK, AUD), 0.1).put(CurrencyPair.of(JPY, CAD), 0.0).put(CurrencyPair.of(EUR, CHF), 1.2).put(CurrencyPair.of(JPY, USD), 0.008).build();

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            FxMatrix matrix = rates.SetOfKeyValuePairs().collect(entriesToFxMatrix());

            assertThat(matrix.fxRate(GBP, USD)).isEqualTo(1.6);
            assertThat(matrix.fxRate(EUR, USD)).isEqualTo(1.4);
        }
예제 #12
0
 /// <summary>
 /// Checks if this currency pair is the inverse of the specified pair.
 /// <para>
 /// This could be used to check if an FX rate specified in one currency pair needs inverting.
 ///
 /// </para>
 /// </summary>
 /// <param name="other">  the other currency pair </param>
 /// <returns> true if the currency is the inverse of the specified pair </returns>
 public bool isInverse(CurrencyPair other)
 {
     ArgChecker.notNull(other, "currencyPair");
     return(@base.Equals(other.counter) && counter.Equals(other.@base));
 }
예제 #13
0
 /// <summary>
 /// Obtains an instance containing a single FX rate.
 /// <para>
 /// This is most likely to be used in testing.
 /// </para>
 /// <para>
 /// An invocation of the method with {@code FxMatrix.of(CurrencyPair.of(GBP, USD), 1.6)}
 /// indicates that 1 pound sterling is worth 1.6 US dollars.
 /// The matrix can also be queried for the reverse rate, from USD to GBP.
 ///
 /// </para>
 /// </summary>
 /// <param name="currencyPair">  the currency pair to be added </param>
 /// <param name="rate">  the FX rate between the base currency of the pair and the
 ///   counter currency. The rate indicates the value of one unit of the base
 ///   currency in terms of the counter currency. </param>
 /// <returns> a matrix containing the single FX rate </returns>
 public static FxMatrix of(CurrencyPair currencyPair, double rate)
 {
     return(FxMatrix.of(currencyPair.Base, currencyPair.Counter, rate));
 }
 public virtual void test_jodaConvert()
 {
     assertJodaConvert(typeof(CurrencyPair), CurrencyPair.of(GBP, USD));
     assertJodaConvert(typeof(CurrencyPair), CurrencyPair.of(GBP, GBP));
 }
        public virtual void test_inverse_same()
        {
            CurrencyPair test = CurrencyPair.of(GBP, GBP);

            assertEquals(test.inverse(), CurrencyPair.of(GBP, GBP));
        }
 public virtual void test_of_CurrencyCurrency_null()
 {
     assertThrowsIllegalArg(() => CurrencyPair.of(null, USD));
     assertThrowsIllegalArg(() => CurrencyPair.of(USD, null));
     assertThrowsIllegalArg(() => CurrencyPair.of(null, null));
 }
        public virtual void test_other_Currency_null()
        {
            CurrencyPair test = CurrencyPair.of(GBP, USD);

            assertThrowsIllegalArg(() => test.other(null));
        }
예제 #18
0
 /// <summary>
 /// Obtains an instance from a currency pair.
 /// <para>
 /// The two currencies may be the same, but if they are then the rate must be one.
 ///
 /// </para>
 /// </summary>
 /// <param name="pair">  the currency pair </param>
 /// <param name="rate">  the conversion rate, greater than zero </param>
 /// <returns> the FX rate </returns>
 /// <exception cref="IllegalArgumentException"> if the rate is invalid </exception>
 public static FxRate of(CurrencyPair pair, double rate)
 {
     return(new FxRate(pair, rate));
 }
예제 #19
0
 /// <summary>
 /// Adds a new rate for a currency pair to the builder. See
 /// <seealso cref="#addRate(Currency, Currency, double)"/> for full
 /// explanation.
 /// </summary>
 /// <param name="currencyPair">  the currency pair to be added </param>
 /// <param name="rate">  the FX rate between the base currency of the pair and the
 ///   counter currency. The rate indicates the value of one unit of the base
 ///   currency in terms of the counter currency. </param>
 /// <returns> the builder updated with the new rate </returns>
 public virtual FxMatrixBuilder addRate(CurrencyPair currencyPair, double rate)
 {
     ArgChecker.notNull(currencyPair, "currencyPair");
     return(addRate(currencyPair.Base, currencyPair.Counter, rate));
 }