Skip to content

Added Unit Test that checks the BTreeIndexBase Column implements IComparable #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests~/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,56 @@ public static void GenericEqualityComparerCheck()
Assert.False(GenericEqualityComparer.Instance.Equals(statusFailed, statusFailedUnequalValue));
Assert.False(GenericEqualityComparer.Instance.Equals(statusCommitted, statusOutOfEnergy));
}

public class BTreeIndexBaseColumnImplementsIComparableTest
{

public sealed class UserHandle : RemoteTableHandle<EventContext, User>
{
protected override string RemoteTableName => "user";

public sealed class IdentityIndex : BTreeIndexBase<SpacetimeDB.Identity>
{
protected override SpacetimeDB.Identity GetKey(User row) => row.Identity;

public IdentityIndex(UserHandle table) : base(table) { }
}

public readonly IdentityIndex Identity;

internal UserHandle(DbConnection conn) : base(conn)
{
Identity = new(this);
}
}
Comment on lines +88 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code won't catch problems that occur if the code generation changes in the future. To catch such problems, we'd need to write the same test against generated code. For example, we could add an index to the Message.Sender field in quickstart-chat -- these tests have access to the quickstart-chat generated code.

If you want to do that, it would be great; if not, I'm willing to merge this, but would appreciate a comment saying why this class is here. // Copy of generated code for a BTreeIndex; TODO: update if that code changes is messy but at least documents what is going on.


[Fact]
public void Identity_ShouldImplementIComparable()
{
// Arrange
var identityType = typeof(SpacetimeDB.Identity);

// Act
bool implementsIComparable =
typeof(IComparable<>).MakeGenericType(identityType).IsAssignableFrom(identityType);

// Assert
Assert.True(implementsIComparable, $"{identityType} does not implement IComparable<{identityType}>");
}

[Fact]
public void IdentityIndex_ShouldInheritFrom_BTreeIndexBase()
{
// Arrange
var identityIndexType = typeof(UserHandle.IdentityIndex);
var expectedBaseType = typeof(RemoteTableHandle<EventContext, User>.BTreeIndexBase<SpacetimeDB.Identity>);

// Act
bool isCorrectBaseType = expectedBaseType.IsAssignableFrom(identityIndexType.BaseType);

// Assert
Assert.True(isCorrectBaseType,
"IdentityIndex does not correctly inherit from BTreeIndexBase<SpacetimeDB.Identity>");
}
}
}
Loading