283 lines
13 KiB
C#
283 lines
13 KiB
C#
|
|
using NUnit.Framework;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.TestTools;
|
||
|
|
using UnityEngine.Tilemaps;
|
||
|
|
using EerieVillage.Map.Data;
|
||
|
|
using EerieVillage.Map.Generation;
|
||
|
|
|
||
|
|
namespace EerieVillage.Map.Tests.Editor
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// BT13-Dev-Map Phase 2-B — EditMode 테스트.
|
||
|
|
/// PD 결정 (a) 단일 채택 2026-05-18 영역 spec §13-2 정합.
|
||
|
|
/// 10건 권고 → 본 영역 12건 (검증 강화).
|
||
|
|
/// </summary>
|
||
|
|
public class MapGeneratorTests
|
||
|
|
{
|
||
|
|
// ───── 헬퍼 ─────
|
||
|
|
static Tile MakeTile()
|
||
|
|
{
|
||
|
|
var t = ScriptableObject.CreateInstance<Tile>();
|
||
|
|
t.colliderType = Tile.ColliderType.Sprite;
|
||
|
|
return t;
|
||
|
|
}
|
||
|
|
|
||
|
|
static MapResourceCatalog MakeCatalog()
|
||
|
|
{
|
||
|
|
// PD 2026-05-19 단순화 — TileEntry·PrefabEntry 폐기, 9 ground slot + platformShort/Long + monsters List 정합
|
||
|
|
var c = ScriptableObject.CreateInstance<MapResourceCatalog>();
|
||
|
|
|
||
|
|
// 지면 — groundCenter 1종 (PD 임시 작업)
|
||
|
|
var center = MakeTile(); center.name = "Ground_Center";
|
||
|
|
c.groundCenter = center;
|
||
|
|
|
||
|
|
// 공중 발판 2종
|
||
|
|
var pShort = MakeTile(); pShort.name = "Platform_Short";
|
||
|
|
var pLong = MakeTile(); pLong.name = "Platform_Long";
|
||
|
|
c.platformShort = pShort;
|
||
|
|
c.platformLong = pLong;
|
||
|
|
|
||
|
|
// monsters 리스트 — 1종 (random pick fallback 검증)
|
||
|
|
c.monsters = new System.Collections.Generic.List<GameObject> { new GameObject("Monster_Test") };
|
||
|
|
|
||
|
|
// §15-9 — bossPrefab (BossRoom spawn 검증 정합)
|
||
|
|
c.bossPrefab = new GameObject("Boss_Test");
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
|
||
|
|
static MapGenerationConfig MakeConfig(int length = 80)
|
||
|
|
{
|
||
|
|
var cfg = ScriptableObject.CreateInstance<MapGenerationConfig>();
|
||
|
|
cfg.lengthTiles = length;
|
||
|
|
cfg.spawnDensity = 0.4f;
|
||
|
|
cfg.minSpawnSpacingTiles = 12;
|
||
|
|
cfg.maxSpawnPerMap = 16;
|
||
|
|
cfg.platformDensity = 0.5f;
|
||
|
|
cfg.minPlatformGapTiles = 3;
|
||
|
|
cfg.maxPlatformGapTiles = 10; // §15-2 OVERRIDE 이중 점프
|
||
|
|
cfg.minPlatformWidthTiles = 2;
|
||
|
|
cfg.maxPlatformWidthTiles = 6;
|
||
|
|
cfg.minPlatformHeight = 2;
|
||
|
|
cfg.maxPlatformHeight = 10; // §15-2 OVERRIDE 이중 점프 SAFE 10.11m
|
||
|
|
cfg.startMarginTiles = 4;
|
||
|
|
cfg.goalMarginTiles = 4;
|
||
|
|
cfg.catalog = MakeCatalog();
|
||
|
|
cfg.chunkSizeTiles = 20;
|
||
|
|
cfg.introPlatformDensityMultiplier = 0.6f;
|
||
|
|
cfg.midPlatformDensityMultiplier = 1.2f;
|
||
|
|
cfg.bossPrePlatformDensityMultiplier = 0.8f;
|
||
|
|
cfg.groundBaseY = 0;
|
||
|
|
cfg.groundPerlinAmplitude = 2;
|
||
|
|
cfg.groundPerlinScale = 0.1f;
|
||
|
|
cfg.flyingEnemyRatio = 0.15f;
|
||
|
|
// PD §15 OVERRIDE 신규 (2026-05-18)
|
||
|
|
cfg.allowFloatingSpawnPoints = true; // §15-5
|
||
|
|
cfg.respawnTimer = 5f; // §15-7
|
||
|
|
cfg.respawnMaxCount = -1; // §15-7
|
||
|
|
cfg.bossRoomEnabled = false; // §15-9 — 영역 영역 영역 영역 영역 false (T13~T15 영역 별도 영역 true)
|
||
|
|
cfg.bossRoomLengthTiles = 20;
|
||
|
|
return cfg;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 1. 기본 Generate 검증
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
[Test]
|
||
|
|
public void T01_Generate_Returns_NonNull_Blueprint()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig();
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
Assert.IsNotNull(bp, "Generate 영역 blueprint 반환 의무");
|
||
|
|
Assert.AreEqual(cfg.lengthTiles, bp.lengthTiles, "blueprint.lengthTiles = config.lengthTiles");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T02_Generate_Null_Config_Returns_Null()
|
||
|
|
{
|
||
|
|
LogAssert.Expect(LogType.Error, "[MapGenerator] config is null");
|
||
|
|
var bp = MapGenerator.Generate(null);
|
||
|
|
Assert.IsNull(bp, "config null 영역 null 반환");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 2. 지면 영역 검증
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
[Test]
|
||
|
|
public void T03_Ground_Tiles_Span_Full_Length()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(100);
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
Assert.IsNotNull(bp.groundSurfaceY, "groundSurfaceY 영역 생성 의무");
|
||
|
|
Assert.AreEqual(cfg.lengthTiles, bp.groundSurfaceY.Length, "groundSurfaceY 영역 길이 = lengthTiles");
|
||
|
|
Assert.Greater(bp.terrain.Count, 0, "terrain Tile 영역 존재 의무");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T04_Ground_Perlin_Variation_Within_Amplitude()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig();
|
||
|
|
cfg.groundPerlinAmplitude = 2;
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
int min = int.MaxValue, max = int.MinValue;
|
||
|
|
foreach (int y in bp.groundSurfaceY)
|
||
|
|
{
|
||
|
|
if (y < min) min = y;
|
||
|
|
if (y > max) max = y;
|
||
|
|
}
|
||
|
|
int range = max - min;
|
||
|
|
Assert.LessOrEqual(range, cfg.groundPerlinAmplitude * 2 + 1,
|
||
|
|
$"지면 영역 변동 폭 ≤ amplitude*2 (실제={range})");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 3. 발판 영역 검증 (§6 룰)
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
[Test]
|
||
|
|
public void T05_Platforms_Within_Map_Bounds()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(120);
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
foreach (var p in bp.platforms)
|
||
|
|
{
|
||
|
|
Assert.GreaterOrEqual(p.x, 0, "발판 x ≥ 0");
|
||
|
|
Assert.Less(p.x, cfg.lengthTiles, "발판 x < lengthTiles");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T06_Platforms_Height_Within_SafeVerticalHeight()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig();
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
// 모든 발판 영역 지면 위 ≤ safeVerticalHeight 5.06m 영역 (5 Tile cap)
|
||
|
|
foreach (var p in bp.platforms)
|
||
|
|
{
|
||
|
|
int groundY = bp.groundSurfaceY[Mathf.Clamp(p.x, 0, bp.groundSurfaceY.Length - 1)];
|
||
|
|
int heightOffset = p.y - groundY;
|
||
|
|
Assert.LessOrEqual(heightOffset, cfg.maxPlatformHeight + 1,
|
||
|
|
$"발판 영역 높이 {heightOffset} ≤ maxPlatformHeight {cfg.maxPlatformHeight}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 4. ValidateJumpReach 영역 검증 (§4-5)
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
[Test]
|
||
|
|
public void T07_ValidateJumpReach_Within_Safe_Distance()
|
||
|
|
{
|
||
|
|
// §15-2 OVERRIDE 이중 점프 SAFE_HORIZONTAL_DISTANCE = 11.56m
|
||
|
|
// 11m 안 = OK
|
||
|
|
Assert.IsTrue(PlatformPlanner.ValidateJumpReach(0f, 0f, 11f, 0f));
|
||
|
|
// 12m 초과 = X
|
||
|
|
Assert.IsFalse(PlatformPlanner.ValidateJumpReach(0f, 0f, 12f, 0f));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T08_ValidateJumpReach_Within_Safe_Height()
|
||
|
|
{
|
||
|
|
// §15-2 OVERRIDE 이중 점프 SAFE_VERTICAL_HEIGHT = 10.11m
|
||
|
|
// 10m 안 = OK
|
||
|
|
Assert.IsTrue(PlatformPlanner.ValidateJumpReach(0f, 0f, 0f, 10f));
|
||
|
|
// 11m 초과 = X
|
||
|
|
Assert.IsFalse(PlatformPlanner.ValidateJumpReach(0f, 0f, 0f, 11f));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T09_ValidateJumpReach_Negative_DY_Always_Reachable()
|
||
|
|
{
|
||
|
|
// dy 음수(아래) = 항상 도달 (이중 점프 영역 동일 정합)
|
||
|
|
Assert.IsTrue(PlatformPlanner.ValidateJumpReach(0f, 10f, 11f, 0f));
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 5. SpawnPoint·Start·Goal 영역 검증 (§8)
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
[Test]
|
||
|
|
public void T10_StartPoint_LeftSide_GoalPoint_RightSide()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(100);
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
Assert.Less(bp.startPoint.x, 20, "Start 영역 좌측 (§15-6 좌측 고정)");
|
||
|
|
Assert.Greater(bp.goalPoint.x, cfg.lengthTiles - 20, "Goal 영역 우측");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T11_SpawnPoints_Within_MaxConcurrent()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(120);
|
||
|
|
cfg.maxSpawnPerMap = 8;
|
||
|
|
cfg.spawnDensity = 1f; // 최대 영역
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
Assert.LessOrEqual(bp.spawnPoints.Count, cfg.maxSpawnPerMap,
|
||
|
|
$"spawnPoints 영역 maxSpawnPerMap {cfg.maxSpawnPerMap} cap");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Test]
|
||
|
|
public void T12_SpawnPoints_MinSpacing_Respected()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(120);
|
||
|
|
cfg.minSpawnSpacingTiles = 12;
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
// 인접 거점 영역 spacing 검증
|
||
|
|
for (int i = 0; i < bp.spawnPoints.Count - 1; i++)
|
||
|
|
{
|
||
|
|
for (int j = i + 1; j < bp.spawnPoints.Count; j++)
|
||
|
|
{
|
||
|
|
float dx = Mathf.Abs(bp.spawnPoints[i].position.x - bp.spawnPoints[j].position.x);
|
||
|
|
Assert.GreaterOrEqual(dx, cfg.minSpawnSpacingTiles - 1,
|
||
|
|
$"spawnPoint 간 거리 {dx} ≥ minSpacing {cfg.minSpawnSpacingTiles}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
// 6. PD §15 OVERRIDE 신규 테스트 — 2026-05-18
|
||
|
|
// ─────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
// §15-9 OVERRIDE — BossRoom 영역 ChunkPlanner 영역 isBossRoom=true 청크 영역
|
||
|
|
[Test]
|
||
|
|
public void T13_BossRoom_ChunkPlanner_Generates_BossRoomChunk()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(120);
|
||
|
|
cfg.bossRoomEnabled = true;
|
||
|
|
cfg.bossRoomLengthTiles = 20;
|
||
|
|
var chunks = ChunkPlanner.Plan(cfg);
|
||
|
|
|
||
|
|
// 마지막 청크 영역 isBossRoom=true 의무
|
||
|
|
Assert.Greater(chunks.Count, 0, "청크 영역 생성 의무");
|
||
|
|
var lastChunk = chunks[chunks.Count - 1];
|
||
|
|
Assert.IsTrue(lastChunk.isBossRoom, "마지막 청크 영역 BossRoom (§15-9 OVERRIDE)");
|
||
|
|
Assert.AreEqual(cfg.lengthTiles, lastChunk.endX, "BossRoom 영역 영역 영역 영역 endX = lengthTiles");
|
||
|
|
}
|
||
|
|
|
||
|
|
// §15-9 OVERRIDE — BossRoom 영역 평탄 영역 (PlatformPlanner 영역 발판 배치 skip)
|
||
|
|
[Test]
|
||
|
|
public void T14_BossRoom_Platforms_Skip_Within_BossRoom()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig(120);
|
||
|
|
cfg.bossRoomEnabled = true;
|
||
|
|
cfg.bossRoomLengthTiles = 20;
|
||
|
|
cfg.platformDensity = 1f; // 최대 영역
|
||
|
|
var bp = MapGenerator.Generate(cfg);
|
||
|
|
|
||
|
|
int bossRoomStart = cfg.lengthTiles - cfg.bossRoomLengthTiles;
|
||
|
|
// BossRoom 영역 영역 발판 없어야 함
|
||
|
|
foreach (var p in bp.platforms)
|
||
|
|
{
|
||
|
|
Assert.Less(p.x, bossRoomStart,
|
||
|
|
$"BossRoom 영역 (x≥{bossRoomStart}) 영역 발판 배치 X (§15-9 OVERRIDE) — 실제 {p.x}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// §15-7 OVERRIDE — config 영역 respawnTimer·respawnMaxCount 영역 전달 정합
|
||
|
|
[Test]
|
||
|
|
public void T15_Respawn_Config_Defaults_Are_Set()
|
||
|
|
{
|
||
|
|
var cfg = MakeConfig();
|
||
|
|
// PD §15-7 OVERRIDE — 기본 timer=5s·maxCount=-1 무제한
|
||
|
|
Assert.AreEqual(5f, cfg.respawnTimer, 0.001f, "§15-7 OVERRIDE respawnTimer 기본 5초");
|
||
|
|
Assert.AreEqual(-1, cfg.respawnMaxCount, "§15-7 OVERRIDE respawnMaxCount 기본 -1 무제한");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|