PageRenderTime 15ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/tests/llmodularmath_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 76 lines | 39 code | 7 blank | 30 comment | 0 complexity | 8d182c6e09e50a391fcc65d1cc0ea16b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file modularmath_test.cpp
  3. * @author babbage
  4. * @date 2008-09
  5. * @brief llmodularmath tests
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "../llmodularmath.h"
  30. #include "../test/lltut.h"
  31. namespace tut
  32. {
  33. struct modularmath_data
  34. {
  35. };
  36. typedef test_group<modularmath_data> modularmath_test;
  37. typedef modularmath_test::object modularmath_object;
  38. tut::modularmath_test modularmath_testcase("LLModularMath");
  39. template<> template<>
  40. void modularmath_object::test<1>()
  41. {
  42. // lhs < rhs
  43. const U32 lhs = 0x000001;
  44. const U32 rhs = 0xFFFFFF;
  45. const U32 width = 24;
  46. U32 result = LLModularMath::subtract<width>(lhs, rhs);
  47. ensure_equals("diff(0x000001, 0xFFFFFF, 24)", result, 2);
  48. }
  49. template<> template<>
  50. void modularmath_object::test<2>()
  51. {
  52. // lhs > rhs
  53. const U32 lhs = 0x000002;
  54. const U32 rhs = 0x000001;
  55. const U32 width = 24;
  56. U32 result = LLModularMath::subtract<width>(lhs, rhs);
  57. ensure_equals("diff(0x000002, 0x000001, 24)", result, 1);
  58. }
  59. template<> template<>
  60. void modularmath_object::test<3>()
  61. {
  62. // lhs == rhs
  63. const U32 lhs = 0xABCDEF;
  64. const U32 rhs = 0xABCDEF;
  65. const U32 width = 24;
  66. U32 result = LLModularMath::subtract<width>(lhs, rhs);
  67. ensure_equals("diff(0xABCDEF, 0xABCDEF, 24)", result, 0);
  68. }
  69. }