@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; } }
@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()); }