Skip to content

Commit

Permalink
100% coverage restored
Browse files Browse the repository at this point in the history
  • Loading branch information
thygrrr committed Oct 29, 2024
1 parent 469e935 commit 7b8a86c
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 11 deletions.
14 changes: 14 additions & 0 deletions fennecs.tests/ArchetypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,18 @@ public void IsComparable_Same_As_Signature()
Assert.True(table1.CompareTo(null) == table1.Signature.CompareTo(default));
}

[Fact]
public void Has_Signature_HashCode()
{
using var world = new World();
var entity1 = world.Spawn().Add("foo").Add(123).Add(17.0f).Id;
var entity2 = world.Spawn().Add(123).Add(17.0f).Id;

var table1 = world.GetEntityMeta(entity1).Archetype;
var table2 = world.GetEntityMeta(entity2).Archetype;

Assert.True(table1.GetHashCode() == table1.Signature.GetHashCode());
Assert.True(table2.GetHashCode() == table2.Signature.GetHashCode());
Assert.NotEqual(table1.GetHashCode(), table2.GetHashCode());
}
}
16 changes: 16 additions & 0 deletions fennecs.tests/Entity/EntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,21 @@ public void Can_Get_Link_Objects_via_Get()
Assert.Contains(helloWorld2, strings);
Assert.Equal(2, strings.Length);
}


[Fact]
public void Truthy()
{
using var world = new World();

var entity = world.Spawn();
Assert.True(entity);

entity.Despawn();
Assert.False(entity);

entity = default;
Assert.False(entity);
}

}
19 changes: 19 additions & 0 deletions fennecs.tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,23 @@ public static void SIMDsizeIsAccurate()
var comp3 = Comp<string>.Plain;
Assert.Equal(0, comp3.SIMDsize);
}

[Fact]
public static void Comp_Virtual()
{
var comp = Comp.Virtual(typeof(int), Match.Any);
var test = Comp<int>.Matching(Match.Any);

Assert.Equal(comp, test);
Assert.Equal(test, comp);
}

[Fact]
public static void Relate_Entity_Operator()
{
using var world = new World();
var entity = world.Spawn();
var to = Relate.To(entity);
Assert.Equal(to, entity);
}
}
20 changes: 20 additions & 0 deletions fennecs.tests/Stream/Stream.1.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,24 @@ public void Streams_Can_Despawn()

Assert.Empty(world.Query<string>().Compile());
}

[Fact]
public void MatchAll_Overloads()
{
using var world = new World();
world.Spawn().Add("69").Add(420).Add(1.0f).Add(new object()).Add('a');

var query = world.All;
var stream1 = query.Stream<string>(Match.Any);
var stream2 = query.Stream<string, int>(Match.Any);
var stream3 = query.Stream<string, int, float>(Match.Any);
var stream4 = query.Stream<string, int, float, object>(Match.Any);
var stream5 = query.Stream<string, int, float, object, char>(Match.Any);

Assert.Single(stream1);
Assert.Single(stream2);
Assert.Single(stream3);
Assert.Single(stream4);
Assert.Single(stream5);
}
}
90 changes: 90 additions & 0 deletions fennecs.tests/Stream/World.Stream.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,94 @@ public void Stream_5()
Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}

[Fact]
public void Stream_1Match()
{
using var world = new World();
var stream = world.Stream<string>(Match.Any);

Assert.Empty(world);
Assert.Empty(stream);

Assert.Equal(0, stream.Count);

world.Spawn().Add("a");
Assert.Equal(1, stream.Count);

Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}

[Fact]
public void Stream_2Match()
{
using var world = new World();
var stream = world.Stream<string, int>(Match.Any);

Assert.Empty(world);
Assert.Empty(stream);

Assert.Equal(0, stream.Count);

world.Spawn().Add("a").Add(1);
Assert.Equal(1, stream.Count);

Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}

[Fact]
public void Stream_3Match()
{
using var world = new World();
var stream = world.Stream<string, int, float>(Match.Any);

Assert.Empty(world);
Assert.Empty(stream);

Assert.Equal(0, stream.Count);

world.Spawn().Add("a").Add(1).Add(1.0f);
Assert.Equal(1, stream.Count);

Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}

[Fact]
public void Stream_4Match()
{
using var world = new World();
var stream = world.Stream<string, int, float, object>(Match.Any);

Assert.Empty(world);
Assert.Empty(stream);

Assert.Equal(0, stream.Count);

world.Spawn().Add("a").Add(1).Add(1.0f).Add(new object());
Assert.Equal(1, stream.Count);

Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}

[Fact]
public void Stream_5Match()
{
using var world = new World();
var stream = world.Stream<string, int, float, object, char>(Match.Any);

Assert.Empty(world);
Assert.Empty(stream);

Assert.Equal(0, stream.Count);

world.Spawn().Add("a").Add(1).Add(1.0f).Add(new object()).Add('a');
Assert.Equal(1, stream.Count);

Assert.NotEmpty(world);
Assert.NotEmpty(stream);
}
}
2 changes: 1 addition & 1 deletion fennecs/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal void ForgetArchetype(Archetype archetype)
/// This query's currently matched Archetypes.
/// (affected by filters)
/// </summary>
internal readonly SortedSet<Archetype> Archetypes = [];
internal readonly SortedSet<Archetype> Archetypes;

/// <summary>
/// The World this Query is associated with.
Expand Down
21 changes: 11 additions & 10 deletions fennecs/World.Streamable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public partial class World : Streamable

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1> Stream<C0, C1>(Match match0, Match match1) where C0 : notnull where C1 : notnull
public Stream<C0, C1> Stream<C0, C1>(Match match0, Match match1) where C0 : notnull where C1 : notnull
=> Query<C0, C1>(match0, match1).Stream();

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1> Stream<C0, C1>(Match matchAll = default) where C0 : notnull where C1 : notnull
=> Query<C0, C1>(matchAll).Stream();
=> Stream<C0, C1>(matchAll, matchAll);

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2> Stream<C0, C1, C2>(Match match0, Match match1, Match match2) where C0 : notnull where C1 : notnull where C2 : notnull
=> Query<C0, C1, C2>(match0, match1, match2).Stream();
=> Query<C0, C1, C2>(match0, match1, match2).Stream();

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2> Stream<C0, C1, C2>(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull
=> Query<C0, C1, C2>(matchAll).Stream();
=> Stream<C0, C1, C2>(matchAll, matchAll, matchAll);

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2,C3}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2, C3> Stream<C0, C1, C2, C3>(Match match0, Match match1, Match match2, Match match3) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull
Expand All @@ -34,15 +34,16 @@ public Stream<C0, C1, C2, C3> Stream<C0, C1, C2, C3>(Match match0, Match match1,
/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2,C3}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2, C3> Stream<C0, C1, C2, C3>(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull
=> Query<C0, C1, C2, C3>(matchAll).Stream();
=> Stream<C0, C1, C2, C3>(matchAll, matchAll, matchAll, matchAll);

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2,C3,C4}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2, C3, C4> Stream<C0, C1, C2, C3, C4>(Match match0, Match match1, Match match2, Match match3, Match match4) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull
public Stream<C0, C1, C2, C3, C4> Stream<C0, C1, C2, C3, C4>(Match match0, Match match1, Match match2, Match match3, Match match4)
where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull
=> Query<C0, C1, C2, C3, C4>(match0, match1, match2, match3, match4).Stream();

/// <summary>Compile an internal Query specifically for the requested Stream Types, and return a <see cref="fennecs.Stream{C0,C1,C2,C3,C4}">Stream</see> View for it.</summary>
/// <inheritdoc />
public Stream<C0, C1, C2, C3, C4> Stream<C0, C1, C2, C3, C4>(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull
=> Query<C0, C1, C2, C3, C4>(matchAll).Stream();
=> Stream<C0, C1, C2, C3, C4>(matchAll, matchAll, matchAll, matchAll, matchAll);
}

0 comments on commit 7b8a86c

Please sign in to comment.