Files
MagnetismHeroes/Assets/MagnetismHeroes/Tests/EditMode/CompositionAssetTests.cs
T

53 lines
3.3 KiB
C#

using System.Linq;
using MagnetismHeroes.Core;
using MagnetismHeroes.UnityRuntime.Bootstrap;
using MagnetismHeroes.UnityRuntime.StageAssets;
using MagnetismHeroes.UnityRuntime.Presentation;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace MagnetismHeroes.Tests
{
public sealed class CompositionAssetTests
{
[TestCase(6, new[] { 1, 1 }, new[] { 2 })]
[TestCase(10, new[] { 2 }, new[] { 1, 1 })]
[TestCase(14, new[] { 3, 1 }, new[] { 2, 2 })]
public void InspectorStageMatchesRepresentativeRule(int id, int[] initial, int[] target)
{
var asset = AssetDatabase.LoadAssetAtPath<StageAsset>($"Assets/MagnetismHeroes/UnityRuntime/StageAssets/Stage{id:D2}.asset");
Assert.That(asset, Is.Not.Null); var definition = asset.ToDefinition();
Assert.That(definition.Id, Is.EqualTo(id)); Assert.That(definition.Kind, Is.EqualTo(StageKind.Composition));
Assert.That(definition.InitialGroups, Is.EqualTo(initial)); Assert.That(definition.TargetGroups, Is.EqualTo(target));
Assert.That(definition.BallPositions.Count, Is.EqualTo(initial.Sum()));
}
[Test] public void AppCatalogControlsAndDraftGuidesAreConnectedWithoutUnlockBypass()
{
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/MagnetismHeroes/UnityRuntime/Presentation/Prefabs/GameApp.prefab");
var serialized = new SerializedObject(prefab.GetComponent<GameApp>()); var stages = serialized.FindProperty("_stages");
Assert.That(stages.arraySize, Is.EqualTo(5)); var definitions = Enumerable.Range(0, stages.arraySize)
.Select(index => ((StageAsset)stages.GetArrayElementAtIndex(index).objectReferenceValue).ToDefinition()).ToArray();
Assert.That(definitions.Select(stage => stage.Id), Is.EqualTo(new[] { 1, 2, 6, 10, 14 }));
var session = new GameSession(definitions, new EmptyStore()); Assert.That(session.IsUnlocked(6), Is.False);
Assert.That(session.StartStage(6), Is.False); Assert.That(session.IsUnlocked(10), Is.False); Assert.That(session.IsUnlocked(14), Is.False);
Assert.That(serialized.FindProperty("_compositionButtons").arraySize, Is.EqualTo(3));
foreach (string field in new[] { "_splitButton", "_cancelSplitButton" }) Assert.That(serialized.FindProperty(field).objectReferenceValue, Is.Not.Null);
}
private sealed class EmptyStore : IProgressStore
{
public bool TryLoad(out ProgressSave save, out string error) { save = new ProgressSave(); error = null; return true; }
public bool TrySave(ProgressSave save, out string error) { error = null; return true; }
}
[Test] public void IdenticalRowsCannotHideEachOthersUnitSpheresAfterContactPlacement()
{
var row = new[] { new Vector3(-.5f, 0, 0), new Vector3(.5f, 0, 0) };
var shifted = new[] { row[0] - Vector3.right, row[1] - Vector3.right };
float correction = ContactPlacement.Clearance(shifted, row, Vector3.left);
Assert.That(correction, Is.EqualTo(1).Within(.0001f));
foreach (var moving in shifted) foreach (var target in row)
Assert.That(Vector3.Distance(moving + Vector3.left * correction, target), Is.GreaterThanOrEqualTo(.9999f));
}
}
}