1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // Not a portable test 10 11 // Precondition: __x->__left_ != nullptr 12 // template <class _NodePtr> 13 // void 14 // __tree_right_rotate(_NodePtr __x); 15 16 #include <__tree> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 struct Node 22 { 23 Node* __left_; 24 Node* __right_; 25 Node* __parent_; 26 __parent_unsafeNode27 Node* __parent_unsafe() const { return __parent_; } __set_parentNode28 void __set_parent(Node* x) { __parent_ = x;} 29 NodeNode30 Node() : __left_(), __right_(), __parent_() {} 31 }; 32 33 void test1()34test1() 35 { 36 Node root; 37 Node x; 38 Node y; 39 root.__left_ = &x; 40 x.__left_ = &y; 41 x.__right_ = 0; 42 x.__parent_ = &root; 43 y.__left_ = 0; 44 y.__right_ = 0; 45 y.__parent_ = &x; 46 std::__tree_right_rotate(&x); 47 assert(root.__parent_ == 0); 48 assert(root.__left_ == &y); 49 assert(root.__right_ == 0); 50 assert(y.__parent_ == &root); 51 assert(y.__left_ == 0); 52 assert(y.__right_ == &x); 53 assert(x.__parent_ == &y); 54 assert(x.__left_ == 0); 55 assert(x.__right_ == 0); 56 } 57 58 void test2()59test2() 60 { 61 Node root; 62 Node x; 63 Node y; 64 Node a; 65 Node b; 66 Node c; 67 root.__left_ = &x; 68 x.__left_ = &y; 69 x.__right_ = &c; 70 x.__parent_ = &root; 71 y.__left_ = &a; 72 y.__right_ = &b; 73 y.__parent_ = &x; 74 a.__parent_ = &y; 75 b.__parent_ = &y; 76 c.__parent_ = &x; 77 std::__tree_right_rotate(&x); 78 assert(root.__parent_ == 0); 79 assert(root.__left_ == &y); 80 assert(root.__right_ == 0); 81 assert(y.__parent_ == &root); 82 assert(y.__left_ == &a); 83 assert(y.__right_ == &x); 84 assert(x.__parent_ == &y); 85 assert(x.__left_ == &b); 86 assert(x.__right_ == &c); 87 assert(a.__parent_ == &y); 88 assert(a.__left_ == 0); 89 assert(a.__right_ == 0); 90 assert(b.__parent_ == &x); 91 assert(b.__left_ == 0); 92 assert(b.__right_ == 0); 93 assert(c.__parent_ == &x); 94 assert(c.__left_ == 0); 95 assert(c.__right_ == 0); 96 } 97 main(int,char **)98int main(int, char**) 99 { 100 test1(); 101 test2(); 102 103 return 0; 104 } 105