public virtual void test_resolve_invalid() { ValueStepSequence test = ValueStepSequence.of(date(2016, 4, 20), date(2016, 10, 20), Frequency.P12M, ADJ); ValueStep baseStep = ValueStep.of(date(2016, 1, 20), ValueAdjustment.ofReplace(500d)); assertThrowsIllegalArg(() => test.resolve(ImmutableList.of(baseStep), RollConventions.NONE)); }
public virtual void test_resolveValues_dateBased_invalidDateAfter() { ValueStep step = ValueStep.of(date(2014, 4, 3), ValueAdjustment.ofReplace(300d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step)); assertThrowsIllegalArg(() => test.resolveValues(SCHEDULE), "ValueStep date is after the end of the schedule.*"); }
public virtual void test_resolveValues_dateBased_indexZeroValid() { ValueStep step = ValueStep.of(date(2014, 1, 1), ValueAdjustment.ofReplace(300d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step)); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(300d, 300d, 300d)); }
public virtual void test_resolveValues_indexBased_indexTooBig() { ValueStep step = ValueStep.of(3, ValueAdjustment.ofReplace(300d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step)); assertThrowsIllegalArg(() => test.resolveValues(SCHEDULE)); }
public virtual void test_resolveValues_dateBased_invalidChangeValue() { ValueStep step = ValueStep.of(date(2014, 4, 1), ValueAdjustment.ofReplace(300d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step)); assertThrowsIllegalArg(() => test.resolveValues(SCHEDULE), "ValueStep date does not match a period boundary.*"); }
public virtual void test_resolveValues_sequenceAndSteps() { ValueStepSequence seq = ValueStepSequence.of(date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 1, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(350d, 450d, 550d)); }
public virtual void test_resolveValues_indexBased_duplicateDefinitionInvalid() { ValueStep step1 = ValueStep.of(1, ValueAdjustment.ofReplace(300d)); ValueStep step2 = ValueStep.of(1, ValueAdjustment.ofReplace(400d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step1, step2)); assertThrowsIllegalArg(() => test.resolveValues(SCHEDULE)); }
public virtual void test_resolveValues_indexBased_duplicateDefinitionValid() { ValueStep step1 = ValueStep.of(1, ValueAdjustment.ofReplace(300d)); ValueStep step2 = ValueStep.of(1, ValueAdjustment.ofReplace(300d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step1, step2)); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(200d, 300d, 300d)); }
public virtual void test_of_intAdjustment() { ValueStep test = ValueStep.of(2, DELTA_MINUS_2000); assertEquals(test.Date, null); assertEquals(test.PeriodIndex, int?.of(2)); assertEquals(test.Value, DELTA_MINUS_2000); }
public virtual void test_of_dateAdjustment() { ValueStep test = ValueStep.of(date(2014, 6, 30), DELTA_MINUS_2000); assertEquals(test.Date, date(2014, 6, 30)); assertEquals(test.PeriodIndex, int?.empty()); assertEquals(test.Value, DELTA_MINUS_2000); }
public virtual void test_resolveValues_sequenceAndStepClash() { ValueStepSequence seq = ValueStepSequence.of(date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 2, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertThrowsIllegalArg(() => test.resolveValues(SCHEDULE)); }
public virtual void test_resolveValues_dateBased_ignoreExcess() { ValueStep step1 = ValueStep.of(date(2014, 2, 1), ValueAdjustment.ofReplace(300d)); ValueStep step2 = ValueStep.of(date(2014, 2, 15), ValueAdjustment.ofReplace(300d)); // no change to value ValueStep step3 = ValueStep.of(date(2014, 3, 1), ValueAdjustment.ofReplace(400d)); ValueStep step4 = ValueStep.of(date(2014, 3, 15), ValueAdjustment.ofDeltaAmount(0d)); // no change to value ValueStep step5 = ValueStep.of(date(2014, 4, 1), ValueAdjustment.ofMultiplier(1d)); ValueSchedule test = ValueSchedule.of(200d, ImmutableList.of(step1, step2, step3, step4, step5)); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(200d, 300d, 400d)); }
//------------------------------------------------------------------------- public virtual void test_resolve() { ValueStepSequence test = ValueStepSequence.of(date(2016, 4, 20), date(2016, 10, 20), Frequency.P3M, ADJ); ValueStep baseStep = ValueStep.of(date(2016, 1, 20), ValueAdjustment.ofReplace(500d)); IList <ValueStep> steps = test.resolve(ImmutableList.of(baseStep), RollConventions.NONE); assertEquals(steps.Count, 4); assertEquals(steps[0], baseStep); assertEquals(steps[1], ValueStep.of(date(2016, 4, 20), ADJ)); assertEquals(steps[2], ValueStep.of(date(2016, 7, 20), ADJ)); assertEquals(steps[3], ValueStep.of(date(2016, 10, 20), ADJ)); }
//------------------------------------------------------------------------- /// <summary> /// Resolves the sequence to a list of steps. /// </summary> /// <param name="existingSteps"> the existing list of steps </param> /// <param name="rollConv"> the roll convention </param> /// <returns> the steps </returns> internal IList <ValueStep> resolve(IList <ValueStep> existingSteps, RollConvention rollConv) { ImmutableList.Builder <ValueStep> steps = ImmutableList.builder(); steps.addAll(existingSteps); LocalDate prev = firstStepDate; LocalDate date = firstStepDate; while (!date.isAfter(lastStepDate)) { steps.add(ValueStep.of(date, adjustment)); prev = date; date = rollConv.next(date, frequency); } if (!prev.Equals(lastStepDate)) { throw new System.ArgumentException(Messages.format("ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}", frequency, rollConv, lastStepDate, prev)); } return(steps.build()); }
public virtual void test_resolveValues_indexBased() { ValueStep step1 = ValueStep.of(1, ValueAdjustment.ofReplace(300d)); ValueStep step2 = ValueStep.of(2, ValueAdjustment.ofReplace(400d)); // no steps ValueSchedule test0 = ValueSchedule.of(200d, ImmutableList.of()); assertEquals(test0.resolveValues(SCHEDULE), DoubleArray.of(200d, 200d, 200d)); // step1 ValueSchedule test1a = ValueSchedule.of(200d, ImmutableList.of(step1)); assertEquals(test1a.resolveValues(SCHEDULE), DoubleArray.of(200d, 300d, 300d)); // step2 ValueSchedule test1b = ValueSchedule.of(200d, ImmutableList.of(step2)); assertEquals(test1b.resolveValues(SCHEDULE), DoubleArray.of(200d, 200d, 400d)); // step1 and step2 ValueSchedule test2 = ValueSchedule.of(200d, ImmutableList.of(step1, step2)); assertEquals(test2.resolveValues(SCHEDULE), DoubleArray.of(200d, 300d, 400d)); }
//------------------------------------------------------------------------- public virtual void Equals() { ValueStep a1 = ValueStep.of(2, DELTA_MINUS_2000); ValueStep a2 = ValueStep.of(2, DELTA_MINUS_2000); ValueStep b = ValueStep.of(1, DELTA_MINUS_2000); ValueStep c = ValueStep.of(2, ABSOLUTE_100); assertEquals(a1.Equals(a1), true); assertEquals(a1.Equals(a2), true); assertEquals(a1.Equals(b), false); assertEquals(a1.Equals(c), false); ValueStep d1 = ValueStep.of(date(2014, 6, 30), DELTA_MINUS_2000); ValueStep d2 = ValueStep.of(date(2014, 6, 30), DELTA_MINUS_2000); ValueStep e = ValueStep.of(date(2014, 7, 30), DELTA_MINUS_2000); ValueStep f = ValueStep.of(date(2014, 7, 30), ABSOLUTE_100); assertEquals(d1.Equals(d1), true); assertEquals(d1.Equals(d2), true); assertEquals(d1.Equals(e), false); assertEquals(d1.Equals(f), false); }
public virtual void test_serialization() { assertSerialization(ValueStep.of(2, DELTA_MINUS_2000)); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(ValueStep.of(2, DELTA_MINUS_2000)); }