Skip to content

Commit

Permalink
Test coverage: add Test_Relations_generic_relation()
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Dec 2, 2024
1 parent b947b1b commit 1c4ed05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Tests/ECS/Base/Test_ComponentSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public static void Test_ComponentTypes()
var components = schema.Components;
var scripts = schema.Scripts;

AreEqual("components: 68 scripts: 10 entity tags: 16", schema.ToString());
AreEqual(69, components.Length);
AreEqual("components: 69 scripts: 10 entity tags: 16", schema.ToString());
AreEqual(70, components.Length);
AreEqual(11, scripts.Length);

AreEqual(74, schema.SchemaTypeByKey.Count);
AreEqual(68, schema.ComponentTypeByType.Count);
AreEqual(75, schema.SchemaTypeByKey.Count);
AreEqual(69, schema.ComponentTypeByType.Count);
AreEqual(10, schema.ScriptTypeByType.Count);

IsNull(components[0]);
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/ECS/Relations/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ internal struct InventoryItem : IRelation<InventoryItemType>
public override string ToString() => type.ToString();
}

/// Check generic relation
[GenericInstanceType("relation-string", typeof(string))]
internal struct GenericRelation<T> : IRelation<int>
{
public int key;
public T value;
public int GetRelationKey() => key;

public override string ToString() => key.ToString();
}

}
11 changes: 11 additions & 0 deletions src/Tests/ECS/Relations/Test_Relations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ public static void Test_Relations_null_relation_key()
IsNull (entity.GetRelation<StringRelation, string>(null).value);
}

/// Cover generic case at <see cref="Friflo.Engine.ECS.SchemaUtils.CreateRelationType{T}"/>
[Test]
public static void Test_Relations_generic_relation()
{
var store = new EntityStore();
var entity = store.CreateEntity();
entity.AddRelation(new GenericRelation<string> { key = 42, value = "test" });
AreEqual("{ 42 }", entity.GetRelations<GenericRelation<string>>().Debug());
AreEqual("test", entity.GetRelation<GenericRelation<string>, int>(42).value);
}


/* COMP_TAG obsolete:
Relations do not implement IComponent anymore. So HasComponent(), GetComponent() and AddComponent() will result in a compiler error
Expand Down

0 comments on commit 1c4ed05

Please sign in to comment.