diff options
author | Alon Zakai <azakai@google.com> | 2021-04-29 11:39:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-29 11:39:28 -0700 |
commit | a4c7866f5e133c58ebbf09715a705d514209dac1 (patch) | |
tree | 7ca2ead470ee9ac15b02ecc7589700052443bb8a /test | |
parent | 2785d936639c62d08eb836a775838a37033127b4 (diff) | |
download | binaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.tar.gz binaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.tar.bz2 binaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.zip |
UniqueDeferredQueue improvements (#3847)
Add clear().
Add UniqueNonrepeatingDeferredQueue which also has the property
that it never repeats values in the output.
Also add unit tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/example/cpp-unit.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp index 49893d1d2..3ab35d381 100644 --- a/test/example/cpp-unit.cpp +++ b/test/example/cpp-unit.cpp @@ -6,6 +6,7 @@ #include <ir/cost.h> #include <ir/effects.h> #include <pass.h> +#include <support/unique_deferring_queue.h> #include <wasm.h> using namespace wasm; @@ -581,12 +582,49 @@ void test_field() { 4); } +void test_queue() { + { + UniqueDeferredQueue<int> queue; + queue.push(1); + queue.push(2); + queue.push(3); + queue.push(2); + // first in was 1 + assert_equal(queue.pop(), 1); + // next in was 2, but it was added later, so we defer to then, and get the 3 + assert_equal(queue.pop(), 3); + assert_equal(queue.pop(), 2); + assert_equal(queue.empty(), true); + } + { + UniqueDeferredQueue<int> queue; + queue.push(1); + queue.push(2); + assert_equal(queue.pop(), 1); + // clearing clears the queue + queue.clear(); + assert_equal(queue.empty(), true); + } + { + UniqueNonrepeatingDeferredQueue<int> queue; + queue.push(1); + assert_equal(queue.pop(), 1); + queue.push(1); + // We never repeat values in this queue, so the last push of 1 is ignored. + assert_equal(queue.empty(), true); + // But new values work. + queue.push(2); + assert_equal(queue.pop(), 2); + } +} + int main() { test_bits(); test_cost(); test_effects(); test_literals(); test_field(); + test_queue(); if (failsCount > 0) { abort(); |