common_value.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file tests/common_value.cpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #include "artis-star/common/event/Value.hpp"
  26. #define BOOST_TEST_MODULE Common_Value_Tests
  27. #include <boost/test/unit_test.hpp>
  28. /*************************************************
  29. * Tests
  30. *************************************************/
  31. BOOST_AUTO_TEST_CASE(Common_Value_TestCase_1)
  32. {
  33. artis::common::event::Value first_value{1};
  34. artis::common::event::Value second_value{1};
  35. BOOST_CHECK(first_value == second_value);
  36. }
  37. BOOST_AUTO_TEST_CASE(Common_Value_TestCase_2)
  38. {
  39. artis::common::event::Value int_value{1};
  40. artis::common::event::Value unsigned_int_value{(unsigned int) 1};
  41. artis::common::event::Value double_value{0.5};
  42. artis::common::event::Value bool_value{true};
  43. artis::common::event::Value char_value{'a'};
  44. BOOST_REQUIRE_EQUAL(int_value.to_string(), "1");
  45. BOOST_REQUIRE_EQUAL(unsigned_int_value.to_string(), "1");
  46. BOOST_REQUIRE_EQUAL(double_value.to_string(), "0.500000");
  47. BOOST_REQUIRE_EQUAL(bool_value.to_string(), "true");
  48. BOOST_REQUIRE_EQUAL(char_value.to_string(), "a");
  49. }
  50. BOOST_AUTO_TEST_CASE(Common_Value_TestCase_3)
  51. {
  52. int int_values[] = {1, 2, 3};
  53. artis::common::event::Value int_value{int_values, 3};
  54. unsigned int unsigned_int_values[] = {1, 2, 3};
  55. artis::common::event::Value unsigned_int_value{unsigned_int_values, 3};
  56. double double_values[] = {0.5, 0.6, 1.2};
  57. artis::common::event::Value double_value{double_values, 3};
  58. bool bool_values[] = {true, false, true, false};
  59. artis::common::event::Value bool_value{bool_values, 4};
  60. char char_values[] = {'a', 'b', 'c'};
  61. artis::common::event::Value char_value{char_values, 3};
  62. BOOST_REQUIRE_EQUAL(int_value.to_string(), "1 2 3 ");
  63. BOOST_REQUIRE_EQUAL(unsigned_int_value.to_string(), "1 2 3 ");
  64. BOOST_REQUIRE_EQUAL(double_value.to_string(), "0.500000 0.600000 1.200000 ");
  65. BOOST_REQUIRE_EQUAL(bool_value.to_string(), "true false true false ");
  66. BOOST_REQUIRE_EQUAL(char_value.to_string(), "abc");
  67. }
  68. BOOST_AUTO_TEST_CASE(Common_Value_TestCase_4)
  69. {
  70. struct S {
  71. } s;
  72. artis::common::event::Value value{s};
  73. BOOST_REQUIRE_EQUAL(value.to_string(), "<unstringify>");
  74. }