|
| 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 | + |
| 31 | +#ifndef TEST_PHYSICS_MATERIAL_H |
| 32 | +#define TEST_PHYSICS_MATERIAL_H |
| 33 | + |
| 34 | +#include "scene/resources/physics_material.h" |
| 35 | +#include "tests/test_macros.h" |
| 36 | + |
| 37 | +namespace TestPhysics_material { |
| 38 | + |
| 39 | +TEST_CASE("[Physics_material] Defaults") { |
| 40 | + Ref<PhysicsMaterial> physics_material; |
| 41 | + physics_material.instantiate(); |
| 42 | + |
| 43 | + CHECK(physics_material->get_friction() == 1.); |
| 44 | + CHECK(physics_material->is_rough() == false); |
| 45 | + CHECK(physics_material->get_bounce() == 0.); |
| 46 | + CHECK(physics_material->is_absorbent() == false); |
| 47 | +} |
| 48 | + |
| 49 | +TEST_CASE("[Physics_material] Friction") { |
| 50 | + Ref<PhysicsMaterial> physics_material; |
| 51 | + physics_material.instantiate(); |
| 52 | + |
| 53 | + real_t friction = 0.314; |
| 54 | + physics_material->set_friction(friction); |
| 55 | + CHECK(physics_material->get_friction() == friction); |
| 56 | +} |
| 57 | + |
| 58 | +TEST_CASE("[Physics_material] Rough") { |
| 59 | + Ref<PhysicsMaterial> physics_material; |
| 60 | + physics_material.instantiate(); |
| 61 | + |
| 62 | + bool rough = true; |
| 63 | + physics_material->set_rough(rough); |
| 64 | + CHECK(physics_material->is_rough() == rough); |
| 65 | + |
| 66 | + real_t friction = 0.314; |
| 67 | + physics_material->set_friction(friction); |
| 68 | + CHECK(physics_material->computed_friction() == -friction); |
| 69 | + |
| 70 | + rough = false; |
| 71 | + physics_material->set_rough(rough); |
| 72 | + CHECK(physics_material->is_rough() == rough); |
| 73 | + |
| 74 | + CHECK(physics_material->computed_friction() == friction); |
| 75 | +} |
| 76 | + |
| 77 | +TEST_CASE("[Physics_material] Bounce") { |
| 78 | + Ref<PhysicsMaterial> physics_material; |
| 79 | + physics_material.instantiate(); |
| 80 | + |
| 81 | + real_t bounce = 0.271; |
| 82 | + physics_material->set_bounce(bounce); |
| 83 | + CHECK(physics_material->get_bounce() == bounce); |
| 84 | +} |
| 85 | + |
| 86 | +TEST_CASE("[Physics_material] Absorbent") { |
| 87 | + Ref<PhysicsMaterial> physics_material; |
| 88 | + physics_material.instantiate(); |
| 89 | + |
| 90 | + bool absorbent = true; |
| 91 | + physics_material->set_absorbent(absorbent); |
| 92 | + CHECK(physics_material->is_absorbent() == absorbent); |
| 93 | + |
| 94 | + real_t bounce = 0.271; |
| 95 | + physics_material->set_bounce(bounce); |
| 96 | + CHECK(physics_material->computed_bounce() == -bounce); |
| 97 | + |
| 98 | + absorbent = false; |
| 99 | + physics_material->set_absorbent(absorbent); |
| 100 | + CHECK(physics_material->is_absorbent() == absorbent); |
| 101 | + |
| 102 | + CHECK(physics_material->computed_bounce() == bounce); |
| 103 | +} |
| 104 | + |
| 105 | +} // namespace TestPhysics_material |
| 106 | + |
| 107 | +#endif // TEST_PHYSICS_MATERIAL_H |
0 commit comments