-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathDz2Test.cs
More file actions
41 lines (34 loc) · 1.42 KB
/
Dz2Test.cs
File metadata and controls
41 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Model.Runtime.Projectiles;
using NUnit.Framework;
using UnityEngine;
public class Dz2Test : MonoBehaviour
{
private const int SamplesOverTrajectory = 100;
private const float ProjectileSpeed = 7f;
[Test]
public void TestProjectileTrajectory()
{
TestProjectileTrajectory(Vector2Int.zero, new Vector2Int(100, 0));
TestProjectileTrajectory(Vector2Int.zero, new Vector2Int(0, 100));
TestProjectileTrajectory(Vector2Int.zero, new Vector2Int(100, 100));
TestProjectileTrajectory(new Vector2Int(50, 50), new Vector2Int(100, 100));
}
public void TestProjectileTrajectory(Vector2Int start, Vector2Int target)
{
var proj = new ArchToTileProjectile(null, target, 0, start);
var totalDistance = Vector2.Distance(start, target);
var timeToTarget = totalDistance / ProjectileSpeed;
var maxHeight = 0.6f * totalDistance;
var step = 1f / SamplesOverTrajectory;
var timeStep = timeToTarget / SamplesOverTrajectory;
var totalPassedTime = 0f;
for (float t = 0; t <= 1; t += step)
{
totalPassedTime += timeStep;
proj.Update(timeStep, totalPassedTime);
var height = proj.Height;
var refHeight = maxHeight * (-(t * 2 - 1) * (t * 2 - 1) + 1);
Assert.AreEqual(refHeight, height, 0.1f, "Height is not as expected at t=" + t);
}
}
}