fn_any.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_any_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( any(a) == false);
  24. REQUIRE( any(b) == true );
  25. REQUIRE( any(c) == true );
  26. REQUIRE( any(a(span::all)) == false);
  27. REQUIRE( any(b(span::all)) == true );
  28. REQUIRE( any(c(span::all)) == true );
  29. REQUIRE( any( c - c) == false);
  30. REQUIRE( any(2*c -2*c) == false);
  31. REQUIRE( any(c < 0.5) == false);
  32. REQUIRE( any(c > 0.5) == true );
  33. }
  34. TEST_CASE("fn_any_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( any(vectorise(A)) == false);
  40. REQUIRE( any(vectorise(B)) == true );
  41. REQUIRE( any(vectorise(C)) == true );
  42. REQUIRE( any(vectorise(A(span::all,span::all))) == false);
  43. REQUIRE( any(vectorise(B(span::all,span::all))) == true );
  44. REQUIRE( any(vectorise(C(span::all,span::all))) == true );
  45. REQUIRE( any(vectorise( C - C)) == false);
  46. REQUIRE( any(vectorise(2*C -2*C)) == false);
  47. REQUIRE( any(vectorise(C) < 0.5) == false);
  48. REQUIRE( any(vectorise(C) > 0.5) == true );
  49. }
  50. TEST_CASE("fn_any_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( any(A) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  57. REQUIRE( accu( any(A,0) == urowvec({0, 0, 0, 0, 0, 0}) ) == 6 );
  58. REQUIRE( accu( any(A,1) == uvec ({0, 0, 0, 0, 0} ) ) == 5 );
  59. REQUIRE( accu( any(B) == urowvec({1, 0, 0, 0, 0, 0}) ) == 6 );
  60. REQUIRE( accu( any(B,0) == urowvec({1, 0, 0, 0, 0, 0}) ) == 6 );
  61. REQUIRE( accu( any(B,1) == uvec ({1, 0, 0, 0, 0} ) ) == 5 );
  62. REQUIRE( accu( any(C) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  63. REQUIRE( accu( any(C,0) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  64. REQUIRE( accu( any(C,1) == uvec ({1, 1, 1, 1, 1} ) ) == 5 );
  65. REQUIRE( accu( any(D) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  66. REQUIRE( accu( any(D,0) == urowvec({1, 1, 1, 1, 1, 1}) ) == 6 );
  67. REQUIRE( accu( any(D,1) == uvec ({1, 1, 1, 1, 1} ) ) == 5 );
  68. }