This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add selftest for vec::reverse
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>, Jeff Law <law at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Cc: Jan Hubicka <hubicka at ucw dot cz>, David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 6 Oct 2017 12:20:33 -0400
- Subject: [PATCH] Add selftest for vec::reverse
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 01773C04B954
- References: <82167884-d00e-a87c-9f22-94f5cd6e834d@suse.cz>
Martin: I noticed that your switch expansion patch added a
vec::reverse ()
method. Here's a proposed selftest for it, mostly to verify
that it handles even vs odd lengths (which it does).
Only lightly tested; hope this is useful.
Dave
gcc/ChangeLog:
* vec.c (selftest::test_reverse): New function.
(selftest::vec_c_tests): Call it.
---
gcc/vec.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/gcc/vec.c b/gcc/vec.c
index d612703..5d70973 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -359,6 +359,43 @@ test_qsort ()
ASSERT_EQ (10, v.length ());
}
+/* Verify that vec::reverse works correctly. */
+
+static void
+test_reverse ()
+{
+ /* Reversing an empty vec ought to be a no-op. */
+ {
+ auto_vec <int> v;
+ ASSERT_EQ (0, v.length ());
+ v.reverse ();
+ ASSERT_EQ (0, v.length ());
+ }
+
+ /* Verify reversing a vec with even length. */
+ {
+ auto_vec <int> v;
+ safe_push_range (v, 0, 4);
+ v.reverse ();
+ ASSERT_EQ (3, v[0]);
+ ASSERT_EQ (2, v[1]);
+ ASSERT_EQ (1, v[2]);
+ ASSERT_EQ (0, v[3]);
+ ASSERT_EQ (4, v.length ());
+ }
+
+ /* Verify reversing a vec with odd length. */
+ {
+ auto_vec <int> v;
+ safe_push_range (v, 0, 3);
+ v.reverse ();
+ ASSERT_EQ (2, v[0]);
+ ASSERT_EQ (1, v[1]);
+ ASSERT_EQ (0, v[2]);
+ ASSERT_EQ (3, v.length ());
+ }
+}
+
/* Run all of the selftests within this file. */
void
@@ -374,6 +411,7 @@ vec_c_tests ()
test_unordered_remove ();
test_block_remove ();
test_qsort ();
+ test_reverse ();
}
} // namespace selftest
--
1.8.5.3