test_physics_material.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**************************************************************************/
  2. /* test_physics_material.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/resources/physics_material.h"
  32. #include "tests/test_macros.h"
  33. namespace TestPhysics_material {
  34. TEST_CASE("[Physics_material] Defaults") {
  35. Ref<PhysicsMaterial> physics_material;
  36. physics_material.instantiate();
  37. CHECK(physics_material->get_friction() == 1.);
  38. CHECK(physics_material->is_rough() == false);
  39. CHECK(physics_material->get_bounce() == 0.);
  40. CHECK(physics_material->is_absorbent() == false);
  41. }
  42. TEST_CASE("[Physics_material] Friction") {
  43. Ref<PhysicsMaterial> physics_material;
  44. physics_material.instantiate();
  45. real_t friction = 0.314;
  46. physics_material->set_friction(friction);
  47. CHECK(physics_material->get_friction() == friction);
  48. }
  49. TEST_CASE("[Physics_material] Rough") {
  50. Ref<PhysicsMaterial> physics_material;
  51. physics_material.instantiate();
  52. bool rough = true;
  53. physics_material->set_rough(rough);
  54. CHECK(physics_material->is_rough() == rough);
  55. real_t friction = 0.314;
  56. physics_material->set_friction(friction);
  57. CHECK(physics_material->computed_friction() == -friction);
  58. rough = false;
  59. physics_material->set_rough(rough);
  60. CHECK(physics_material->is_rough() == rough);
  61. CHECK(physics_material->computed_friction() == friction);
  62. }
  63. TEST_CASE("[Physics_material] Bounce") {
  64. Ref<PhysicsMaterial> physics_material;
  65. physics_material.instantiate();
  66. real_t bounce = 0.271;
  67. physics_material->set_bounce(bounce);
  68. CHECK(physics_material->get_bounce() == bounce);
  69. }
  70. TEST_CASE("[Physics_material] Absorbent") {
  71. Ref<PhysicsMaterial> physics_material;
  72. physics_material.instantiate();
  73. bool absorbent = true;
  74. physics_material->set_absorbent(absorbent);
  75. CHECK(physics_material->is_absorbent() == absorbent);
  76. real_t bounce = 0.271;
  77. physics_material->set_bounce(bounce);
  78. CHECK(physics_material->computed_bounce() == -bounce);
  79. absorbent = false;
  80. physics_material->set_absorbent(absorbent);
  81. CHECK(physics_material->is_absorbent() == absorbent);
  82. CHECK(physics_material->computed_bounce() == bounce);
  83. }
  84. } // namespace TestPhysics_material