Repository: gonum/gonum
Pull request #1618 (2021-04-26 00:54:36)

graph/iterator: fix Len for depleted ImplicitNodesIterator
Please take a look.

<!--
Checklist:

- API changes have been discussed
- code is goformated correctly (goimports)
- packages with generated code have had code generation run
- tests pass locally
- linked to relevant issues

Please make sure your commit message summary line and pull request
title match the Go convention; a one-line summary of the change,
prefixed by the primary affected package that should complete the
sentence, "This change modifies Gonum to _____."
-->


codecov-commenter: # [Codecov](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum) Report
> Merging [#1618](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum) (0935df3) into [master](https://codecov.io/gh/gonum/gonum/commit/ccc0da248a78266c0e8a38ac56e983d17c4ba15f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum) (ccc0da2) will **decrease** coverage by `0.07%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/gonum/gonum/pull/1618/graphs/tree.svg?width=650&height=150&src=pr&token=B7qHnqSPNL&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum)](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum)

```diff
@@            Coverage Diff             @@
##           master    #1618      +/-   ##
==========================================
- Coverage   73.04%   72.97%   -0.08%     
==========================================
  Files         498      493       -5     
  Lines       58813    58532     -281     
==========================================
- Hits        42961    42714     -247     
+ Misses      13424    13408      -16     
+ Partials     2428     2410      -18     
```


| [Impacted Files](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum) | Coverage Δ | |
|---|---|---|
| [graph/iterator/nodes.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-Z3JhcGgvaXRlcmF0b3Ivbm9kZXMuZ28=) | `90.47% <100.00%> (+0.15%)` | :arrow_up: |
| [lapack/gonum/dlaqr1.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-bGFwYWNrL2dvbnVtL2RsYXFyMS5nbw==) | `40.62% <0.00%> (-15.63%)` | :arrow_down: |
| [optimize/listsearch.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-b3B0aW1pemUvbGlzdHNlYXJjaC5nbw==) | `72.22% <0.00%> (-1.86%)` | :arrow_down: |
| [...sp/fourier/internal/fftpack/array\_bounds\_checks.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-ZHNwL2ZvdXJpZXIvaW50ZXJuYWwvZmZ0cGFjay9hcnJheV9ib3VuZHNfY2hlY2tzLmdv) | | |
| [graph/iterator/nodes\_map\_safe.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-Z3JhcGgvaXRlcmF0b3Ivbm9kZXNfbWFwX3NhZmUuZ28=) | | |
| [graph/internal/set/same\_appengine.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-Z3JhcGgvaW50ZXJuYWwvc2V0L3NhbWVfYXBwZW5naW5lLmdv) | | |
| [mat/index\_bound\_checks.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-bWF0L2luZGV4X2JvdW5kX2NoZWNrcy5nbw==) | | |
| [mat/offset\_appengine.go](https://codecov.io/gh/gonum/gonum/pull/1618/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum#diff-bWF0L29mZnNldF9hcHBlbmdpbmUuZ28=) | | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum). Last update [ccc0da2...0935df3](https://codecov.io/gh/gonum/gonum/pull/1618?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gonum).


Patch:
diff --git a/graph/iterator/nodes.go b/graph/iterator/nodes.go
index b3cac597..2b507304 100644
--- a/graph/iterator/nodes.go
+++ b/graph/iterator/nodes.go
@@ -389,6 +389,9 @@ func NewImplicitNodes(beg, end int, new func(id int) graph.Node) *ImplicitNodes
 
 // Len returns the remaining number of nodes to be iterated over.
 func (n *ImplicitNodes) Len() int {
+	if n.end <= n.curr {
+		return 0
+	}
 	return n.end - n.curr - 1
 }
 


Test patch:
diff --git a/graph/iterator/nodes_test.go b/graph/iterator/nodes_test.go
index c7d88064..6d2add08 100644
--- a/graph/iterator/nodes_test.go
+++ b/graph/iterator/nodes_test.go
@@ -98,6 +98,9 @@ func TestImplicitNodesIterate(t *testing.T) {
 					t.Errorf("unexpected iterator length during iteration for round %d: got:%d want:%d", i, it.Len(), (test.end-test.beg)-len(got))
 				}
 			}
+			if it.Len() != 0 {
+				t.Errorf("unexpected depleted iterator length for round %d: got:%d want:0", i, it.Len())
+			}
 			if !reflect.DeepEqual(got, test.want) {
 				t.Errorf("unexpected iterator output for round %d: got:%#v want:%#v", i, got, test.want)
 			}