package cn.fansunion.leecode; import org.junit.Assert; import org.junit.Test; import cn.fansunion.leecode.todo.ClimbingStairs; import cn.hutool.core.date.StopWatch; /** * @author wen.lei@brgroup.com * * 2022-1-11 */ public class ClimbingStairsTest { @Test public void test() { ClimbingStairs cs = new ClimbingStairs(); final int actual45 = 1836311903 ; StopWatch sw45 = new StopWatch(); sw45.start(); Assert.assertEquals(cs.climbStairs( 45 ), actual45); sw45.stop(); System.out.println( "45:" +sw45.getTotalTimeMillis()+ "ms" ); StopWatch sw37 = new StopWatch(); sw37.start(); Assert.assertEquals(cs.climbStairs( 37 ), 39088169 ); sw37.stop(); System.out.println( "37:" +sw37.getTotalTimeMillis()+ "ms" ); } @Test public void testDp() { ClimbingStairs cs = new ClimbingStairs(); final int actual45 = 1836311903 ; StopWatch sw45 = new StopWatch(); sw45.start(); Assert.assertEquals(cs.climbStairsDp( 45 ), actual45); sw45.stop(); System.out.println( "45:" +sw45.getTotalTimeNanos()+ "ns" ); StopWatch sw37 = new StopWatch(); sw37.start(); Assert.assertEquals(cs.climbStairsDp( 37 ), 39088169 ); sw37.stop(); System.out.println( "37:" +sw37.getTotalTimeNanos()+ "ns" ); } @Test public void climbStairsDpTmpVariable() { ClimbingStairs cs = new ClimbingStairs(); final int actual45 = 1836311903 ; StopWatch sw45 = new StopWatch(); sw45.start(); Assert.assertEquals(cs.climbStairsDpTmpVariable( 45 ), actual45); sw45.stop(); System.out.println( "45:" +sw45.getTotalTimeNanos()+ "ns" ); StopWatch sw37 = new StopWatch(); sw37.start(); Assert.assertEquals(cs.climbStairsDpTmpVariable( 37 ), 39088169 ); sw37.stop(); System.out.println( "37:" +sw37.getTotalTimeNanos()+ "ns" ); } @Test public void testCache() { ClimbingStairs cs = new ClimbingStairs(); final int actual45 = 1836311903 ; StopWatch sw45 = new StopWatch(); sw45.start(); Assert.assertEquals(cs.climbStairsCache( 45 ), actual45); sw45.stop(); System.out.println( "45Cache:" +sw45.getTotalTimeMillis()); StopWatch sw37 = new StopWatch(); sw37.start(); Assert.assertEquals(cs.climbStairsCache( 37 ), 39088169 ); sw37.stop(); System.out.println( "37Cache:" +sw37.getTotalTimeMillis()); } } |