gen_linspace.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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("gen_linspace_1")
  19. {
  20. vec a = linspace(1,5,5);
  21. REQUIRE(a(0) == Approx(1.0));
  22. REQUIRE(a(1) == Approx(2.0));
  23. REQUIRE(a(2) == Approx(3.0));
  24. REQUIRE(a(3) == Approx(4.0));
  25. REQUIRE(a(4) == Approx(5.0));
  26. vec b = linspace<vec>(1,5,6);
  27. REQUIRE(b(0) == Approx(1.0));
  28. REQUIRE(b(1) == Approx(1.8));
  29. REQUIRE(b(2) == Approx(2.6));
  30. REQUIRE(b(3) == Approx(3.4));
  31. REQUIRE(b(4) == Approx(4.2));
  32. REQUIRE(b(5) == Approx(5.0));
  33. rowvec c = linspace<rowvec>(1,5,6);
  34. REQUIRE(c(0) == Approx(1.0));
  35. REQUIRE(c(1) == Approx(1.8));
  36. REQUIRE(c(2) == Approx(2.6));
  37. REQUIRE(c(3) == Approx(3.4));
  38. REQUIRE(c(4) == Approx(4.2));
  39. REQUIRE(c(5) == Approx(5.0));
  40. mat X = linspace<mat>(1,5,6);
  41. REQUIRE(X.n_rows == 6);
  42. REQUIRE(X.n_cols == 1);
  43. }