A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7KB

  1. using System;
  2. using Unity.Mathematics;
  3. using GamecraftModdingAPI;
  4. using GamecraftModdingAPI.Tests;
  5. namespace GamecraftModdingAPI.Players
  6. {
  7. #if TEST
  8. /// <summary>
  9. /// Player test cases. Not accessible in release versions.
  10. /// </summary>
  11. [APITestClass]
  12. public static class PlayerTests
  13. {
  14. [APITestCase(TestType.EditMode)]
  15. public static void ExistsTest()
  16. {
  17. if (!Assert.Equal(Player.Exists(PlayerType.Local), true, "Local player does not exist.", "Local player detected.")) return;
  18. Assert.Equal(Player.Count(), 1u, "Player.Count() is not one, possibly because it failed silently.", "Player count is one for single player game.");
  19. }
  20. [APITestCase(TestType.EditMode)]
  21. public static void PositionTest()
  22. {
  23. Player p = new Player(PlayerType.Local);
  24. if (!Assert.Errorless(() => { p.Teleport(0, 0, 0, relative: false); }, "Player.Teleport(origin) errored: ", "Player teleported to origin successfully.")) return;
  25. if (!Assert.CloseTo(p.Position, float3.zero, "Player is not close to origin despite being teleported there.", "Player.Position is at origin.")) return;
  26. if (!Assert.Errorless(() => { p.Position = float3.zero + 1; }, "Player.Position = origin+1 errored: ", "Player moved to origin+1.")) return;
  27. Assert.CloseTo(p.Position, float3.zero + 1, "Player is not close to origin+1 despite being teleported there.", "Player.Position is at origin+1.");
  28. }
  29. [APITestCase(TestType.Menu)]
  30. public static void InvalidStateTest()
  31. {
  32. if (!Assert.Errorless(() => { Player.Count(); }, "Player.Count() errored in menu.", "Player.Count() succeeded in menu.")) return;
  33. Assert.Equal(Player.Count(), 0u, "Player.Count() is not zero in menu.", "Player count is zero in menu as expected.");
  34. }
  35. }
  36. #endif
  37. }