d4fa7af8442ca198b11b89a68963ea9974fabf82
[oweals/gnunet.git] / src / testbed / test_testbed_api_sd.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21
22 /**
23  * @file testbed/testbed_api_sd.c
24  * @brief test cases for calculating standard deviation
25  * @author Sree Harsha Totakura <sreeharsha@totakura.in> 
26  */
27
28 #include "platform.h"
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "testbed_api_sd.h"
32
33 /**
34  * Global return value
35  */
36 static int ret;
37
38 /**
39  * Main run function.
40  *
41  * @param cls NULL
42  * @param args arguments passed to GNUNET_PROGRAM_run
43  * @param cfgfile the path to configuration file
44  * @param cfg the configuration file handle
45  */
46 static void
47 run (void *cls, char *const *args, const char *cfgfile,
48      const struct GNUNET_CONFIGURATION_Handle *config)
49 {
50   struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20);
51   int sd;
52
53   ret = 0;
54   GNUNET_TESTBED_SD_add_data_ (h, 40);
55   if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd))
56   {
57     GNUNET_break (0);
58     ret = 1;
59     goto err;
60   }
61   GNUNET_TESTBED_SD_add_data_ (h, 30); 
62   if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd))
63   {
64     GNUNET_break (0);
65     ret = 1;
66     goto err;
67   }
68   GNUNET_TESTBED_SD_add_data_ (h, 40);
69   if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd))
70       || (-2 != sd))
71   {
72     GNUNET_break (0);
73     ret = 1;
74     goto err;
75   }
76   GNUNET_TESTBED_SD_add_data_ (h, 10);
77   GNUNET_TESTBED_SD_add_data_ (h, 30);
78   if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd))
79       || (3 != sd))
80   {
81     GNUNET_break (0);
82     ret = 1;
83     goto err;
84   }
85
86  err:
87   GNUNET_TESTBED_SD_destroy_ (h);
88 }
89
90
91 /**
92  * Main function
93  */
94 int
95 main (int argc, char **argv)
96 {
97   struct GNUNET_GETOPT_CommandLineOption options[] = {
98     GNUNET_GETOPT_OPTION_END
99   };
100   int result;
101
102   result = GNUNET_SYSERR;
103   result =
104       GNUNET_PROGRAM_run (argc, argv,
105                           "test_testbed_api_sd", "nohelp", options, &run, NULL);
106   if ((GNUNET_OK != result))
107     return 1;
108   return ret;
109 }
110
111 /* end of test_testbed_api_sd.c */