예제 #1
0
TEST(Treap , Min)
{
    Treap* tr = new Treap(false);

    tr->Insert(1);
    tr->Insert(5);
    tr->Insert(2);
    tr->Insert(61);
    tr->Insert(61);
    tr->Insert(24);
    tr->Insert(51);
    tr->Insert(61);
    tr->Insert(57);
    tr->Insert(32);
    tr->Insert(24);

    CHECK(tr->Min() == 1);
    tr->Remove(1);
    tr->Remove(2);
    CHECK(tr->Min() == 5);
    tr->Remove(5);
    CHECK(tr->Min() == 24);
    tr->Remove(24);
    CHECK(tr->Min() == 32);
    tr->Remove(32);
    CHECK(tr->Min() == 51);
    tr->Remove(51);
    CHECK(tr->Min() == 57);
    tr->Remove(57);
    CHECK(tr->Min() == 61);
    tr->Remove(61);
    CHECK(tr->Min() == -1);

    delete tr;
}
예제 #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;
}