Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, April 19, 2024

File: [Platon] / libco / test / vector.c (download)

Revision 1.4, Sun Mar 30 10:27:38 2003 UTC (21 years ago) by yenar


Changes since 1.3: +11 -8 lines

adapt to libco changes [clone.c, delegation.c, exception.c, python.c, string.c, vector.c]

/***{{{*******************************************************************
 * This file is part of libco - object library for C                     *
 * Copyright (c) 2002 Peter Rockai (yenar) <yenar@host.sk>               *
 *                                                                       *
 * This program is free software; you can redistribute it and/or         *
 * modify it under the terms of the GNU General Public                   *
 * License as published by the Free Software Foundation; either          *
 * version 2 of the License, or (at your option) any later version.      *
 *                                                                       *
 * This program is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 * General Public License for more details.                              *
 *                                                                       *
 * You should have received a copy of the GNU General Public License     *
 * along with this program; see the file COPYING.  If not, write to      *
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
 * Boston, MA 02111-1307, USA.                                           *
 *******************************************************************}}}***/
/* {{{ file description */
/**
 * @file vector.c
 * @brief Test libco's vector object.
 **/
/* }}} */

/* {{{ includes */
#include "co_vector.h"
#include "test_util.h"
#include "co_conv.h"
#include <limits.h>
/* }}} */

#include "vector.cometa"

#define ITEMS 1000
/* {{{ */ int main (void)
{
    co v;
    int i, j, last;
    co_o_small item;

    co super;
    super = co_init ();
    __co_file_init_vector_c (super);

    v = co_vector_new ();

    for (i = 0; i < ITEMS; i ++) {
        j = (int)(1+(50000.0*rand()/(RAND_MAX+1.0)));
        CO_DEBUG (1, "appending value: %d ", j);
        item = co_vector_item_new ();
        M (item, bless, co_t_int, j);
        CO_M (v, item_add, item);
    }
    CO_M (v, sort);
    //last = 0xFFFFFFFFFFFFLL;
    last = 0;
    for (i = 0; i < ITEMS; i ++) {
        item = CO_M (v, item_get, i) . _co;
        j = CO_A (int, item, v);
        CO_DEBUG (1, "item: %d, last: %d", j, last);
        if (j < last)
            error (1, "sorting failed (bad order)\n");
        last = j;
    }
    item = CO_M (v, item_get, ITEMS - 1) . _co;
    last = CO_A (int, item, v);
    for (i = 0; i < ITEMS; i ++)
    {
        if (i == ITEMS - 1) {
            item = CO_M (v, item_get, 0) . _co;
            if (last != CO_A (int, item, v))
                error (1, "removal isn't working properly\n");
        }
        CO_M (v, item_remove, 0);
    }
    CO_M (v, delete);

    return 0;
} /* }}} */

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top