66 lines
3.0 KiB
GDScript
66 lines
3.0 KiB
GDScript
# Idle-support stability tests for res://scripts/player.gd (static helpers).
|
|
extends GdUnitTestSuite
|
|
|
|
const PLAYER_SCRIPT: Script = preload("res://scripts/player.gd")
|
|
|
|
|
|
func test_idle_support_is_stable_on_flat_floor_without_wall_contacts() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, Vector3.UP, slide_normals, 0)
|
|
assert_that(stable).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_false_when_floor_is_not_flat_enough() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP]
|
|
var tilted_floor: Vector3 = Vector3(0.07, 0.9975, 0.0).normalized()
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, tilted_floor, slide_normals, 0)
|
|
assert_that(stable).is_false()
|
|
|
|
|
|
func test_idle_support_is_stable_min_flat_up_dot_parameter() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP]
|
|
var floor_n: Vector3 = Vector3(0.05, 0.99875, 0.0).normalized()
|
|
var strict: bool = PLAYER_SCRIPT.idle_support_is_stable(true, floor_n, slide_normals, 0, 0.999)
|
|
var holdish: bool = PLAYER_SCRIPT.idle_support_is_stable(true, floor_n, slide_normals, 0, 0.992)
|
|
assert_that(strict).is_false()
|
|
assert_that(holdish).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_true_when_flat_floor_has_extra_contacts() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP, Vector3(0.0, 0.6, 0.8).normalized()]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, Vector3.UP, slide_normals, 0)
|
|
assert_that(stable).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_true_when_loose_ticks_and_ridged_but_floor_still_level() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP, Vector3(1.0, 0.0, 0.0)]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, Vector3.UP, slide_normals, 12)
|
|
assert_that(stable).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_false_when_loose_ticks_and_ridged_and_shallow_floor() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP, Vector3(1.0, 0.0, 0.0)]
|
|
var floor_n: Vector3 = Vector3(0.35, 0.88, 0.0).normalized()
|
|
assert_that(floor_n.dot(Vector3.UP) < 0.968).is_true()
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, floor_n, slide_normals, 12)
|
|
assert_that(stable).is_false()
|
|
|
|
|
|
func test_idle_support_is_stable_true_when_loose_ticks_but_flat_open_support() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, Vector3.UP, slide_normals, 12)
|
|
assert_that(stable).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_true_when_loose_ticks_and_shallow_seam_not_ridged() -> void:
|
|
var n2: Vector3 = Vector3(0.0, 0.42, sqrt(1.0 - 0.42 * 0.42)).normalized()
|
|
var slide_normals: Array[Vector3] = [Vector3.UP, n2]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(true, Vector3.UP, slide_normals, 12)
|
|
assert_that(stable).is_true()
|
|
|
|
|
|
func test_idle_support_is_stable_false_when_not_on_floor() -> void:
|
|
var slide_normals: Array[Vector3] = [Vector3.UP]
|
|
var stable: bool = PLAYER_SCRIPT.idle_support_is_stable(false, Vector3.UP, slide_normals, 0)
|
|
assert_that(stable).is_false()
|