Coverage Report - com.dvp.tutoriel.fibonacci.MaCalculette2
 
Classes in this File Line Coverage Branch Coverage Complexity
MaCalculette2
100 %
8/8
100 %
6/6
6
 
 1  
 package com.dvp.tutoriel.fibonacci;
 2  
 
 3  
 
 4  52
 public class MaCalculette2 implements Calculette {
 5  
 
 6  
         private final static double NOMBRE_OR = 1.61803398874989;
 7  
         private final static double RACINE_5 = 2.236067977499;
 8  
 
 9  
         public Long fibonacci(Integer n) {
 10  
                 // REGLE RG024.4
 11  49
                 if (n <= 0) {
 12  8
                         throw new IllegalArgumentException("On ne calcule que pour des nombres positifs");
 13  
                 }
 14  
 
 15  
                 // REGLE RG024.1 : f(1) = 1
 16  
                 // REGLE RG024.2 : f(2) = 1
 17  41
                 if (n == 1 || n == 2) {
 18  8
                         return 1L;
 19  
                 }
 20  
 
 21  33
                 final double nominateur = Math.pow(NOMBRE_OR, n);
 22  
 
 23  33
                 final double result = nominateur / RACINE_5;
 24  33
                 return Math.round(result);
 25  
         }
 26  
 
 27  
 }