Esempio n. 1
0
  @Test
  public void testPrev() {
    long a = 0, b = 1, c = -1;
    long prev = -1;

    for (int i = 0; i < Fibonacci.MAX_INDEX + 1; i++) {
      c = a + b;
      System.out.println(i + " " + a);

      if (prev != -1 && a != 1) assertEquals(prev, Fibonacci.previous(a));

      prev = a;
      a = b;
      b = c;
    }
  }
Esempio n. 2
0
  @Test
  public void testPrevSpeed() {
    Global.random = new Random();

    int m = 1000000;

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
    }
    System.out.println(toc());

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
      Fibonacci.previous(n);
    }
    System.out.println(toc());
  }