示例#1
0
        public virtual void test_of_function()
        {
            ScenarioArray <string>        test     = ScenarioArray.of(3, i => Convert.ToString(i + 1));
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
示例#2
0
        public virtual void test_of_array()
        {
            ScenarioArray <string>        test     = ScenarioArray.of("1", "2", "3");
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
示例#3
0
        public virtual void test_of_list()
        {
            ScenarioArray <string>        test     = ScenarioArray.of(ImmutableList.of("1", "2", "3"));
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            DefaultScenarioArray <int> test = DefaultScenarioArray.of(1, 2, 3);

            coverImmutableBean(test);
            DefaultScenarioArray <string> test2 = DefaultScenarioArray.of("2", "3");

            coverBeanEquals(test, test2);
        }
        public virtual void wrongNumberOfFxRates()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2));
            DefaultScenarioArray <CurrencyAmount> test = DefaultScenarioArray.of(values);

            assertThrows(() => test.convertedTo(Currency.USD, fxProvider), typeof(System.ArgumentException), "Expected 2 FX rates but received 3");
        }
        public virtual void missingFxRates()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(EUR, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2), CurrencyAmount.of(Currency.GBP, 3));
            DefaultScenarioArray <CurrencyAmount> test = DefaultScenarioArray.of(values);

            assertThrows(() => test.convertedTo(Currency.USD, fxProvider), typeof(System.ArgumentException));
        }
        public virtual void create_withFunction()
        {
            DefaultScenarioArray <int> test = DefaultScenarioArray.of(3, i => (i + 1));

            assertThat(test.Values).isEqualTo(ImmutableList.of(1, 2, 3));
            assertThat(test.ScenarioCount).isEqualTo(3);
            assertThat(test.get(0)).isEqualTo(1);
            assertThat(test.get(1)).isEqualTo(2);
            assertThat(test.get(2)).isEqualTo(3);
            assertThat(test.ToList()).isEqualTo(ImmutableList.of(1, 2, 3));
        }
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public ScenarioArray<?> convertedTo(com.opengamma.strata.basics.currency.Currency resultCurrency, ScenarioFxRateProvider fxRateProvider)
        public ScenarioArray <object> convertedTo(Currency resultCurrency, ScenarioFxRateProvider fxRateProvider)
        {
            int scenarioCount = ScenarioCount;

            if (fxRateProvider.ScenarioCount != scenarioCount)
            {
                throw new System.ArgumentException(Messages.format("Expected {} FX rates but received {}", scenarioCount, fxRateProvider.ScenarioCount));
            }
            ImmutableList <object> converted = zipWithIndex(values.stream()).map(tp => convert(resultCurrency, fxRateProvider, tp.First, tp.Second)).collect(toImmutableList());

            return(DefaultScenarioArray.of(converted));
        }
        public virtual void notConvertible()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <string> values = ImmutableList.of("a", "b", "c");
            DefaultScenarioArray <string> test = DefaultScenarioArray.of(values);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(com.opengamma.strata.basics.currency.Currency.GBP, fxProvider);
            ScenarioArray <object> convertedList = test.convertedTo(Currency.GBP, fxProvider);

            assertThat(convertedList).isEqualTo(test);
        }
        public virtual void convertCurrencyAmount()
        {
            FxRateScenarioArray    rates              = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider         = new TestScenarioFxRateProvider(rates);
            SingleScenarioArray <CurrencyAmount> test = SingleScenarioArray.of(3, CurrencyAmount.of(GBP, 2));

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(USD, fxProvider);
            ScenarioArray <object> convertedList  = test.convertedTo(USD, fxProvider);
            IList <CurrencyAmount> expectedValues = ImmutableList.of(CurrencyAmount.of(USD, 2 * 1.61), CurrencyAmount.of(USD, 2 * 1.62), CurrencyAmount.of(USD, 2 * 1.63));
            DefaultScenarioArray <CurrencyAmount> expectedList = DefaultScenarioArray.of(expectedValues);

            assertThat(convertedList).isEqualTo(expectedList);
        }
        //-----------------------------------------------------------------------
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj != null && obj.GetType() == this.GetType())
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: DefaultScenarioArray<?> other = (DefaultScenarioArray<?>) obj;
                DefaultScenarioArray <object> other = (DefaultScenarioArray <object>)obj;
                return(JodaBeanUtils.equal(values, other.values));
            }
            return(false);
        }
示例#12
0
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public ScenarioArray<?> convertedTo(com.opengamma.strata.basics.currency.Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)
        public ScenarioArray <object> convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (value instanceof com.opengamma.strata.basics.currency.FxConvertible<?>)
            if (value is FxConvertible <object> )
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.basics.currency.FxConvertible<?> convertible = (com.opengamma.strata.basics.currency.FxConvertible<?>) value;
                FxConvertible <object> convertible = (FxConvertible <object>)value;
                if (fxRateProvider.ScenarioCount != scenarioCount)
                {
                    throw new System.ArgumentException(Messages.format("Expected {} FX rates but received {}", scenarioCount, fxRateProvider.ScenarioCount));
                }
                ImmutableList <object> converted = IntStream.range(0, scenarioCount).mapToObj(i => convertible.convertedTo(reportingCurrency, fxRateProvider.fxRateProvider(i))).collect(toImmutableList());
                return(DefaultScenarioArray.of(converted));
            }
            return(this);
        }