# Tests res://scripts/zoom_band_config.gd (NEO-16 discrete bands).
extends GdUnitTestSuite

const ZoomBandConfigScript := preload("res://scripts/zoom_band_config.gd")


func test_empty_bands_band_count_zero() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array()
	# Act
	var n: int = c.band_count()
	# Assert
	assert_that(n).is_equal(0)


func test_empty_bands_clamp_index_zero() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array()
	# Act
	var a: int = c.clamp_index(0)
	var b: int = c.clamp_index(99)
	# Assert
	assert_that(a).is_equal(0)
	assert_that(b).is_equal(0)


func test_empty_bands_distance_at_zero() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array()
	# Act
	var d: float = c.distance_at(0)
	# Assert
	assert_that(d).is_equal(0.0)


func test_single_band_clamp_always_zero() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array([42.0])
	# Act
	var a: int = c.clamp_index(-1)
	var b: int = c.clamp_index(0)
	var cc: int = c.clamp_index(9)
	# Assert
	assert_that(a).is_equal(0)
	assert_that(b).is_equal(0)
	assert_that(cc).is_equal(0)


func test_multi_band_clamp_and_distance_at() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array([10.0, 20.0, 30.0])
	# Act
	var i0: int = c.clamp_index(-5)
	var i1: int = c.clamp_index(1)
	var i2: int = c.clamp_index(99)
	var d1: float = c.distance_at(1)
	var d2: float = c.distance_at(100)
	# Assert
	assert_that(i0).is_equal(0)
	assert_that(i1).is_equal(1)
	assert_that(i2).is_equal(2)
	assert_that(d1).is_equal(20.0)
	assert_that(d2).is_equal(30.0)


func test_default_index_clamped_via_clamp_index() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array([1.0, 2.0, 3.0])
	c.default_band_index = 99
	# Act
	var idx: int = c.clamp_index(c.default_band_index)
	# Assert
	assert_that(idx).is_equal(2)


func test_all_band_distances_positive_vacuous_when_empty() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array()
	# Act
	var ok: bool = c.all_band_distances_positive()
	# Assert
	assert_that(ok).is_true()


func test_all_band_distances_positive_true_when_all_positive() -> void:
	# Arrange
	var c = ZoomBandConfigScript.new()
	c.band_distances = PackedFloat32Array([1.0, 2.5, 10.0])
	# Act
	var ok: bool = c.all_band_distances_positive()
	# Assert
	assert_that(ok).is_true()


func test_all_band_distances_positive_false_when_zero_or_negative() -> void:
	# Arrange
	var c0 = ZoomBandConfigScript.new()
	c0.band_distances = PackedFloat32Array([10.0, 0.0, 20.0])
	var cn = ZoomBandConfigScript.new()
	cn.band_distances = PackedFloat32Array([5.0, -1.0])
	# Act
	var ok0: bool = c0.all_band_distances_positive()
	var okn: bool = cn.all_band_distances_positive()
	# Assert
	assert_that(ok0).is_false()
	assert_that(okn).is_false()
