Esempio n. 1
0
static void test_set_insert(CuTest * tc)
{
    struct quicklist *ql = NULL;
    int a, qi;
    a = ql_set_insert(&ql, (void *)data);
    CuAssertIntEquals(tc, 1, ql_length(ql));
    CuAssertIntEquals(tc, ql_true, a);
    a = ql_set_insert(&ql, (void *)(data + 1));
    CuAssertIntEquals(tc, 2, ql_length(ql));
    CuAssertIntEquals(tc, ql_true, a);
    a = ql_set_insert(&ql, (void *)data);
    CuAssertIntEquals(tc, 2, ql_length(ql));
    CuAssertIntEquals(tc, ql_false, a);
    a = ql_set_insert(&ql, (void *)(data + 2));
    CuAssertIntEquals(tc, ql_true, a);
    CuAssertIntEquals(tc, 3, ql_length(ql));
    CuAssertPtrEquals(tc, (void *)data, ql_get(ql, 0));
    CuAssertPtrEquals(tc, (void *)(data + 1), ql_get(ql, 1));
    CuAssertPtrEquals(tc, (void *)(data + 2), ql_get(ql, 2));

    a = ql_set_find(&ql, &qi, (void *)(data + 3));
    CuAssertIntEquals(tc, 0, a);
    a = ql_set_find(&ql, &qi, (void *)data);
    CuAssertIntEquals(tc, 1, a);
    CuAssertPtrEquals(tc, (void *)data, ql_get(ql, qi));
    ql_free(ql);
}
Esempio n. 2
0
static void test_set_insert_ex(CuTest * tc)
{
    const char * strings[] = {
        "aaa", "bbb", "ccc", "ddd"
    };
    struct quicklist *ql = NULL;
    int qi;

    /* insert a string: */
    CuAssertIntEquals(tc, ql_true, ql_set_insert_ex(&ql, (void *)strings[0], cmp_str));
    CuAssertIntEquals(tc, 1, ql_length(ql));

    /* insert a second string: */
    CuAssertIntEquals(tc, ql_true, ql_set_insert_ex(&ql, (void *)strings[1], cmp_str));
    CuAssertIntEquals(tc, 2, ql_length(ql));
    /* same string again, no change: */
    CuAssertIntEquals(tc, ql_false, ql_set_insert_ex(&ql, (void *)strings[1], cmp_str));
    CuAssertIntEquals(tc, 2, ql_length(ql));

    /* a third string */
    CuAssertIntEquals(tc, ql_true, ql_set_insert_ex(&ql, (void *)strings[2], cmp_str));
    CuAssertIntEquals(tc, 3, ql_length(ql));

    /* check that they are alphabetically ordered: */
    for (qi = 0; qi != 3; ++qi) {
        CuAssertPtrEquals(tc, (void *)strings[qi], ql_get(ql, qi));
    }

    CuAssertIntEquals(tc, 1, ql_set_find_ex(&ql, &qi, (void *)strings[2], cmp_str));
    CuAssertIntEquals(tc, 2, qi);
    ql_free(ql);
}
Esempio n. 3
0
static void test_push(CuTest * tc)
{
    struct quicklist *result, *ql = NULL;
    CuAssertIntEquals(tc, 0, ql_length(ql));
    result = ql_push(&ql, (void *)data);
    CuAssertPtrEquals(tc, result, ql);
    CuAssertIntEquals(tc, 1, ql_length(ql));
    CuAssertPtrEquals(tc, (void *)data, ql_get(ql, 0));
    ql_delete(&ql, 0);
    CuAssertPtrEquals(tc, 0, ql);
}
Esempio n. 4
0
static void test_delete_rand(CuTest * tc)
{
    struct quicklist *ql = NULL;
    int i;
    for (i = 0; i != 32; ++i) {
        ql_push(&ql, (void *)(data + i));
    }
    CuAssertIntEquals(tc, 32, ql_length(ql));
    ql_delete(&ql, 0);
    CuAssertPtrEquals(tc, (void *)(data + 1), ql_get(ql, 0));
    CuAssertIntEquals(tc, 31, ql_length(ql));
    ql_delete(&ql, 30);
    CuAssertIntEquals(tc, 30, ql_length(ql));
    ql_free(ql);
}
Esempio n. 5
0
static void test_remove_empty_factions_alliance(CuTest *tc) {
    faction *f;
    struct alliance *al;

    test_cleanup();
    f = test_create_faction(0);
    al = makealliance(0, "Hodor");
    setalliance(f, al);
    CuAssertPtrEquals(tc, f, alliance_get_leader(al));
    CuAssertIntEquals(tc, 1, ql_length(al->members));
    remove_empty_factions();
    CuAssertPtrEquals(tc, 0, al->_leader);
    CuAssertIntEquals(tc, 0, ql_length(al->members));
    test_cleanup();
}
Esempio n. 6
0
static void test_seen_faction(CuTest *tc) {
    faction *f1, *f2;
    race *rc = test_create_race("human");
    f1 = test_create_faction(rc);
    f2 = test_create_faction(rc);
    add_seen_faction(f1, f2);
    CuAssertPtrEquals(tc, f2, ql_get(f1->seen_factions, 0));
    CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions));
    add_seen_faction(f1, f2);
    CuAssertIntEquals(tc, 1, ql_length(f1->seen_factions));
    add_seen_faction(f1, f1);
    CuAssertIntEquals(tc, 2, ql_length(f1->seen_factions));
    f2 = (faction *)ql_get(f1->seen_factions, 1);
    f1 = (faction *)ql_get(f1->seen_factions, 0);
    CuAssertTrue(tc, f1->no < f2->no);
}
Esempio n. 7
0
static void test_insert_many(CuTest * tc)
{
    struct quicklist *ql = NULL;
    int i;
    for (i = 0; i != 32; ++i) {
        ql_push(&ql, (void *)(data + i));
    }
    for (i = 0; i != 32; ++i) {
        CuAssertIntEquals(tc, 32 - i, ql_length(ql));
        CuAssertPtrEquals(tc, (void *)(data + i), ql_get(ql, 0));
        CuAssertPtrEquals(tc, (void *)(data + 31), ql_get(ql, ql_length(ql) - 1));
        ql_delete(&ql, 0);
    }
    CuAssertPtrEquals(tc, 0, ql);
    ql_free(ql);
}
Esempio n. 8
0
static void test_set_remove(CuTest * tc)
{
    struct quicklist *ql = NULL, *q2;
    int a;

    ql_set_insert(&ql, (void *)data);
    ql_set_insert(&ql, (void *)(data + 1));
    ql_set_insert(&ql, (void *)(data + 2));

    q2 = ql;

    a = ql_set_remove(&ql, (void *)(data + 1));
    CuAssertIntEquals(tc, ql_true, a);
    CuAssertPtrEquals(tc, q2, ql);
    CuAssertPtrEquals(tc, (void *)data, ql_get(ql, 0));
    CuAssertPtrEquals(tc, (void *)(data + 2), ql_get(ql, 1));
    CuAssertIntEquals(tc, 2, ql_length(ql));

    a = ql_set_remove(&ql, (void *)(data + 1));
    CuAssertIntEquals(tc, ql_false, a);
    CuAssertPtrEquals(tc, q2, ql);

    a = ql_set_remove(&ql, (void *)data);
    CuAssertIntEquals(tc, ql_true, a);
    a = ql_set_remove(&ql, (void *)(data + 2));
    CuAssertIntEquals(tc, ql_true, a);
    CuAssertPtrEquals(tc, 0, ql);

    ql_free(ql);
}
Esempio n. 9
0
static void test_delete_edgecases(CuTest * tc)
{
    struct quicklist *ql = NULL;
    ql_delete(&ql, 0);
    CuAssertPtrEquals(tc, 0, ql);
    ql_push(&ql, (void *)data);
    ql_delete(&ql, -1);
    ql_delete(&ql, 32);
    CuAssertIntEquals(tc, 1, ql_length(ql));
    ql_free(ql);
}
Esempio n. 10
0
/** randomly shuffle an array
 * for correctness, see Donald E. Knuth, The Art of Computer Programming
 */
static void scramble_fighters(quicklist * ql)
{
    int qi, qlen = ql_length(ql);

    for (qi = 0; qi != qlen; ++qi) {
        int qj = qi + (rng_int() % (qlen - qi));
        void *a = ql_get(ql, qi);
        void *b = ql_replace(ql, qj, a);
        ql_replace(ql, qi, b);
    }
}
Esempio n. 11
0
static void test_insert(CuTest * tc)
{
    struct quicklist *ql = NULL;
    int i;
    for (i = 0; i != 32; ++i) {
        CuAssertIntEquals(tc, i, ql_length(ql));
        ql_insert(&ql, 0, (void *)(data + 31 - i));
    }
    for (i = 0; i != 32; ++i) {
        CuAssertPtrEquals(tc, (void *)(data + i), ql_get(ql, i));
    }
    ql_free(ql);
}
Esempio n. 12
0
void test_updatespells(CuTest * tc)
{
  faction * f;
  spell * sp;
  spellbook *book = 0;

  test_cleanup();
  
  f = test_create_faction(0);
  sp = create_spell("testspell", 0);
  CuAssertPtrNotNull(tc, sp);

  book = create_spellbook("spells");
  CuAssertPtrNotNull(tc, book);
  spellbook_add(book, sp, 1);

  CuAssertPtrEquals(tc, 0, f->spellbook);
  pick_random_spells(f, 1, book, 1);
  CuAssertPtrNotNull(tc, f->spellbook);
  CuAssertIntEquals(tc, 1, ql_length(f->spellbook->spells));
  CuAssertPtrNotNull(tc, spellbook_get(f->spellbook, sp));
}
Esempio n. 13
0
static void test_insert_atend(CuTest * tc)
{
    struct quicklist *ql = NULL;
    ql_iter qi;
    int i;
    for (i = 0; i != QL_MAXSIZE; ++i) {
        ql_insert(&ql, i, (void *)(data + i));
    }
    CuAssertIntEquals(tc, QL_MAXSIZE, ql_length(ql));
    qi = qli_init(&ql);
    for (i = 0; qli_more(qi); ++i) {
        void *ptr = qli_next(&qi);
        CuAssertPtrEquals(tc, (void *)(data + i), ptr);
        if (i < QL_MAXSIZE - 1) {
            CuAssertPtrEquals(tc, ql, qi.l);
        }
        else {
            CuAssertPtrEquals(tc, 0, qi.l);
        }
    }
    ql_free(ql);
}
Esempio n. 14
0
static void test_empty_list(CuTest * tc)
{
    CuAssertIntEquals(tc, 0, ql_length(0));
}