|
|
@@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
|
|
|
|
using Gamecraft.Wires; |
|
|
|
using Unity.Mathematics; |
|
|
|
|
|
|
|
using GamecraftModdingAPI; |
|
|
|
using GamecraftModdingAPI.Tests; |
|
|
@@ -60,19 +61,31 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
Assert.Errorless(() => { b = newBlock.Specialise<Piston>(); }, "Block.Specialize<Piston>() raised an exception: ", "Block.Specialize<Piston>() completed without issue."); |
|
|
|
if (!Assert.NotNull(b, "Block.Specialize<Piston>() returned null, possibly because it failed silently.", "Specialized Piston is not null.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumExtension, 1.01f, $"Piston.MaximumExtension {b.MaximumExtension} does not equal default value, possibly because it failed silently.", "Piston.MaximumExtension is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumForce, 750f, $"Piston.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Piston.MaximumForce is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumForce, 1.0f, $"Piston.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Piston.MaximumForce is close enough to default.")) return; |
|
|
|
} |
|
|
|
|
|
|
|
[APITestCase(TestType.EditMode)] |
|
|
|
[APITestCase(TestType.EditMode)] |
|
|
|
public static void TestServo() |
|
|
|
{ |
|
|
|
Block newBlock = Block.PlaceNew(BlockIDs.ServoAxle, Unity.Mathematics.float3.zero + 1); |
|
|
|
Servo b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler |
|
|
|
Assert.Errorless(() => { b = newBlock.Specialise<Servo>(); }, "Block.Specialize<Servo>() raised an exception: ", "Block.Specialize<Servo>() completed without issue."); |
|
|
|
if (!Assert.NotNull(b, "Block.Specialize<Servo>() returned null, possibly because it failed silently.", "Specialized Servo is not null.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumAngle, 180f, $"Servo.MaximumAngle {b.MaximumAngle} does not equal default value, possibly because it failed silently.", "Servo.MaximumAngle is close enough to default.")) return; |
|
|
|
Block newBlock = Block.PlaceNew(BlockIDs.ServoAxle, Unity.Mathematics.float3.zero + 1); |
|
|
|
Servo b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler |
|
|
|
Assert.Errorless(() => { b = newBlock.Specialise<Servo>(); }, "Block.Specialize<Servo>() raised an exception: ", "Block.Specialize<Servo>() completed without issue."); |
|
|
|
if (!Assert.NotNull(b, "Block.Specialize<Servo>() returned null, possibly because it failed silently.", "Specialized Servo is not null.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumAngle, 180f, $"Servo.MaximumAngle {b.MaximumAngle} does not equal default value, possibly because it failed silently.", "Servo.MaximumAngle is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MinimumAngle, -180f, $"Servo.MinimumAngle {b.MinimumAngle} does not equal default value, possibly because it failed silently.", "Servo.MinimumAngle is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumForce, 750f, $"Servo.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Servo.MaximumForce is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaximumForce, 60f, $"Servo.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Servo.MaximumForce is close enough to default.")) return; |
|
|
|
} |
|
|
|
|
|
|
|
[APITestCase(TestType.EditMode)] |
|
|
|
public static void TestDampedSpring() |
|
|
|
{ |
|
|
|
Block newBlock = Block.PlaceNew(BlockIDs.DampedSpring, Unity.Mathematics.float3.zero + 1); |
|
|
|
DampedSpring b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler |
|
|
|
Assert.Errorless(() => { b = newBlock.Specialise<DampedSpring>(); }, "Block.Specialize<Servo>() raised an exception: ", "Block.Specialize<DampedSpring>() completed without issue."); |
|
|
|
if (!Assert.NotNull(b, "Block.Specialize<DampedSpring>() returned null, possibly because it failed silently.", "Specialized DampedSpring is not null.")) return; |
|
|
|
if (!Assert.CloseTo(b.Stiffness, 1.0f, $"DampedSpring.Stiffness {b.Stiffness} does not equal default value, possibly because it failed silently.", "DampedSpring.Stiffness is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.Damping, 0.1f, $"DampedSpring.Damping {b.Damping} does not equal default value, possibly because it failed silently.", "DampedSpring.Damping is close enough to default.")) return; |
|
|
|
if (!Assert.CloseTo(b.MaxExtension, 0.3f, $"DampedSpring.MaxExtension {b.MaxExtension} does not equal default value, possibly because it failed silently.", "DampedSpring.MaxExtension is close enough to default.")) return; |
|
|
|
} |
|
|
|
|
|
|
|
[APITestCase(TestType.Game)] |
|
|
@@ -119,6 +132,13 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
if (!Assert.Errorless(() => { newWire = b.Connect(0, target, 0);})) return; |
|
|
|
if (!Assert.NotNull(newWire, "SignalingBlock.Connect(...) returned null, possible because it failed silently.", "SignalingBlock.Connect(...) returned a non-null value.")) return; |
|
|
|
} |
|
|
|
|
|
|
|
[APITestCase(TestType.EditMode)] |
|
|
|
public static void TestSpecialiseError() |
|
|
|
{ |
|
|
|
Block newBlock = Block.PlaceNew(BlockIDs.Bench, new float3(1, 1, 1)); |
|
|
|
if (Assert.Errorful<BlockTypeException>(() => newBlock.Specialise<MusicBlock>(), "Block.Specialise<MusicBlock>() was expected to error on a bench block.", "Block.Specialise<MusicBlock>() errored as expected for a bench block.")) return; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |