using System; using Unity.Mathematics; using GamecraftModdingAPI; using GamecraftModdingAPI.Tests; namespace GamecraftModdingAPI.Players { #if TEST /// /// Player test cases. Not accessible in release versions. /// [APITestClass] public static class PlayerTests { [APITestCase(TestType.EditMode)] public static void ExistsTest() { if (!Assert.Equal(Player.Exists(PlayerType.Local), true, "Local player does not exist.", "Local player detected.")) return; Assert.Equal(Player.Count(), 1u, "Player.Count() is not one, possibly because it failed silently.", "Player count is one for single player game."); } [APITestCase(TestType.EditMode)] public static void PositionTest() { Player p = new Player(PlayerType.Local); if (!Assert.Errorless(() => { p.Teleport(0, 0, 0, relative: false); }, "Player.Teleport(origin) errored: ", "Player teleported to origin successfully.")) return; if (!Assert.CloseTo(p.Position, float3.zero, "Player is not close to origin despite being teleported there.", "Player.Position is at origin.")) return; if (!Assert.Errorless(() => { p.Position = float3.zero + 1; }, "Player.Position = origin+1 errored: ", "Player moved to origin+1.")) return; Assert.CloseTo(p.Position, float3.zero + 1, "Player is not close to origin+1 despite being teleported there.", "Player.Position is at origin+1."); } [APITestCase(TestType.Menu)] public static void InvalidStateTest() { if (!Assert.Errorless(() => { Player.Count(); }, "Player.Count() errored in menu.", "Player.Count() succeeded in menu.")) return; Assert.Equal(Player.Count(), 0u, "Player.Count() is not zero in menu.", "Player count is zero in menu as expected."); } } #endif }