public virtual void test_get() { MultiCurrencyAmount expected = MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.USD, 33), CurrencyAmount.of(Currency.EUR, 44)); assertThat(VALUES_ARRAY.get(2)).isEqualTo(expected); assertThrows(() => VALUES_ARRAY.get(3), typeof(System.IndexOutOfRangeException)); assertThrows(() => VALUES_ARRAY.get(-1), typeof(System.IndexOutOfRangeException)); }
public virtual void test_stream() { IList <MultiCurrencyAmount> expected = ImmutableList.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 20), CurrencyAmount.of(Currency.USD, 30), CurrencyAmount.of(Currency.EUR, 40)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.USD, 32), CurrencyAmount.of(Currency.EUR, 43)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.USD, 33), CurrencyAmount.of(Currency.EUR, 44))); assertThat(VALUES_ARRAY.ToList()).isEqualTo(expected); }
/// <summary> /// Returns a stream of the amounts. /// </summary> /// <returns> a stream of the amounts </returns> public Stream <CurrencyAmount> stream() { return(values.stream().mapToObj(amount => CurrencyAmount.of(currency, amount))); }
public virtual void test_of_map() { MultiCurrencyAmountArray array = MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21, 22), Currency.EUR, DoubleArray.of(40, 43, 44))); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(ImmutableList.of(MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 20), CurrencyAmount.of(Currency.EUR, 40)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 21), CurrencyAmount.of(Currency.EUR, 43)), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.GBP, 22), CurrencyAmount.of(Currency.EUR, 44)))); assertThat(array.size()).isEqualTo(3); assertThat(array).isEqualTo(expected); assertThrowsIllegalArg(() => MultiCurrencyAmountArray.of(ImmutableMap.of(Currency.GBP, DoubleArray.of(20, 21), Currency.EUR, DoubleArray.of(40, 43, 44))), "Arrays must have the same size.*"); MultiCurrencyAmountArray empty = MultiCurrencyAmountArray.of(ImmutableMap.of()); assertThat(empty.size()).isEqualTo(0); }
/// <summary> /// Obtains an instance representing an amount where the date is fixed. /// <para> /// Whether the payment is pay or receive is determined by the sign of the specified amount. /// /// </para> /// </summary> /// <param name="value"> the amount of the payment </param> /// <param name="date"> the date that the payment is made </param> /// <returns> the adjustable payment instance </returns> public static AdjustablePayment of(CurrencyAmount value, LocalDate date) { return(new AdjustablePayment(value, AdjustableDate.of(date))); }
/// <summary> /// Gets the amount at the specified index. /// </summary> /// <param name="index"> the zero-based index to retrieve </param> /// <returns> the amount at the specified index </returns> public CurrencyAmount get(int index) { return(CurrencyAmount.of(currency, values.get(index))); }
/// <summary> /// Obtains an instance representing an amount to be received where the date is adjustable. /// <para> /// The sign of the amount will be normalized to be positive, indicating receipt. /// /// </para> /// </summary> /// <param name="value"> the amount of the payment </param> /// <param name="date"> the date that the payment is made </param> /// <returns> the adjustable payment instance </returns> public static AdjustablePayment ofReceive(CurrencyAmount value, AdjustableDate date) { return(new AdjustablePayment(value.positive(), date)); }
/// <summary> /// Obtains an instance representing an amount where the date is adjustable. /// <para> /// Whether the payment is pay or receive is determined by the sign of the specified amount. /// /// </para> /// </summary> /// <param name="currency"> the currency of the payment </param> /// <param name="amount"> the amount of the payment </param> /// <param name="date"> the date that the payment is made </param> /// <returns> the adjustable payment instance </returns> public static AdjustablePayment of(Currency currency, double amount, AdjustableDate date) { return(new AdjustablePayment(CurrencyAmount.of(currency, amount), date)); }
/// <summary> /// Obtains an instance representing an amount to be paid where the date is adjustable. /// <para> /// The sign of the amount will be normalized to be negative, indicating a payment. /// /// </para> /// </summary> /// <param name="value"> the amount of the payment </param> /// <param name="date"> the date that the payment is made </param> /// <returns> the adjustable payment instance </returns> public static AdjustablePayment ofPay(CurrencyAmount value, AdjustableDate date) { return(new AdjustablePayment(value.negative(), date)); }
//------------------------------------------------------------------------- public virtual void test_plus() { IList<CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(USD, 2), CurrencyAmount.of(GBP, 3)); assertThrowsIllegalArg(() => CurrencyAmountArray.of(3, i => values[i])); }
public virtual void test_of_function() { IList<CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); CurrencyAmountArray test = CurrencyAmountArray.of(3, i => values[i]); assertThat(test.Currency).isEqualTo(GBP); assertThat(test.Values).isEqualTo(DoubleArray.of(1d, 2d, 3d)); assertThat(test.size()).isEqualTo(3); assertThat(test.get(0)).isEqualTo(CurrencyAmount.of(GBP, 1)); assertThat(test.get(1)).isEqualTo(CurrencyAmount.of(GBP, 2)); assertThat(test.get(2)).isEqualTo(CurrencyAmount.of(GBP, 3)); assertThat(test.ToList()).containsExactly(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); }
public virtual void test_of_CurrencyList_mixedCurrency() { IList<CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(USD, 2), CurrencyAmount.of(GBP, 3)); assertThrowsIllegalArg(() => CurrencyAmountArray.of(values)); }
//------------------------------------------------------------------------- public virtual void test_of_CurrencyDoubleArray() { DoubleArray values = DoubleArray.of(1, 2, 3); CurrencyAmountArray test = CurrencyAmountArray.of(GBP, values); assertThat(test.Currency).isEqualTo(GBP); assertThat(test.Values).isEqualTo(values); assertThat(test.size()).isEqualTo(3); assertThat(test.get(0)).isEqualTo(CurrencyAmount.of(GBP, 1)); assertThat(test.get(1)).isEqualTo(CurrencyAmount.of(GBP, 2)); assertThat(test.get(2)).isEqualTo(CurrencyAmount.of(GBP, 3)); assertThat(test.ToList()).containsExactly(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); }