diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
commit | 3e519524c118651123eecf60c2bbc5d65ad9bac3 (patch) | |
tree | b2dd4168cfe448920a602cd7d2e40f95da187153 /libcxx/test/containers/associative/tree_right_rotate.pass.cpp | |
parent | 9132c59d43b6c590c9bb33496eebf9f192d6857a (diff) | |
download | bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.tar.gz bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.zip |
libcxx initial import
llvm-svn: 103490
Diffstat (limited to 'libcxx/test/containers/associative/tree_right_rotate.pass.cpp')
-rw-r--r-- | libcxx/test/containers/associative/tree_right_rotate.pass.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/libcxx/test/containers/associative/tree_right_rotate.pass.cpp b/libcxx/test/containers/associative/tree_right_rotate.pass.cpp new file mode 100644 index 00000000000..41721cf8d1b --- /dev/null +++ b/libcxx/test/containers/associative/tree_right_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__left_ != nullptr +// template <class _NodePtr> +// void +// __tree_right_rotate(_NodePtr __x); + +#include <__tree> +#include <cassert> + +struct Node +{ + Node* __left_; + Node* __right_; + Node* __parent_; + + Node() : __left_(), __right_(), __parent_() {} +}; + +void +test1() +{ + Node root; + Node x; + Node y; + root.__left_ = &x; + x.__left_ = &y; + x.__right_ = 0; + x.__parent_ = &root; + y.__left_ = 0; + y.__right_ = 0; + y.__parent_ = &x; + std::__tree_right_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == 0); + assert(y.__right_ == &x); + assert(x.__parent_ == &y); + assert(x.__left_ == 0); + assert(x.__right_ == 0); +} + +void +test2() +{ + Node root; + Node x; + Node y; + Node a; + Node b; + Node c; + root.__left_ = &x; + x.__left_ = &y; + x.__right_ = &c; + x.__parent_ = &root; + y.__left_ = &a; + y.__right_ = &b; + y.__parent_ = &x; + a.__parent_ = &y; + b.__parent_ = &y; + c.__parent_ = &x; + std::__tree_right_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == &a); + assert(y.__right_ == &x); + assert(x.__parent_ == &y); + assert(x.__left_ == &b); + assert(x.__right_ == &c); + assert(a.__parent_ == &y); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(b.__parent_ == &x); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(c.__parent_ == &x); + assert(c.__left_ == 0); + assert(c.__right_ == 0); +} + +int main() +{ + test1(); + test2(); +} |