Esempio n. 1
0
void test_count_empty_params() {
    int ret_val = 0;

    ret_val = pl_count("", "One");
    assert_equal_int(
                -1,
                ret_val,
                "test_count_empty_params",
                "Test 1: Error code not returned."
            );

    ret_val = pl_count(NULL, "one");
    assert_equal_int(
                -1,
                ret_val,
                "test_count_empty_params",
                "Test 2: Error code not returned."
            );

    ret_val = pl_count("one three three seven", "");
    assert_equal_int(
                -1,
                ret_val,
                "test_count_empty_params",
                "Test 3: Error code not returned."
            );

    ret_val = pl_count("one three three seven", NULL);
    assert_equal_int(
                -1,
                ret_val,
                "test_count_empty_params",
                "Test 4: Error code not returned."
            );
}
Esempio n. 2
0
static void test_box_counter (struct test_solver_info *ts_info)
{
    int box_num, *box_count;
    MALLOC(box_count, ts_info->length);

    for (int n = 0; n < ts_info->length; n++) {
        for (int i = 0; i < ts_info->dim; i++) {
            ts_info->data[n][i] = n;
        }
    }
    box_num = box_counter((const double* const*)ts_info->data,
            ts_info->length, ts_info->dim, 1.0, box_count);
    assert_equal_int(ts_info->length, box_num);

    for (int n = 0; n < ts_info->length; n++) {
        for (int i = 0; i < ts_info->dim; i++) {
            ts_info->data[n][i] = 0;
        }
    }
    box_num = box_counter((const double* const*)ts_info->data,
            ts_info->length, ts_info->dim, 1.0, box_count);
    assert_equal_int(1, box_num);

    for (int n = 0; n < ts_info->length; n++) {
        for (int i = 0; i < ts_info->dim; i++) {
            ts_info->data[n][i] = (n % 10);
        }
    }
    box_num = box_counter((const double* const*)ts_info->data,
            ts_info->length, ts_info->dim, 1.0, box_count);
    assert_equal_int(10, box_num);

    FREE(box_count);
}
Esempio n. 3
0
void test_split() {
    int size = 0;
    char the_string[] = "fooasdbar";
    char **ret_val;

    ret_val = pl_split(the_string, "asd", &size);

    assert_equal_str(
                "foo",
                ret_val[0],
                "test_split",
                "Test 1: The strings are not equal."
            );

    assert_equal_str(
                "bar",
                ret_val[1],
                "test_split",
                "Test 2: The strings are not equal."
            );

    assert_equal_int(
                2,
                size,
                "test_split",
                "Test 3: Size is not correct."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val);
}
Esempio n. 4
0
static void test_new_rnn_runner (void)
{
    struct rnn_runner *runner;
    int stat = _new_rnn_runner(&runner);
    assert_equal_int(0, stat);
    mu_assert(runner != NULL);
    _delete_rnn_runner(runner);
}
Esempio n. 5
0
void test_endswith_empty_params() {
    int ret_val;

    ret_val = pl_endswith(NULL, ".com");
    assert_equal_int(
                -1,
                ret_val,
                "test_endswith_empty_params",
                "Test 1: -1 Not returned."
            );

    ret_val = pl_endswith("asd.com", NULL);
    assert_equal_int(
                -1,
                ret_val,
                "test_endswith_empty_params",
                "Test 1: -1 not returned."
            );
}
Esempio n. 6
0
void test_count() {
    int ret_val = 0;

    ret_val = pl_count("one one two three one two four", "one");
    assert_equal_int(
                3,
                ret_val,
                "test_count",
                "Test 1: Count not right"
            );

    ret_val = pl_count("one one two three one two four", "six");
    assert_equal_int(
                0,
                ret_val,
                "test_count",
                "Test 2: Count not right"
            );
}
Esempio n. 7
0
void test_startwith_empty_params() {
    int ret_val;

    ret_val = pl_startswith(NULL, "asd");
    assert_equal_int(
                -1,
                ret_val,
                "test_startwith_empty_params",
                "Test 1: -1 Not returned."
            );

    ret_val = pl_startswith("www.vg.no", NULL);
    assert_equal_int(
                -1,
                ret_val,
                "test_startwith_empty_params",
                "Test 2: -1 Not returned."
            );
}
Esempio n. 8
0
void test_endswith() {
    char the_string[] = "http://yahoo.com";

    int ret_val = pl_endswith(the_string, ".com");

    assert_equal_int(
                1,
                ret_val,
                "test_endswith",
                "Test 1: The strings does not end with .com"
            );

    ret_val = pl_endswith(the_string, ".net");

    assert_equal_int(
                0,
                ret_val,
                "test_endswith",
                "Test 2: The string does end with .net"
            );
}
Esempio n. 9
0
void test_startswith() {
    char the_string[] = "http://google.com";

    int ret_val = pl_startswith(the_string, "http://");

    assert_equal_int(
                1,
                ret_val,
                "test_startswith",
                "Test 1: The string does not start with http://"
            );

    ret_val = pl_startswith(the_string, "https://");

    assert_equal_int(
                0,
                ret_val,
                "test_startswith",
                "Test 2: The string starts with https://"
            );
}
Esempio n. 10
0
void test_endswith_empty_postfix() {
    char the_string[] = "http://duckduckgo.com";

    int ret_val = pl_endswith(the_string, "");

    assert_equal_int(
                -1,
                ret_val,
                "test_endswith_empty_postfix",
                "Error code not returned."
            );
}
Esempio n. 11
0
void test_startwith_empy_prefix() {
    char the_string[] = "http://bing.com";

    int ret_val = pl_startswith(the_string, "");

    assert_equal_int(
            -1,
            ret_val,
            "test_startwith_empy_prefix",
            "The function did not return the correct error value."
        );
}
Esempio n. 12
0
void test_endswith_empty_string() {
    char the_string[] = "";

    int ret_val = pl_endswith(the_string, "asd");

    assert_equal_int(
                -1,
                ret_val,
                "test_endswith_empty_string",
                "Error code not returned."
            );
}
Esempio n. 13
0
void test_startwith_empy_string() {
    char the_string[] = "";

    int ret_val = pl_startswith(the_string, "asd");

    assert_equal_int(
                -1,
                ret_val,
                "test_startwith_empy_string",
                "The function did not return the correct error value."
            );
}
Esempio n. 14
0
static void test_init_rnn_runner (
        struct test_rnn_runner_data *t_data,
        int in_state_size,
        int c_state_size,
        int out_state_size,
        int delay_length,
        rnn_output_t output_type,
        int target_num,
        int *target_length)
{
    struct recurrent_neural_network rnn;
    FILE *fp;

    init_recurrent_neural_network(&rnn, in_state_size, c_state_size,
            out_state_size);
    rnn.rnn_p.output_type = output_type;
    test_rnn_state_setup(&rnn, target_num, target_length);

    fp = tmpfile();
    if (fp == NULL) {
        print_error_msg("Cannot open tmpfile");
        exit(EXIT_FAILURE);
    }
    if (fwrite(&delay_length, sizeof(int), 1, fp) != 1) {
        print_error_msg();
        exit(EXIT_FAILURE);
    }
    fwrite_recurrent_neural_network(&rnn, fp);
    fseek(fp, 0L, SEEK_SET);
    init_rnn_runner(&t_data->runner, fp);
    fclose(fp);

    t_data->in_state_size = in_state_size;
    t_data->c_state_size = c_state_size;
    t_data->out_state_size = out_state_size;
    t_data->delay_length = delay_length;
    t_data->output_type = output_type;
    t_data->target_num = target_num;

    assert_equal_int(in_state_size,
            rnn_in_state_size_from_runner(&t_data->runner));
    assert_equal_int(c_state_size,
            rnn_c_state_size_from_runner(&t_data->runner));
    assert_equal_int(out_state_size,
            rnn_out_state_size_from_runner(&t_data->runner));
    assert_equal_int(delay_length,
            rnn_delay_length_from_runner(&t_data->runner));
    assert_equal_int((int)output_type,
            rnn_output_type_from_runner(&t_data->runner));
    assert_equal_int(target_num, rnn_target_num_from_runner(&t_data->runner));
    assert_equal_rnn_p(&rnn.rnn_p, &t_data->runner.rnn.rnn_p);
    for (int i = 0; i < target_num; i++) {
        assert_equal_rnn_s(rnn.rnn_s + i, t_data->runner.rnn.rnn_s + i);
    }
    free_recurrent_neural_network(&rnn);
}
Esempio n. 15
0
void test_splitlines_keepends() {
    char **ret_val = NULL;
    int size = 0;

    ret_val = pl_splitlines("asd\ndsa\n\rqwe", 1, &size);
    assert_equal_str(
                "asd\n",
                ret_val[0],
                "test_splitlines_keepends",
                "Test 1: Strings not equal."
            );

    assert_equal_str(
                "dsa\n",
                ret_val[1],
                "test_splitlines_keepends",
                "Test 2: Strings not equal."
            );

    assert_equal_str(
                "\r",
                ret_val[2],
                "test_splitlines_keepends",
                "Test 3: Strings not equal."
            );

    assert_equal_str(
                "qwe",
                ret_val[3],
                "test_splitlines_keepends",
                "Test 4: Strings not equal."
            );

    assert_equal_int(
                4,
                size,
                "test_splitlines_keepends",
                "Test 5: Size not right."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val[3]);
    free(ret_val);
}
Esempio n. 16
0
void test_splitlines() {
    char **ret_val = NULL;
    int size = 0;

    ret_val = pl_splitlines("asd\ndsa\n\rqwe", 0, &size);
    assert_equal_str(
                "asd",
                ret_val[0],
                "test_splitlines",
                "Test 1: Strings are not equal"
            );

    assert_equal_str(
                "dsa",
                ret_val[1],
                "test_splitlines",
                "Test 2: Strings are not equal."
            );

    assert_equal_str(
                "",
                ret_val[2],
                "test_splitlines",
                "Test 3: String is not empty."
            );

    assert_equal_str(
                "qwe",
                ret_val[3],
                "test_splitlines",
                "Test 4: Strings are not equal."
            );

    assert_equal_int(
                4,
                size,
                "test_splitlines",
                "Test 5: Size not right;"
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val[3]);
    free(ret_val);
}
Esempio n. 17
0
void test_split_delim_not_found() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "x", &size);

    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_delim_not_found",
                "Test 1: NULL not returned."
            );

    assert_equal_int(
                0,
                size,
                "test_split_delim_not_found",
                "Test 2: Size is not correct."
            );
}
Esempio n. 18
0
void test_split_empty_delim() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "", &size);

    assert_equal_str(
                NULL,
                (char *) ret_val,
                "test_split_empty_delim",
                "Test 1: NULL not returned."
            );

    assert_equal_int(
                0,
                size,
                "test_split_empty_delim",
                "Test 2: Size is not right."
            );
}
Esempio n. 19
0
void test_split_single_delim() {
    int size = 0;
    char the_string[] = "abc def ghi";
    char **ret_val;

    ret_val = pl_split(the_string, " ", &size);

    assert_equal_str(
                "abc",
                ret_val[0],
                "test_split_single_delim",
                "Test 1: Strings not equal."
            );

    assert_equal_str(
                "def",
                ret_val[1],
                "test_split_single_delim",
                "Test 2: Strings not equal."
            );

    assert_equal_str(
                "ghi",
                ret_val[2],
                "test_split_single_delim",
                "Test 3: Strings not equal."
            );

    assert_equal_int(
                3,
                size,
                "test_split_single_delim",
                "Test 4: Size of the returned array is not right."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val);
}
Esempio n. 20
0
void test_split_multiple_delims() {
    int size = 0;
    char the_string[] = "fooasdbarasdmagic";
    char **ret_val;

    ret_val = pl_split(the_string, "asd", &size);

    assert_equal_str(
                "foo",
                ret_val[0],
                "test_split_multiple_delims",
                "Test 1: Strings are not equal."
            );

    assert_equal_str(
                "bar",
                ret_val[1],
                "test_split_multiple_delims",
                "Test 2: Strings are not equal."
            );

    assert_equal_str(
                "magic",
                ret_val[2],
                "test_split_multiple_delims",
                "Test 3: Strings are not equal"
            );

    assert_equal_int(
                3,
                size,
                "test_split_multiple_delims",
                "Test 4: Size is not correct."
            );

    free(ret_val[0]);
    free(ret_val[1]);
    free(ret_val[2]);
    free(ret_val);
}
Esempio n. 21
0
static void test_rnn_out_state_size_from_runner (
        struct test_rnn_runner_data *t_data)
{
    assert_equal_int(t_data->out_state_size,
            rnn_out_state_size_from_runner(&t_data->runner));
}
Esempio n. 22
0
void test_mifare_desfire_key (void)
{
  mifare_desfire_key key;
  int version;
  
  uint8_t key1_des_data[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
  uint8_t key2_des_data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  
  uint8_t key1_3des_data[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                                0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0XEE, 0xFF};
  uint8_t key2_3des_data[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0X01, 0x00,
                                0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
  uint8_t key3_3des_data[16] = {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0X00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77};
    
  MifareDesKeyNew(&key, key1_des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 1");

  MifareDesKeyNewWithVersion(&key, key1_des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x55, version, "Wrong MifareDESFireKey version 2");
  
  MifareKeySetVersion(&key, 0xaa);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0xaa, version, "Wrong MifareDESFireKey version 3");
  
  MifareDesKeyNew(&key, key2_des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 4");
    
  MifareDesKeyNewWithVersion(&key, key2_des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 5");
    
  Mifare3DesKeyNew(&key, key1_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 6");
    
  Mifare3DesKeyNewWithVersion(&key, key1_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x55, version, "Wrong MifareDESFireKey version 7");
  
  MifareKeySetVersion(&key, 0xaa);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0xaa, version, "Wrong MifareDESFireKey version 8");
    
  Mifare3DesKeyNew(&key, key2_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 9");
  
  Mifare3DesKeyNewWithVersion(&key, key2_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x02, version, "Wrong MifareDESFireKey version 10");
    
  Mifare3DesKeyNew(&key, key3_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int(0x00, version, "Wrong MifareDESFireKey version 11");
  
  Mifare3DesKeyNewWithVersion(&key, key3_3des_data);
  version = MifareKeyGetVersion(&key);
  assert_equal_int (0x10, version, "Wrong MifareDESFireKey version 12");
}
Esempio n. 23
0
void testDummyHandlerAndE2HandlerHaveRunAfterEnoughTime(void) {
    _delay_ms(20);

    assert_equal_int(test_e2_arg, handler_flag_value);
}
Esempio n. 24
0
static void test_rnn_delay_length_from_runner (
        struct test_rnn_runner_data *t_data)
{
    assert_equal_int(t_data->delay_length,
            rnn_delay_length_from_runner(&t_data->runner));
}
Esempio n. 25
0
static void test_rnn_target_num_from_runner (
        struct test_rnn_runner_data *t_data)
{
    assert_equal_int(t_data->target_num,
            rnn_target_num_from_runner(&t_data->runner));
}
Esempio n. 26
0
static void test_rnn_output_type_from_runner (
        struct test_rnn_runner_data *t_data)
{
    assert_equal_int((int)t_data->output_type,
            rnn_output_type_from_runner(&t_data->runner));
}