time_nodes.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* time_nodes.cpp - test time-related nodes
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program 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. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <catch.hpp>
  18. #include <core/node_info.h>
  19. #include <core/node/node.h>
  20. #include <core/context.h>
  21. #include "zero_context.h"
  22. using namespace rainynite;
  23. using namespace rainynite::core;
  24. TEST_CASE("Test TimeMap node", "[node]") {
  25. auto tmap = make_node_with_name<Node<double>>("TimeMap/Real");
  26. tmap->set_property("source", make_node_with_name<AbstractValue>("Linear"));
  27. CHECK(tmap->value(zero_context()) == 0.0);
  28. tmap->get_property("offset")->set_any(Time(1.0));
  29. CHECK(tmap->value(zero_context()) == 1.0);
  30. tmap->get_property("multiplier")->set_any(2.0);
  31. CHECK(tmap->value(zero_context()) == 1.0);
  32. tmap->get_property("offset")->set_any(Time(2.0));
  33. CHECK(tmap->value(zero_context()) == 2.0);
  34. auto ctx = make_shared<Context>();
  35. ctx->set_time(Time(0.5));
  36. CHECK(tmap->value(ctx) == 3.0);
  37. ctx->set_time(Time(1.0));
  38. CHECK(tmap->value(ctx) == 4.0);
  39. tmap->get_property("multiplier")->set_any(0.0);
  40. CHECK(tmap->value(ctx) == 2.0);
  41. }
  42. TEST_CASE("Test TimeList node", "[node]") {
  43. auto time_list = make_node_with_name<Node<vector<double>>>("TimeList/Real");
  44. time_list->get_property("step")->set_any(Time(1.0));
  45. time_list->get_property("period")->set_any(TimePeriod(Time(0.0), Time(2.0)));
  46. time_list->get_property("source")->set_any(0.0);
  47. CHECK((time_list->value(zero_context()) == vector<double>{0, 0}));
  48. time_list->set_property("source", make_node_with_name<AbstractValue>("Linear"));
  49. CHECK((time_list->value(zero_context()) == vector<double>{0, 1}));
  50. }