aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_sd.c
blob: a8f1c155e5fb9ccd3c6c9fa1dde4f357edfacba2 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
/*
      This file is part of GNUnet
      Copyright (C) 2008--2013 GNUnet e.V.

      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
      by the Free Software Foundation, either version 3 of the License,
      or (at your option) any later version.

      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
     
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * @file testbed/testbed_api_sd.c
 * @brief test cases for calculating standard deviation
 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
 */

#include "platform.h"
#include "gnunet_util_lib.h"
#include "testbed_api_sd.h"

/**
 * Global return value
 */
static int ret;

/**
 * Main run function.
 *
 * @param cls NULL
 * @param args arguments passed to GNUNET_PROGRAM_run
 * @param cfgfile the path to configuration file
 * @param cfg the configuration file handle
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *config)
{
  struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20);
  int sd;

  ret = 0;
  GNUNET_TESTBED_SD_add_data_ (h, 40);
  if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd))
  {
    GNUNET_break (0);
    ret = 1;
    goto err;
  }
  GNUNET_TESTBED_SD_add_data_ (h, 30);
  if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd))
  {
    GNUNET_break (0);
    ret = 1;
    goto err;
  }
  GNUNET_TESTBED_SD_add_data_ (h, 40);
  if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd))
      || (-2 != sd))
  {
    GNUNET_break (0);
    ret = 1;
    goto err;
  }
  GNUNET_TESTBED_SD_add_data_ (h, 10);
  GNUNET_TESTBED_SD_add_data_ (h, 30);
  if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd))
      || (3 != sd))
  {
    GNUNET_break (0);
    ret = 1;
    goto err;
  }

 err:
  GNUNET_TESTBED_SD_destroy_ (h);
}


/**
 * Main function
 */
int
main (int argc, char **argv)
{
  struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  int result;

  result = GNUNET_SYSERR;
  result =
      GNUNET_PROGRAM_run (argc, argv,
                          "test_testbed_api_sd", "nohelp", options, &run, NULL);
  if ((GNUNET_OK != result))
    return 1;
  return ret;
}

/* end of test_testbed_api_sd.c */