@Test
  public void testGenerateScheduleInterestOnlyArrayBounds() {
    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    amAttrs.setLoanAmount(ofUSD(10000));
    amAttrs.setInterestRateAsPercent(12.);
    amAttrs.setInterestOnly(true);
    amAttrs.setPaymentFrequency(TimePeriod.Weekly.getPeriodsPerYear());
    int termInMonths = 24;
    amAttrs.setTermInMonths(termInMonths);
    amAttrs.setAdjustmentDate(LocalDate.of(2016, Month.JANUARY, 1));

    List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs);

    try {
      schedule.get(-1);
      fail("Interest only schedule should not allow negative payment number");
    } catch (IndexOutOfBoundsException iobe) {
    }

    int expectedPayments =
        (int) Math.ceil(amAttrs.getPaymentFrequency() * amAttrs.getTermInMonths() / 12.);

    try {
      schedule.get(expectedPayments);
      fail("Interest only schedule should not allow payments beyond schedule bound");
    } catch (IndexOutOfBoundsException iobe) {
    }

    schedule.get(expectedPayments - 1);
  }
Example #2
0
  /**
   * Duplicate because I need DocumentLengthTEST!
   *
   * @param valueOf
   * @return [0] - passageCount in collection and [1] - the average legnth of passages
   * @throws URISyntaxException
   * @throws IOException
   */
  private double[] getNumberOfPassages(Integer windowSize) throws IOException, URISyntaxException {

    double count = 0.0;
    double avg = 0.0;
    double[] res = new double[2];

    List<String> documentLengthList =
        Utils.readFileToList("/DocumentLengthTEST.txt"); // I uses TEST!!! for testing only!!
    for (String length : documentLengthList) {

      double docLength = Double.valueOf(length);
      double ceil = Math.ceil(docLength / (double) windowSize);
      double floor = Math.floor(docLength / (double) windowSize);
      count += ceil;
      avg += ((floor * windowSize) + (docLength - (floor * windowSize)));
    }
    avg = avg / count;
    res[0] = count;
    res[1] = avg;
    return res;
  }