Пример #1
0
END_TEST

START_TEST (test_split_str_i) {
    int ret;
    i_array * v;
    i_array * exp;
    v = init_i_array(1);
    exp = init_i_array(1);
    char * string = "1\t22\t-432";
    append_i_array(exp, 1);
    append_i_array(exp, 22);
    append_i_array(exp, -432);
    ret = split_str_i(string, v, 0);
    ck_assert_int_eq(ret, 0);
    ck_assert_int_eq(v->length, 3);
    ck_assert_msg((i_arrays_equal(v, exp) != 0),
            "unexpected result of `split_str_i`");
    ret = split_str_i(string, v, 3);
    ck_assert_int_eq(ret, 0);
    ret = split_str_i(string, v, 4);
    ck_assert_int_eq(ret, 3);
    ck_assert_msg((i_arrays_equal(v, exp) != 0),
            "unexpected result of `split_str_i`");
    free_i_array(v);
    free_i_array(exp);
}
Пример #2
0
END_TEST

START_TEST (test_get_i_array_2d) {
    int size, el_size, i, ret;
    i_array_2d * v;
    i_array * ia1;
    i_array * ia2;
    el_size = 3;
    ia1 = init_i_array(el_size);
    ia2 = init_i_array(el_size);
    for (i = 0; i < el_size; i++) {
        append_i_array(ia1, i);
        append_i_array(ia2, (el_size + i));
    }
    size = 1;
    v = init_i_array_2d(size, el_size);
    append_i_array_2d(v, ia1);
    ret = i_arrays_equal(get_i_array_2d(v, 0), ia1);
    ck_assert_msg((ret != 0), "`i_array_2d` element is incorrect");
    append_i_array_2d(v, ia2);
    ret = i_arrays_equal(get_i_array_2d(v, 1), ia2);
    ck_assert_msg((ret != 0), "`i_array_2d` element is incorrect");

    free_i_array_2d(v);
    free_i_array(ia1);
    free_i_array(ia2);
}
Пример #3
0
END_TEST

START_TEST (test_set_i_array_2d) {
    int size, el_size, i, ret;
    i_array_2d * v;
    i_array * ia1;
    i_array * ia2;
    el_size = 3;
    ia1 = init_i_array(el_size);
    ia2 = init_i_array(el_size);
    for (i = 0; i < el_size; i++) {
        append_i_array(ia1, i);
        append_i_array(ia2, (el_size + i));
    }
    size = 1;
    v = init_i_array_2d(size, el_size);
    append_i_array_2d(v, ia1);
    ret = i_arrays_equal(v->a[0], ia1);
    ck_assert_msg((ret != 0), "`i_array_2d` element %d is incorrect: %d %d %d",
            0, v->a[0]->a[0], v->a[0]->a[1], v->a[0]->a[2]);
    set_i_array_2d(v, 0, ia2);
    ret = i_arrays_equal(v->a[0], ia2);
    ck_assert_msg((ret != 0), "`i_array_2d` element %d is incorrect: %d %d %d",
            0, v->a[0]->a[0], v->a[0]->a[1], v->a[0]->a[2]);

    free_i_array_2d(v);
    free_i_array(ia1);
    free_i_array(ia2);
}
Пример #4
0
END_TEST

START_TEST (test_append_i_array_2d) {
    int size, el_size, i, ret;
    i_array_2d * v;
    i_array * ia1;
    i_array * ia2;
    el_size = 3;
    ia1 = init_i_array(el_size);
    ia2 = init_i_array(el_size);
    for (i = 0; i < el_size; i++) {
        append_i_array(ia1, i);
        append_i_array(ia2, (el_size + i));
    }
    size = 1;
    v = init_i_array_2d(size, el_size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    append_i_array_2d(v, ia1);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 1);
    ret = i_arrays_equal(v->a[0], ia1);
    ck_assert_msg((ret != 0), "`i_array_2d` element is incorrect");
    append_i_array_2d(v, ia2);
    ck_assert_int_eq(v->capacity, size*2);
    ck_assert_int_eq(v->length, 2);
    ret = i_arrays_equal(v->a[1], ia2);
    ck_assert_msg((ret != 0), "`i_array_2d` element is incorrect");

    free_i_array_2d(v);
    free_i_array(ia1);
    free_i_array(ia2);
}
Пример #5
0
END_TEST

START_TEST (test_generate_int_partitions_n4) {
    int n, i;
    n = 4;
    i_array * expected = init_i_array(1);
    i_array_2d * partitions = init_i_array_2d(1,1);
    partitions = generate_int_partitions(n);
    ck_assert_int_eq(partitions->length, 5);
    i = 0;
    expected->length = 0;
    append_i_array(expected, 4);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, i),
            expected) != 0),
            "unexpected partition");
    i = 1;
    expected->length = 0;
    append_i_array(expected, 3);
    append_i_array(expected, 1);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, i),
            expected) != 0),
            "unexpected partition");
    i = 2;
    expected->length = 0;
    append_i_array(expected, 2);
    append_i_array(expected, 2);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, i),
            expected) != 0),
            "unexpected partition");
    i = 3;
    expected->length = 0;
    append_i_array(expected, 2);
    append_i_array(expected, 1);
    append_i_array(expected, 1);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, i),
            expected) != 0),
            "unexpected partition");
    i = 4;
    expected->length = 0;
    append_i_array(expected, 1);
    append_i_array(expected, 1);
    append_i_array(expected, 1);
    append_i_array(expected, 1);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, i),
            expected) != 0),
            "unexpected partition");
    free_i_array(expected);
    free_i_array_2d(partitions);
}
Пример #6
0
END_TEST

START_TEST (test_i_arrays_equal) {
    int size, ret;
    i_array * v1;
    i_array * v2;
    int s = 1;
    size = 3;
    v1 = init_i_array(size);
    v2 = init_i_array(size);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`i_array`s not equal, but should be");
    append_i_array(v1, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`i_array`s equal, but should not be");
    append_i_array(v2, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`i_array`s not equal, but should be");
    s = 2;
    append_i_array(v1, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`i_array`s equal, but should not be");
    append_i_array(v2, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`i_array`s not equal, but should be");
    append_i_array(v1, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`i_array`s equal, but should not be");
    s = 3;
    append_i_array(v2, s);
    ret = i_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`i_array`s equal, but should not be");
    free_i_array(v1);
    free_i_array(v2);
}
Пример #7
0
END_TEST

START_TEST (test_generate_int_partitions_n1) {
    int n;
    n = 1;
    i_array * expected = init_i_array(1);
    i_array_2d * partitions = init_i_array_2d(1,1);
    partitions = generate_int_partitions(n);
    ck_assert_int_eq(partitions->length, 1);
    append_i_array(expected, 1);
    ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, 0),
            expected) != 0),
            "unexpected partition");
    free_i_array(expected);
    free_i_array_2d(partitions);
}