fn_all.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2015 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2015 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. #include <armadillo>
  16. #include "catch.hpp"
  17. using namespace arma;
  18. TEST_CASE("fn_all_1")
  19. {
  20. vec a(5, fill::zeros);
  21. vec b(5, fill::zeros); b(0) = 1.0;
  22. vec c(5, fill::ones );
  23. REQUIRE( all(a) == false);
  24. REQUIRE( all(b) == false);
  25. REQUIRE( all(c) == true );
  26. REQUIRE( all(a(span::all)) == false);
  27. REQUIRE( all(b(span::all)) == false);
  28. REQUIRE( all(c(span::all)) == true );
  29. REQUIRE( all( c - c) == false);
  30. REQUIRE( all(2*c -2*c) == false);
  31. REQUIRE( all(c < 0.5) == false);
  32. REQUIRE( all(c > 0.5) == true );
  33. }
  34. TEST_CASE("fn_all_2")
  35. {
  36. mat A(5, 6, fill::zeros);
  37. mat B(5, 6, fill::zeros); B(0,0) = 1.0;
  38. mat C(5, 6, fill::ones );
  39. REQUIRE( all(vectorise(A)) == false);
  40. REQUIRE( all(vectorise(B)) == false);
  41. REQUIRE( all(vectorise(C)) == true );
  42. REQUIRE( all(vectorise(A(span::all,span::all))) == false);
  43. REQUIRE( all(vectorise(B(span::all,span::all))) == false);
  44. REQUIRE( all(vectorise(C(span::all,span::all))) == true );
  45. REQUIRE( all(vectorise( C - C)) == false);
  46. REQUIRE( all(vectorise(2*C -2*C)) == false);
  47. REQUIRE( all(vectorise(C) < 0.5) == false);
  48. REQUIRE( all(vectorise(C) > 0.5) == true );
  49. }
  50. TEST_CASE("fn_all_3")
  51. {
  52. mat A(5, 6, fill::zeros);
  53. mat B(5, 6, fill::zeros); B(0,0) = 1.0;
  54. mat C(5, 6, fill::ones );
  55. mat D(5, 6, fill::ones ); D(0,0) = 0.0;
  56. REQUIRE( accu( all(A) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  57. REQUIRE( accu( all(A,0) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  58. REQUIRE( accu( all(A,1) == uvec ({0, 0, 0, 0, 0} ) ) == 5 );
  59. REQUIRE( accu( all(B) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  60. REQUIRE( accu( all(B,0) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  61. REQUIRE( accu( all(B,1) == uvec ({0, 0, 0, 0, 0} ) ) == 5 );
  62. REQUIRE( accu( all(C) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  63. REQUIRE( accu( all(C,0) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  64. REQUIRE( accu( all(C,1) == uvec ({1, 1, 1, 1, 1} ) ) == 5 );
  65. REQUIRE( accu( all(D) == urowvec({0, 1, 1, 1, 1, 1}) ) == 6 );
  66. REQUIRE( accu( all(D,0) == urowvec({0, 1, 1, 1, 1, 1}) ) == 6 );
  67. REQUIRE( accu( all(D,1) == uvec ({0, 1, 1, 1, 1} ) ) == 5 );
  68. }