Fix issue with linked list remove (#7065)

* Added failing linked-list test for #7059

* Fixed linked-list remove bug #7059
This commit is contained in:
btheado
2022-11-26 09:05:10 -06:00
committed by GitHub
parent 32a033bb50
commit bea1a6b14f
2 changed files with 18 additions and 7 deletions

View File

@@ -137,6 +137,21 @@ describe("LinkedList class tests", function() {
compare(pushTop(newPair(["C", "X", "A", "A"]), "X")); // CAAX
});
it("can remove all instances of a multi-instance value #7059", function() {
// Remove duplicate items when one or more items between the duplicates
// are not removed and the first of those duplicates is not the first item.
// These tests used to fail prior to the fix to #7059
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "C", "A", "A"])); // B
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["C", "A", "A", "A"])); // B
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "A", "A"])); // CB
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "A", "A", "C"])); // B
compare(remove(newPair(["A", "A", "B", "A"]), ["A", "A", "A"])); // B
compare(remove(newPair(["A", "A", "B", "A"]), ["A", "A", "A", "B"])); //
compare(remove(newPair(["C", "A", "B", "A"]), ["C", "A", "A"])); // B
compare(remove(newPair(["C", "A", "B", "A", "C"]), ["C", "A", "A", "C"])); // B
compare(remove(newPair(["B", "A", "B", "A"]), ["B", "A", "A"])); // B
});
it("can handle particularly nasty pushTop pitfall", function() {
var pair = newPair(["A", "B", "A", "C"]);
pushTop(pair, "A"); // BACA