MathUtils { public double computeLogFactorial(int n) { if (n > m_maxFactComputed) { for (int i = m_maxFactComputed + 1; i <= n; i++) { m_logFactTbl.add(m_logFactTbl.get(i - 1) + Math.log(i)); } m_maxFactComputed = n; } return m_logFactTbl.get(n); } MathUtils(); double computeLogFactorial(int n); static final int INIT_TBL_CAPACITY; }
@Test public void testComputeLogFactorialInputZero(){ MathUtils newMathUtils = new MathUtils(); assertEquals("Input of 0, so the first if fails. ",0.0, newMathUtils.computeLogFactorial(0), 0 ); }
@Test public void testComputeLogFactorialInputMoreThanZero(){ MathUtils newMathUtils = new MathUtils(); double valueOf3 = Math.log(3)+Math.log(2)+Math.log(1); assertEquals("Input of 3, so the first if passes. ", valueOf3 , newMathUtils.computeLogFactorial(3), 0 ); }