new_node.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* new_node.cpp - test new node system
  2. * Copyright (C) 2017-2018 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/make.h>
  19. #include <core/node_info/node_info.h>
  20. #include "zero_context.h"
  21. #include "new_node.h"
  22. using namespace rainynite;
  23. using namespace rainynite::core;
  24. TEST_CASE("New node system: simple Add node", "[node]") {
  25. auto add = make_shared<Add>();
  26. CHECK(add->value(zero_context()) == 0);
  27. add->set_property("a", make_value<double>(1));
  28. CHECK(add->value(zero_context()) == 1);
  29. add->set_property("b", make_value<double>(2));
  30. CHECK(add->value(zero_context()) == 3);
  31. }
  32. TEST_CASE("New node system: custom properties", "[node]") {
  33. auto add = make_shared<Add>();
  34. CHECK_THROWS_AS(add->get_property("_custom"), NodeAccessError);
  35. auto zero = make_value<double>(0);
  36. add->set_property("_custom", zero);
  37. CHECK(add->get_property("_custom") == zero);
  38. CHECK(add->get_link(add->link_count()-1) == zero);
  39. add->remove(add->link_count()-1);
  40. CHECK_THROWS_AS(add->get_property("_custom"), NodeAccessError);
  41. }
  42. TEST_CASE("New node system: test set_any_at (Linear)", "[node]") {
  43. auto one_context = make_shared<Context>(*zero_context());
  44. one_context->set_time(Time{1});
  45. auto linear = make_node_with_name_as<BaseValue<double>>("Linear");
  46. CHECK(linear->value(zero_context()) == 0);
  47. CHECK(linear->value(one_context) == 1);
  48. linear->set_any_at(5.0, zero_context());
  49. CHECK(linear->value(zero_context()) == 5);
  50. CHECK(linear->value(one_context) == 6);
  51. linear->set_any_at(5.0, one_context);
  52. CHECK(linear->value(zero_context()) == 4);
  53. CHECK(linear->value(one_context) == 5);
  54. }