package test.leecode.array; import org.junit.Assert; import org.junit.Test; import cn.fansunion.leecode.array.RemoveOneElementToMakeTheArrayStrictlyIncreasing; /** * @author wen.lei@brgroup.com * * 2022-2-17 */ public class RemoveOneElementToMakeTheArrayStrictlyIncreasingTest @Test public void test() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); //[105,924,32,968] Assert.assertEquals( true , incr.canBeIncreasing( new int [] 105 , 924 , 32 , 968 )); Assert.assertEquals( true , incr.canBeIncreasing( new int [] 10 , 1 , 2 , 5 , 7 )); Assert.assertEquals( false , incr.canBeIncreasing( new int [] 1 , 1 , 2 , 2 )); Assert.assertEquals( false , incr.canBeIncreasing( new int [] 2 , 3 , 1 , 2 )); Assert.assertEquals( true , incr.canBeIncreasing( new int [] 1 , 2 , 10 , 5 , 7 )); Assert.assertEquals( true , incr.canBeIncreasing( new int [] 1 , 2 , 5 , 7 , 10 )); Assert.assertEquals( true , incr.canBeIncreasing( new int [] 1 , 2 , 5 , 3 , 7 )); Assert.assertEquals( true , incr.canBeIncreasing( new int [] 1 , 2 , 3 , 3 , 5 , 7 )); Assert.assertEquals( false , incr.canBeIncreasing( new int [] 1 , 3 , 2 , 5 , 3 , 7 ));
@Test public void testError() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); //[105,924,32,968] Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 105 , 924 , 32 , 968 )); Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 10 , 1 , 2 , 5 , 7 )); Assert.assertEquals( false , incr.canBeIncreasingError( new int [] 1 , 1 , 2 , 2 )); Assert.assertEquals( false , incr.canBeIncreasingError( new int [] 2 , 3 , 1 , 2 )); Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 1 , 2 , 10 , 5 , 7 )); Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 1 , 2 , 5 , 7 , 10 )); Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 1 , 2 , 5 , 3 , 7 )); Assert.assertEquals( true , incr.canBeIncreasingError( new int [] 1 , 2 , 3 , 3 , 5 , 7 )); Assert.assertEquals( false , incr.canBeIncreasingError( new int [] 1 , 3 , 2 , 5 , 3 , 7 ));
@Test public void testStupid() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); Assert.assertEquals( false , incr.canBeIncreasingStupid( new int [] 1 , 1 , 2 , 2 )); Assert.assertEquals( false , incr.canBeIncreasingStupid( new int [] 2 , 3 , 1 , 2 )); Assert.assertEquals( true , incr.canBeIncreasingStupid( new int [] 1 , 2 , 10 , 5 , 7 ));
@Test public void testStupidError1() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); Assert.assertEquals( false , incr.canBeIncreasingStupid( new int [] 1 , 1 , 2 , 2 )); Assert.assertEquals( false , incr.canBeIncreasingStupid( new int [] 2 , 3 , 1 , 2 )); Assert.assertEquals( true , incr.canBeIncreasingStupid( new int [] 1 , 2 , 10 , 5 , 7 )); //暴力破解法的局限性 //int length=1234567891;Java heap space int length= 123456789 ; int [] nums = new int [length]; for ( int index= 0 ;index<length;index++) nums[index]=index;
Assert.assertEquals( true , incr.canBeIncreasingStupid(nums));
@Test public void testStupidError2() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); //暴力破解法的局限性2 //int length2=123456789;迟迟不出结果 int length2= 12345678 ; int [] nums2 = new int [length2+ 1 ]; for ( int index= 0 ;index<length2;index++) nums2[index]=index;
//末尾插入1个数字,增加代码复杂度,123456789长度就迟迟不出结果了;12345678可以 nums2[length2]= 123456 ; final boolean canBeIncreasingStupid = incr.canBeIncreasingStupid(nums2); Assert.assertEquals( true , canBeIncreasingStupid);
@Test public void testNewNumsExceptOne() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); Assert.assertArrayEquals( new int [] 1 , 1 , 2 , incr.newNumsExceptOne( new int [] 1 , 1 , 2 , 2 , 2 )); Assert.assertArrayEquals( new int [] 2 , 3 , 1 , incr.newNumsExceptOne( new int [] 2 , 3 , 1 , 2 , 3 )); Assert.assertArrayEquals( new int [] 2 , 10 , 5 , 7 , incr.newNumsExceptOne( new int [] 1 , 2 , 10 , 5 , 7 , 0 ));
@Test public void testIncreasing() RemoveOneElementToMakeTheArrayStrictlyIncreasing incr = new RemoveOneElementToMakeTheArrayStrictlyIncreasing(); Assert.assertEquals( false , incr.increasing( new int [] 1 , 1 , 2 , 2 )); Assert.assertEquals( false , incr.increasing( new int [] 2 , 3 , 1 , 2 )); Assert.assertEquals( true , incr.increasing( new int [] 1 , 2 , 5 , 7 )); Assert.assertEquals( true , incr.increasing( new int [] 1 , 2 , 5 , 7 , 11 , 13 , 16 , 12345 ));
|