Amazing corner cases test, the reason I love Leetcode so much! ^ ^


  • 1

    This problem labeled as EASY, and looks also very straightforward, but it took me 1 hour to get it AC'ed. I'm amazed at the variety and comprehensiveness of its 315 test cases.
    Here's a list of 11 corner/good test cases. I'm sharing it here for others to enjoy this question. ^ ^
    Also viewable here.

    @Test
        public void test1(){
            word = "internationalization";
            abbr = "i12iz4n";
            expected = true;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
    
        }
    
        @Test
        public void test2(){
            word = "apple";
            abbr = "a2e";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
    
        }
    
        @Test
        public void test3(){
            word = "internationalization";
            abbr = "i5a11o1";
            expected = true;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
    
        }
    
        @Test
        public void test4(){
            word = "hi";
            abbr = "1";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test5(){
            word = "a";
            abbr = "1";
            expected = true;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test6(){
            word = "a";
            abbr = "2";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test7(){
            word = "hi";
            abbr = "1i";
            expected = true;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test8(){
            word = "hi";
            abbr = "3";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test9(){
            word = "hi";
            abbr = "11";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test10(){
            word = "word";
            abbr = "1o1d";
            expected = true;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    
        @Test
        public void test11(){
            word = "abbreviation";
            abbr = "a010n";
            expected = false;
            actual = test.validWordAbbreviation(word, abbr);
            assertEquals(expected, actual);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.