OpenCores
URL https://opencores.org/ocsvn/connect-6/connect-6/trunk

Subversion Repositories connect-6

[/] [connect-6/] [trunk/] [CONNECTK/] [connectk-2.0/] [src/] [tests.c] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sumanta.ch
 
2
/*
3
 
4
connectk -- a program to play the connect-k family of games
5
Copyright (C) 2007 Michael Levin
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
*/
22
 
23
#include "config.h"
24
#include <gtk/gtk.h>
25
#include <glib/gprintf.h>
26
#include "shared.h"
27
#include "connectk.h"
28
 
29
/*
30
 *      Tests
31
 */
32
 
33
void dfs_cache_dump(void);
34
void sum_of_marks(void);
35
void debug_counts(void);
36
 
37
static char *achain_stat_string(AllocChain *ac, gsize mem)
38
{
39
        int used = 0, total = 0;
40
 
41
        while (ac) {
42
                total++;
43
                if (!ac->free)
44
                        used++;
45
                ac = ac->next;
46
        }
47
        return va("%d of %d in use, %d bytes allocated",
48
                  used, total, total * mem);
49
}
50
 
51
static void dump_stats(void)
52
{
53
        g_debug("Boards: %s",
54
                achain_stat_string(board_root, board_mem));
55
        g_debug("AIMoves: %s",
56
                achain_stat_string(aimoves_root, aimoves_mem));
57
}
58
 
59
void dump_board(const Board *b)
60
/* Print out a board to the console */
61
{
62
        int x, y;
63
 
64
        for (y = 0; y < board_size; y++) {
65
                for (x = 0; x < board_size; x++)
66
                        g_printf("%c", piece_to_char(piece_at(b, x, y)));
67
                g_print("\n");
68
        }
69
}
70
 
71
static void board_id(void)
72
{
73
        g_debug("Board id %d", board->ac.id);
74
}
75
 
76
typedef struct {
77
        char *desc;
78
        void (*func)(void);
79
} Test;
80
 
81
/* This array contains no argument functions which will appear in the tests
82
   menu */
83
static Test tests[] = {
84
        { "Memory Statistics", dump_stats },
85
        { "Board ID", board_id },
86
        { "Dump DFS cache", dfs_cache_dump },
87
        { "Sum of marks", sum_of_marks },
88
        { "Threat counts", debug_counts },
89
};
90
 
91
#define TESTS (sizeof (tests) / sizeof (tests[0]))
92
 
93
/*
94
 *      Test Interface
95
 */
96
 
97
static void test_menu_item_activate(GtkMenuItem *item, gpointer user_data)
98
{
99
        Test *test = (Test*)user_data;
100
 
101
        test->func();
102
}
103
 
104
void add_tests_to_menu_shell(GtkWidget *menu)
105
{
106
        GtkWidget *item;
107
        int i;
108
 
109
        for(i = 0; i < TESTS; i++) {
110
                item = gtk_menu_item_new_with_mnemonic(tests[i].desc);
111
                g_signal_connect(item, "activate",
112
                                 G_CALLBACK(test_menu_item_activate),
113
                                 tests + i);
114
                gtk_menu_attach(GTK_MENU(menu), item, 0, 1, i, i + 1);
115
        }
116
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.