示例#1
0
TEST(Treap , InsertFind)
{
    Treap* tr = new Treap(false);
    BinarySearchTree* bst = new BinarySearchTree(false);

    size_t n=5000;
    uint32_t* A = (uint32_t*)malloc(n*sizeof(uint32_t));
    for (size_t i=0; i<n; i++) A[i] = rand() % 5001;
    for (size_t i=0; i<n; i++) {
        tr->Insert(A[i]);
        bst->Insert(A[i]);
    }
    for (size_t i=0; i<n; i++) {
        CHECK(tr->Find(A[i]) == bst->Find(A[i]));
        CHECK(tr->Find(A[i]+1) == bst->Find(A[i]+1));
    }
    delete tr;
    delete bst;
    free(A);
}
示例#2
0
TEST(Treap , Remove)
{
    Treap* tr = new Treap(false);
    size_t n=5000;
    uint32_t* A = (uint32_t*)malloc(n*sizeof(uint32_t));
    for (size_t i=0; i<n; i++) A[i] = rand() % 5001;

    for (size_t i=0; i<n; i++) tr->Insert(A[i]);
    for (size_t i=1; i<n; i+=2) tr->Remove(A[i]);

    for (size_t i=0; i<n; i++) {
        if (i%2==1) {
            CHECK(tr->Find(A[i]) == false);
        }
    }

    free(A);
    delete tr;
}