2
0

test_testbed_api_sd.c 2.7 KB

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