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

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, 9 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
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..8974ed754ae92a8212cca98aad69b2cb6ad88b7e
--- /dev/null
+++ b/test/unittests/wasm/switch-logic-unittest.cc
@@ -0,0 +1,87 @@
+// 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) {
+ Zone zone;
+ 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) {
+ Zone zone;
+ 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) {
+ Zone zone;
+ 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) {
+ Zone zone;
+ 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_);
+}
+
+} // namespace wasm
+} // namespace internal
+} // namespace v8
« src/wasm/switch-logic.cc ('K') | « test/unittests/unittests.gyp ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698