Should null elements be considered in test cases?


  • 0

    Currently there is no system test case for null elements:

    For example:

    ArrayList<Integer> al = new ArrayList<Integer>() {
        {
            add(null);
            add(null);
            add(1);
            add(2);
            add(3);
        }
    };
    
    PeekingIterator pi = new PeekingIterator(al.iterator());
    
    if (pi.hasNext()) {
        System.out.println( pi.peek() );
        System.out.println( pi.next() );
    }
    
    if (pi.hasNext()) {
        System.out.println( pi.next() );
        System.out.println( pi.peek() );
    }

  • 0
    L
    This post is deleted!

  • 0

    Is that really your own code? It looks like mine.


  • 0

    System tests are the same for all languages and C++ doesn't have the "null" possibility, so it's a rather safe bet that that won't happen here. But I agree that if it were just Java, null should be ruled out by the specification or correctly handled by the solution.


  • 0

    Yep, I totally agree with you. And I think it will be better if the judge system could add some special test cases for Java and Python in the future with problems just like this one.


Log in to reply
 

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