示例#1
0
  @Test
  public void testIndexSpeed() {
    Global.random = new Random();

    int m = 10000000;

    tic();
    for (int i : Series.series(m)) {
      int index = Global.random.nextInt(Fibonacci.MAX_INDEX + 1);
      long n = Fibonacci.get(index);
      Fibonacci.getIndexApprox(n);
    }
    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.getIndex(n);
    }
    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);
    }
    System.out.println(toc());
  }
示例#2
0
  @Test
  public void testGetIndex() {
    long a = 0, b = 1, c = -1;

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

      if (a != 1) assertEquals(i, Fibonacci.getIndex(a));

      a = b;
      b = c;
    }
  }
示例#3
0
  @Test
  public void testGet() {
    long a = 0, b = 1;

    System.out.println(Long.MAX_VALUE);
    for (int i = 0; i < Fibonacci.MAX_INDEX + 1; i++) {
      long c = Fibonacci.get(i);
      System.out.println(i + " " + c);
      assertEquals(c, a);
      a = b;
      b = b + c;
    }
  }
示例#4
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;
    }
  }