[ https://issues.apache.org/jira/browse/MATH-1682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18004842#comment-18004842 ]
Ruiqi Dong commented on MATH-1682: ---------------------------------- {code:java} package org.apache.commons.math4.legacy.linear; import java.util.Iterator; import org.apache.commons.math4.legacy.linear.RealVector.Entry;import org.junit.Assert; import org.junit.Test; /** * Tests for {@link RealVector}. */ public class RealVectorTest extends RealVectorAbstractTest{ @Override public RealVector create(final double[] data) { return new RealVectorTestImpl(data); } /* ========= above is existing code in RealVectorTest.java ========= */ /* here is the new test case */ @Test public void testSparseIteratorEmptyVector() { RealVector v = create(new double[0]); Iterator<Entry> it = v.sparseIterator(); // Throws OutOfRangeException Assert.assertFalse(it.hasNext()); } }{code} > RealVector.sparseIterator() throws OutOfRangeException for empty vectors > ------------------------------------------------------------------------ > > Key: MATH-1682 > URL: https://issues.apache.org/jira/browse/MATH-1682 > Project: Commons Math > Issue Type: Bug > Components: legacy > Reporter: Ruiqi Dong > Priority: Minor > Original Estimate: 0.5h > Remaining Estimate: 0.5h > > When calling {{sparseIterator()}} on an empty {{RealVector}} (dimension = 0), > an {{OutOfRangeException}} is thrown instead of returning an empty iterator. > This violates the expected behavior of iterator pattern where empty > collections should return empty iterators. > *Test Case:* > {code:java} > RealVector v = create(new double[0]); > Iterator<Entry> it = v.sparseIterator();// Throws OutOfRangeException {code} > -- This message was sent by Atlassian Jira (v8.20.10#820010)