1.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // 20020717 gdr
  2. // Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. // Test slice class invariants
  17. #include <valarray>
  18. #include <cstdlib>
  19. #include <testsuite_hooks.h>
  20. bool
  21. construction(std::size_t start, std::size_t size, std::size_t stride)
  22. {
  23. std::slice s(start, size, stride);
  24. return s.start() == start && s.size() == size && s.stride() == stride;
  25. }
  26. bool
  27. copy(std::size_t start, std::size_t size, std::size_t stride)
  28. {
  29. std::slice s(start, size, stride);
  30. std::slice t = s;
  31. return t.start() == start && t.size() == size && t.stride() == stride;
  32. }
  33. bool
  34. assignment(std::size_t start, std::size_t size, std::size_t stride)
  35. {
  36. std::slice s(start, size, stride);
  37. std::slice t;
  38. t = s;
  39. return t.start() == start && t.size() == size && t.stride() == stride;
  40. }
  41. int main()
  42. {
  43. std::srand(20020717);
  44. using std::rand;
  45. VERIFY(construction(rand(), rand(), rand()));
  46. VERIFY(copy(rand(), rand(), rand()));
  47. VERIFY(assignment(rand(), rand(), rand()));
  48. return 0;
  49. }