Skip to content

Tests | Refactor NativeVectorFloat32Tests for future Half support#4347

Open
edwardneal wants to merge 27 commits into
dotnet:mainfrom
edwardneal:tests/generic-vector-testbase
Open

Tests | Refactor NativeVectorFloat32Tests for future Half support#4347
edwardneal wants to merge 27 commits into
dotnet:mainfrom
edwardneal:tests/generic-vector-testbase

Conversation

@edwardneal

Copy link
Copy Markdown
Contributor

Description

This is somewhat inspired by #4234. We don't yet have support for SqlVector<Half> and other types, but this should hopefully make the test logic trivial to add.

I'd recommend moving commit by commit - the introduction of a base class has resulted in the PR looking much larger than it truly is.

The overall design is now more generic. We have:

  • NativeVectorTestDataBase<TElement>, which contains test data for SqlVector<TElement>
  • NativeVectorTestsBase<TElement, TTestData>, which contains the test logic and links it to the test data
  • VectorFloat32TestData: derived from NativeVectorTestDataBase which contains float-based sample data
  • NativeVectorFloat32Tests: the same tests and the same logic as in main, but derived from NativeVectorTestsBase

Adding future support for Half should mean simply introducing VectorFloat16TestData and NativeVectorFloat16Tests classes:

public sealed class VectorFloat16TestData : NativeVectorTestDataBase<Half>
{
    public override Half[] SampleScalarData => [1, 2, 3, 4, 5, 6];

    public override Half[,] SampleDataSet => /* */;

    public override int IncorrectScalarDataParameterSize => 9999;

    public override bool IsSupported => DataTestUtility.IsSqlVectorFloat16Supported;

    public override string SqlServerTypeName => "float16";
}

public sealed class NativeVectorFloat16Tests : NativeVectorTestsBase<Half, VectorFloat16TestData>
{
}

I've also made a handful of hygiene improvements, but none are particularly controversial:

  • Use of RAII primitives
  • Text corrections in comments
  • Assertion cleanups (catching an exception and running Assert.Fail, performing Assert.True(!verifyReader.IsDBNull(0), ...), etc.)
  • Nullability annotations

Issues

In lieu of any more specific issue for Half/float16 support for SqlVector, this contributes to #3444.

Testing

All automated tests continue to pass.

@edwardneal edwardneal requested a review from a team as a code owner June 7, 2026 16:15
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Jun 7, 2026
@apoorvdeshmukh apoorvdeshmukh self-assigned this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants