From 4ee3b6705f2e2b1cfa46f24f56abd08f278c7fc8 Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Tue, 30 Jul 2024 21:42:11 -0700 Subject: [PATCH] dylan: Fix return value of push-last According to the DRM, the push-last function is supposed to return the new value added to a deque rather than the deque. * sources/dylan/deque.dylan (trusted-push-last): Change to return the new element. (push-last): Change return signature to reflect returning the new element. * sources/dylan/tests/collections.dylan (test test--functions): New test (inspired by cmu-test-suite) for testing -specific functions and methods. (suite dylan-collections-test-suite): Add test--functions. --- sources/dylan/deque.dylan | 8 ++++---- sources/dylan/tests/collections.dylan | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/dylan/deque.dylan b/sources/dylan/deque.dylan index 808f08c856..ce42c3bf97 100644 --- a/sources/dylan/deque.dylan +++ b/sources/dylan/deque.dylan @@ -517,7 +517,7 @@ end method pop; // define sealed inline method trusted-push-last - (deque :: , new-element) => (result :: ) + (deque :: , new-element) => (new-element) let rep = deque.representation; let rep-last-index = rep.last-index; while (rep-last-index = (rep.size - 1)) @@ -529,13 +529,13 @@ define sealed inline method trusted-push-last end while; rep.last-index := rep-last-index := rep-last-index + 1; island-deque-element(rep, rep-last-index) := new-element; - deque + new-element end method trusted-push-last; define sealed method push-last - (deque :: , new-element) => (result :: ) + (deque :: , new-element) => (new-element) check-type(new-element, element-type(deque)); - trusted-push-last(deque, new-element); + trusted-push-last(deque, new-element) end method push-last; diff --git a/sources/dylan/tests/collections.dylan b/sources/dylan/tests/collections.dylan index 50d764b4b8..42633c8271 100644 --- a/sources/dylan/tests/collections.dylan +++ b/sources/dylan/tests/collections.dylan @@ -62,6 +62,22 @@ define test test- () test-collection-class(, instantiable?: #t); end; +define test test--functions () + let d = make-test-instance(); + for (i from 5 to 1 by -1) + check-equal("push returns new value", i, push(d, i)); + end for; + for (i from 6 to 10) + check-equal("push-last returns new value", i, push-last(d, i)); + end for; + check-equal("first pop is last item inserted at start", 1, pop(d)); + check-equal("first pop-lat is last item inserted at end", 10, pop-last(d)); + check-true("add! returns argument", d == add!(d, 1)); + check-equal("add! added new element to front", 1, pop(d)); + check-true("remove! returns argument", d == remove!(d, 9)); + check-equal("remove! removed final element", 8, pop-last(d)); +end; + define test test- () test-collection-class(, instantiable?: #t); end; @@ -108,6 +124,7 @@ define suite dylan-collections-test-suite () test test-; test test-; test test-; + test test--functions; test test-; test test-; test test-;