Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: test/unittests/wasm/switch-logic-unittest.cc

Issue 1838973002: optimized switch implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/unittests/unittests.gyp ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/switch-logic-unittest.cc
diff --git a/test/unittests/wasm/switch-logic-unittest.cc b/test/unittests/wasm/switch-logic-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be587c28bd16bad9dc4c4c75eeb5f042040eeeb6
--- /dev/null
+++ b/test/unittests/wasm/switch-logic-unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/wasm/switch-logic.h"
+#include "test/unittests/test-utils.h"
+
+namespace v8 {
+namespace internal {
+namespace wasm {
+class SwitchLogicTest : public TestWithZone {};
+
+void CheckNodeValues(CaseNode* node, int begin, int end) {
+ CHECK_EQ(node->begin, begin);
+ CHECK_EQ(node->end, end);
+}
+
+TEST_F(SwitchLogicTest, Single_Table_Test) {
+ ZoneVector<int> values(zone());
+ values.push_back(14);
+ values.push_back(12);
+ values.push_back(15);
+ values.push_back(19);
+ values.push_back(18);
+ values.push_back(16);
+ CaseNode* root = OrderCases(&values, zone());
+ CHECK_NULL(root->left);
+ CHECK_NULL(root->right);
+ CheckNodeValues(root, 12, 19);
+}
+
+TEST_F(SwitchLogicTest, Balanced_Tree_Test) {
+ ZoneVector<int> values(zone());
+ values.push_back(5);
+ values.push_back(1);
+ values.push_back(6);
+ values.push_back(9);
+ values.push_back(-4);
+ CaseNode* root = OrderCases(&values, zone());
+ CheckNodeValues(root, 5, 5);
+ CheckNodeValues(root->left, -4, -4);
+ CHECK_NULL(root->left->left);
+ CheckNodeValues(root->left->right, 1, 1);
+ CHECK_NULL(root->left->right->left);
+ CHECK_NULL(root->left->right->right);
+ CheckNodeValues(root->right, 6, 6);
+ CHECK_NULL(root->right->left);
+ CheckNodeValues(root->right->right, 9, 9);
+ CHECK_NULL(root->right->right->left);
+ CHECK_NULL(root->right->right->right);
+}
+
+TEST_F(SwitchLogicTest, Hybrid_Test) {
+ ZoneVector<int> values(zone());
+ values.push_back(1);
+ values.push_back(2);
+ values.push_back(3);
+ values.push_back(4);
+ values.push_back(7);
+ values.push_back(10);
+ values.push_back(11);
+ values.push_back(12);
+ values.push_back(13);
+ values.push_back(16);
+ CaseNode* root = OrderCases(&values, zone());
+ CheckNodeValues(root, 7, 7);
+ CheckNodeValues(root->left, 1, 4);
+ CheckNodeValues(root->right, 10, 13);
+ CheckNodeValues(root->right->right, 16, 16);
+}
+
+TEST_F(SwitchLogicTest, Single_Case) {
+ ZoneVector<int> values(zone());
+ values.push_back(3);
+ CaseNode* root = OrderCases(&values, zone());
+ CheckNodeValues(root, 3, 3);
+ CHECK_NULL(root->left);
+ CHECK_NULL(root->right);
+}
+
+TEST_F(SwitchLogicTest, Empty_Case) {
+ ZoneVector<int> values(zone());
+ CaseNode* root = OrderCases(&values, zone());
+ CHECK_NULL(root);
+}
+
+} // namespace wasm
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/unittests/unittests.gyp ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698