etc
Check-in [5326ee38a0]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:moved test related macros to test.hxx
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5326ee38a0ec4af4248d06c95b0ba5c9f2ae4d20
User & Date: alzwded 2014-04-12 11:42:54
Context
2014-04-12
11:55
some cleanup check-in: ddf80e8868 user: alzwded tags: trunk
11:42
moved test related macros to test.hxx check-in: 5326ee38a0 user: alzwded tags: trunk
11:30
Add test bed for Pack class Also, add even more SDL_Delay before SDL_Quit because its timer thread is (apparently, out of pure observation) not joined and bad things happen. check-in: 821ccd6221 user: alzwded tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to t2048/pack.cpp.

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
...
271
272
273
274
275
276
277
278
279
280
281

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
            std::inserter(cells, cells.begin()),
            [&](cell_t* p) { return *p; });
    shift_(cells, anythingAccomplished);
    std::for_each(pointers_.rbegin(), pointers_.rend(), Translator(cells));
    return anythingAccomplished;
}

#define TEST_BEGIN(NAME) \
{ #NAME, [&]() { \
    /*clock_t t0 = clock();*/ \
    printf("%s: ", #NAME);

#define TEST_END(NAME) \
    printf("OK\n"); \
    /*printf("%s: test took %5.3fus to run\n", #NAME, (float)(clock() - t0)/1000.f/CLOCKS_PER_SEC);*/ \
    return 0; \
               }},

#ifdef TEST_PACK
# include <cassert>
# include <cstring>
//# include <ctime>

# define NELEMENTS(A) ( sizeof(A) / sizeof(A[0]) )

static struct {
    const char* name;
    int (*fn)();
} tests[] = {

    TEST_BEGIN(EmptyCellIsRemoved) {
        std::list<cell_t> line;
        line.push_back(0);
        line.push_back(0);
        std::list<cell_t> ref;
        ref.push_back(0); // particularity of the implementation, a value already on the edge is left as is since it would not affect the board results in any way (which pads with 0s anyway)
        int moved(0);
................................................................................
        line.push_back(0);
        line.push_back(randomValue);
        line.push_back(randomValue);
        int moved(0);
        shift_(line, moved);
        assert(moved);
    } TEST_END(EatingACellDoesNotMergeNewNeighbours)
};

int main(int argc, char* argv[])
{

    size_t i = 0;
    assert(argc == 2);
    if(argv[1][0] == '-' && argv[1][1] == 'l') {
        for(; i < NELEMENTS(tests); ++i) {
            printf("%s ", tests[i].name);
        }
        printf("\n");
        return 0;
    }
    for(; i < NELEMENTS(tests); ++i) {
        if(strcmp(argv[1], tests[i].name) == 0) {
            return tests[i].fn();
        }
    }
# define NO_TEST_FOUND false
    assert(NO_TEST_FOUND);
    return 255;
}
#endif







<
<
<
<
<
<
<
<
<
<
<

|
<
<

<
<
<
<
<
<
>







 







|

|
<
>
|
<
<
<
<
<
<
|
|
<
<
<
|
<
<
<
<
<

81
82
83
84
85
86
87











88
89


90






91
92
93
94
95
96
97
98
...
253
254
255
256
257
258
259
260
261
262

263
264






265
266



267





268
            std::inserter(cells, cells.begin()),
            [&](cell_t* p) { return *p; });
    shift_(cells, anythingAccomplished);
    std::for_each(pointers_.rbegin(), pointers_.rend(), Translator(cells));
    return anythingAccomplished;
}












#ifdef TEST_PACK
# include "test.hxx"









TEST_BUNDLE_BEGIN(tests) {
    TEST_BEGIN(EmptyCellIsRemoved) {
        std::list<cell_t> line;
        line.push_back(0);
        line.push_back(0);
        std::list<cell_t> ref;
        ref.push_back(0); // particularity of the implementation, a value already on the edge is left as is since it would not affect the board results in any way (which pads with 0s anyway)
        int moved(0);
................................................................................
        line.push_back(0);
        line.push_back(randomValue);
        line.push_back(randomValue);
        int moved(0);
        shift_(line, moved);
        assert(moved);
    } TEST_END(EatingACellDoesNotMergeNewNeighbours)
} TEST_BUNDLE_END(tests);

int main(int argc, char* argv[]) {

    int ret(0);
    TEST_MAIN(tests, ret, argc, argv);






    return ret;
}









#endif

Added t2048/test.hxx.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef TEST_HXX
#define TEST_HXX

#include <cassert>
#include <cstring>

/*
   My nice little test bed header.
*/

#define TEST_NELEMENTS(A) ( sizeof(A) / sizeof(A[0]) )

#define TEST_BUNDLE_BEGIN(BUNDLE_NAME) \
static struct { \
    const char* name; \
    int (*fn)(); \
} BUNDLE_NAME[] =

#define TEST_BEGIN(NAME) \
{ #NAME, [&]() { \
    printf("%s: ", #NAME);

#define TEST_END(NAME) \
    printf("OK\n"); \
    return 0; \
               }},

#define TEST_BUNDLE_END(BUNDLE_NAME)

#define NO_TEST_FOUND false
#define TEST_MAIN(BUNDLE_NAME, ret, argc, argv) \
do { \
    size_t i = 0; \
    assert(argc == 2); \
    if(argv[1][0] == '-' && argv[1][1] == 'l') { \
        for(; i < TEST_NELEMENTS(BUNDLE_NAME); ++i) { \
            printf("%s ", BUNDLE_NAME[i].name); \
        } \
        printf("\n"); \
        ret = 0; \
        break; \
    } \
    for(; i < TEST_NELEMENTS(BUNDLE_NAME); ++i) { \
        if(strcmp(argv[1], BUNDLE_NAME[i].name) == 0) { \
            return BUNDLE_NAME[i].fn(); \
        } \
    } \
    assert(NO_TEST_FOUND); \
    ret = 255; \
    break; \
} while(0)

#endif