This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UTY-2661: Improve snapshot api (#1479)
Improve `Snapshot` API: - Added method to check if `EntityId` is valid - Improve search for next available `EntityId` - Throws exception when adding duplicate `EntityId` - Implement `IDisposable` to free native memory Co-authored-by: Jamie Brynes <[email protected]>
- Loading branch information
1 parent
a9e1e7d
commit 05ec260
Showing
5 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
workers/unity/Assets/Tests/EditmodeTests/Correctness/Utility/SnapshotTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Linq; | ||
using Improbable.Gdk.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Improbable.Gdk.EditmodeTests.Utility | ||
{ | ||
[TestFixture] | ||
public class SnapshotTests | ||
{ | ||
private Snapshot snapshot; | ||
|
||
[SetUp] | ||
public void Initialize() | ||
{ | ||
snapshot = new Snapshot(); | ||
} | ||
|
||
[Test] | ||
public void Contains_returns_true_if_entityId_exists() | ||
{ | ||
var entityId = snapshot.GetNextEntityId(); | ||
var template = GetTemplate(); | ||
snapshot.AddEntity(entityId, template); | ||
Assert.IsTrue(snapshot.Contains(entityId)); | ||
} | ||
|
||
[Test] | ||
public void Contains_returns_false_if_entityId_does_not_exists() | ||
{ | ||
var entityId = snapshot.GetNextEntityId(); | ||
Assert.IsFalse(snapshot.Contains(entityId)); | ||
} | ||
|
||
[TestCase(10)] | ||
[TestCase(20)] | ||
[TestCase(40)] | ||
public void GetNextEntityId_will_return_valid_EntityIds(int size) | ||
{ | ||
var entities = Enumerable.Range(1, size).Select(i => new EntityId(i)); | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot()); | ||
foreach (var entity in entities) | ||
{ | ||
snapshot.AddEntity(entity, template); | ||
} | ||
|
||
Assert.IsFalse(snapshot.Contains(snapshot.GetNextEntityId())); | ||
} | ||
|
||
[TestCase(10)] | ||
[TestCase(20)] | ||
[TestCase(40)] | ||
public void Count_increases_on_adding_new_entity(int size) | ||
{ | ||
var entityIds = Enumerable.Range(1, size).Select(i => new EntityId(i)); | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot()); | ||
foreach (var entityId in entityIds) | ||
{ | ||
snapshot.AddEntity(entityId, template); | ||
} | ||
|
||
Assert.AreEqual(size, snapshot.Count); | ||
} | ||
|
||
[Test] | ||
public void AddEntity_throws_if_EntityId_exists() | ||
{ | ||
var entityId = new EntityId(1); | ||
var template = GetTemplate(); | ||
var template2 = GetTemplate(new Coordinates(1, 2, 3)); | ||
snapshot.AddEntity(entityId, template); | ||
Assert.Throws<ArgumentException>(() => snapshot.AddEntity(entityId, template2)); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
snapshot.Dispose(); | ||
} | ||
|
||
private static EntityTemplate GetTemplate(Coordinates pos = default) | ||
{ | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot(pos)); | ||
return template; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
workers/unity/Assets/Tests/EditmodeTests/Correctness/Utility/SnapshotTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters