Repository navigation
Conversation
72d685b to
1d1ac5b
Compare
alanhc
left a comment
There was a problem hiding this comment.
Matches what graphToJson already does in C++: the null is refused where neighbors are queued, with the same message, so every node in byValue has had its neighbors checked before the rows read next.val. The scenario now covers all five languages plus the JavaScript undefined slot.
One nit, not blocking: with nulls refused before they reach the queue, if (cur == null) continue; in the Java loop (and if (!current) continue / if current is None in the JS and Python ones) can no longer fire. C++ keeps the same line, so leaving it for consistency is fine.
1d1ac5b to
8ef77fa
Compare
There was a problem hiding this comment.
Checked out the head (1d1ac5b) on macOS and ran:
$ node --test tests/browser/graph-clone-identity.test.js
ℹ tests 36
ℹ pass 17
ℹ fail 0
ℹ skipped 19
The C and C++ cases pass. The 19 skipped are the Java cases (no JDK on
this machine) and the JavaScript and Python cases (no Chromium), so I
checked the Python serializer directly instead: with a.neighbors = None,
_graph_to_adjacency raises "TypeError: 'NoneType' object is not
iterable".
The element-level fix looks right to me, and alanhc's note on the dead
continue guards already covers that part. Two things inline: a null
neighbors list still fails inside the Java and Python checkers, and the
new tests only null a neighbor of the root.
8ef77fa to
afe4667
Compare
|
Add screenshots to the pull request description to illustrate your work, as @ColtenOuO suggests. Example: #349 |
afe4667 to
1d5ddc2
Compare
A Clone Graph answer whose copy holds a null neighbor got "Returned graph has a NULL neighbor." in C and C++, but an exception from inside the checker elsewhere: a NullPointerException from ArrayDeque in Java, and a read of neighbor.val on null in JavaScript and Python. Refuse the null where each serializer queues neighbors, with the message C and C++ already use. Nothing null can then reach the queue, so drop the skip at the top of each queue loop, C++ included, rather than leave it implying that a null neighbor is passed over quietly. The null-neighbor clone test covered only C and only the root's list; it now runs for every language and also nulls a neighbor of a node reached from the root. A copy that also points at an input node still gets the deep-copy refusal in C, which checks each edge in order, and the null refusal in the other four, which check every neighbor while queueing; a test pins both instead of implying one message for every mixed violation. Close sysprog21#725 Change-Id: I79634808b1e2e839ffdd87db19c54399771bfc11
1d5ddc2 to
e86f0ec
Compare
A Clone Graph answer whose copy holds a null neighbor got
Returned graph has a NULL neighbor.in C and C++, but an exception raised inside the checker in the other three languages:java.lang.NullPointerExceptionfrom theArrayDequein the JavagraphJson, andCannot read properties of null (reading 'val')orAttributeError: 'NoneType' object has no attribute 'val'from the JavaScript and Python serializers inweb/runners.js, which skip the null in the queue and then readneighbor.valwhile building rows.Each of the three now refuses the null where it queues neighbors, with the message C and C++ already use, so an answer whose only fault is a null neighbor gets the same case error in all five languages. Java reports it as
java.lang.IllegalArgumentException: Returned graph has a NULL neighbor.and Python asTypeError: Returned graph has a NULL neighbor., the same shapes as their deep-copy and duplicate-ID refusals. The JavaScript check is== null, so anundefinedslot is refused as well, and the browser suite covers both.In an interview, the JavaScript answer below adds
copies.get(next)to a copy's neighbors beforenexthas a copy of its own, so the copy holdsundefined. Run against Sandbox Topology Replica in the same local server, with onlyweb/compiler-explorer.jsandweb/runners.jsswitched betweenmainat fe04f8f and this change, three of the five cases fail either way; before, each reports an exception raised inside the checker, and after, each names the fault.Before,

mainat fe04f8f:After, this change:

With every neighbor checked before it is queued, nothing null can reach the queue: its first entry is the root, and each serializer already returns early when the root is null. The skip at the top of the queue loop in Java, JavaScript, Python and C++ therefore can no longer run and is removed, so no loop suggests that a null neighbor is passed over quietly.
tests/browser/graph-clone-identity.test.jshad the null-neighbor scenario for C only, and only for the root's own list. It now runs for C, C++ and Java in the toolchain suite and for JavaScript and Python in the browser suite, once with a neighbor of the root nulled and once with a neighbor ofb, which is reached from the root. The compiled-language assertion usesendsWith, as the duplicate-ID one does, because Java prefixes the exception class. Without the fix, the JavaScript, Python and Java null-neighbor cases fail and the C and C++ ones pass; with it, all pass. A guard narrowed to the root's list fails the non-root cases.An answer that breaks two rules on one node is not aligned by this change. With a copied node whose neighbors are
[input node, null], C walks each edge in order and reportsReturned graph must be a deep copy., while C++, Java, JavaScript and Python refuse the null while queueing every neighbor and report the NULL neighbor. C and C++ already differed this way onmain; this change brings Java, JavaScript and Python to the C++ order. A mixed scenario in the same test file pins both outcomes, so a later change to either order has to update it on purpose.A
neighborslist that is itself null is a separate gap, filed as #736.Close #725