Statistics
| Branch: | Tag: | Revision:

sssimulator / Matrix / Test / string_indexer_test.c @ master

History | View | Annotate | Download (1.72 KB)

1
/*
2
 * This is SSSim: the Simple & Stupid Simulator
3
 *
4
 *  Copyright (c) 2015 Luca Baldesi
5
 *
6
 *  This is free software; see gpl-3.0.txt
7
 */
8

    
9
#include <assert.h>
10
#include <stdio.h>
11
#include <string_indexer.h>
12

    
13
void string_indexer_new_test()
14
{
15
        struct string_indexer * si;
16

    
17
        si = string_indexer_new(0);
18
        assert(string_indexer_size(si) == 0);
19
        string_indexer_destroy(&si);
20

    
21
        si = string_indexer_new(30);
22
        assert(string_indexer_size(si) == 0);
23
        string_indexer_destroy(&si);
24

    
25
        fprintf(stderr,"%s successfully passed!\n",__func__);
26
}
27

    
28
void string_indexer_id_test()
29
{
30
        struct string_indexer *si = NULL;
31
        uint32_t i;
32

    
33
        string_indexer_id(NULL,"ciao");
34

    
35
        si = string_indexer_new(0);
36
        string_indexer_id(si,NULL);
37
        assert(string_indexer_size(si) == 0);
38

    
39
        i = string_indexer_id(si,"ciao");
40
        assert(string_indexer_size(si) == 1);
41
        assert(string_indexer_id(si,"ciao") == i);
42
        assert(string_indexer_size(si) == 1);
43

    
44
        assert(i != string_indexer_id(si,"hole"));
45
        assert(string_indexer_id(si,"ciao") == i);
46
        assert(string_indexer_size(si) == 2);
47

    
48
        string_indexer_destroy(&si);
49
        fprintf(stderr,"%s successfully passed!\n",__func__);
50
}
51

    
52
void string_indexer_size_test()
53
{
54
        struct string_indexer *si = NULL;
55

    
56
        assert(0 == string_indexer_size(NULL));
57

    
58
        string_indexer_destroy(&si);
59
        fprintf(stderr,"%s successfully passed!\n",__func__);
60
}
61

    
62
void string_indexer_destroy_test()
63
{
64
        struct string_indexer *si = NULL;
65

    
66
        string_indexer_destroy(NULL);
67

    
68
        si = string_indexer_new(0);
69
        string_indexer_destroy(&si);
70

    
71
        si = string_indexer_new(100);
72
        string_indexer_destroy(&si);
73

    
74
        fprintf(stderr,"%s successfully passed!\n",__func__);
75
}
76

    
77
int main(char ** argc,int argv)
78
{
79
        string_indexer_new_test();
80
        string_indexer_id_test();
81
        string_indexer_size_test();
82
        string_indexer_destroy_test();
83
        return 0;
84
}