@@ -17,6 +17,12 @@ namespace Celerity.Tests.Collections;
1717/// </summary>
1818public class SetIEnumerableConstructorTests
1919{
20+ // The hash-table sets reserve an out-of-band null slot and never hash it.
21+ // Keep the generic type non-nullable to match StringFnV1AHasher's contract
22+ // while deliberately retaining runtime-null test data for that slot.
23+ private static string [ ] CreateSourceWithRuntimeNulls ( params string ? [ ] values ) =>
24+ Array . ConvertAll ( values , static value => value ! ) ;
25+
2026 // ──────────────────────────────────────────────────────────────
2127 // IntSet — source argument validation
2228 // ──────────────────────────────────────────────────────────────
@@ -480,12 +486,12 @@ public void CeleritySet_ShouldSilentlyDedupe_DuplicateElements()
480486 public void CeleritySet_ShouldSilentlyDedupe_DuplicateNullElements ( )
481487 {
482488 // null is the out-of-band slot for reference-typed sets — ensure dedupe covers it.
483- var source = new string ? [ ] { "a" , null , "b" , null , "c" , null } ;
489+ var source = CreateSourceWithRuntimeNulls ( "a" , null , "b" , null , "c" , null ) ;
484490
485- var set = new CeleritySet < string ? , StringFnV1AHasher > ( source ) ;
491+ var set = new CeleritySet < string , StringFnV1AHasher > ( source ) ;
486492
487493 Assert . Equal ( 4 , set . Count ) ;
488- Assert . True ( set . Contains ( null ) ) ;
494+ Assert . True ( set . Contains ( null ! ) ) ;
489495 Assert . True ( set . Contains ( "a" ) ) ;
490496 Assert . True ( set . Contains ( "b" ) ) ;
491497 Assert . True ( set . Contains ( "c" ) ) ;
@@ -509,12 +515,12 @@ public void CeleritySet_ShouldSilentlyDedupe_DuplicateDefaultValueTypeElements()
509515 [ Fact ]
510516 public void CeleritySet_ShouldCaptureNullElement_FromSource ( )
511517 {
512- var source = new string ? [ ] { null , "x" , "y" } ;
518+ var source = CreateSourceWithRuntimeNulls ( null , "x" , "y" ) ;
513519
514- var set = new CeleritySet < string ? , StringFnV1AHasher > ( source ) ;
520+ var set = new CeleritySet < string , StringFnV1AHasher > ( source ) ;
515521
516522 Assert . Equal ( 3 , set . Count ) ;
517- Assert . True ( set . Contains ( null ) ) ;
523+ Assert . True ( set . Contains ( null ! ) ) ;
518524 Assert . True ( set . Contains ( "x" ) ) ;
519525 Assert . True ( set . Contains ( "y" ) ) ;
520526 }
@@ -662,12 +668,12 @@ public void SwissSet_ShouldSilentlyDedupe_DuplicateElements()
662668 [ Fact ]
663669 public void SwissSet_ShouldSilentlyDedupe_DuplicateNullElements ( )
664670 {
665- var source = new string ? [ ] { "a" , null , "b" , null , "c" , null } ;
671+ var source = CreateSourceWithRuntimeNulls ( "a" , null , "b" , null , "c" , null ) ;
666672
667- var set = new SwissSet < string ? , StringFnV1AHasher > ( source ) ;
673+ var set = new SwissSet < string , StringFnV1AHasher > ( source ) ;
668674
669675 Assert . Equal ( 4 , set . Count ) ;
670- Assert . True ( set . Contains ( null ) ) ;
676+ Assert . True ( set . Contains ( null ! ) ) ;
671677 Assert . True ( set . Contains ( "a" ) ) ;
672678 Assert . True ( set . Contains ( "b" ) ) ;
673679 Assert . True ( set . Contains ( "c" ) ) ;
@@ -689,12 +695,12 @@ public void SwissSet_ShouldSilentlyDedupe_DuplicateDefaultValueTypeElements()
689695 [ Fact ]
690696 public void SwissSet_ShouldCaptureNullElement_FromSource ( )
691697 {
692- var source = new string ? [ ] { null , "x" , "y" } ;
698+ var source = CreateSourceWithRuntimeNulls ( null , "x" , "y" ) ;
693699
694- var set = new SwissSet < string ? , StringFnV1AHasher > ( source ) ;
700+ var set = new SwissSet < string , StringFnV1AHasher > ( source ) ;
695701
696702 Assert . Equal ( 3 , set . Count ) ;
697- Assert . True ( set . Contains ( null ) ) ;
703+ Assert . True ( set . Contains ( null ! ) ) ;
698704 Assert . True ( set . Contains ( "x" ) ) ;
699705 Assert . True ( set . Contains ( "y" ) ) ;
700706 }
@@ -844,12 +850,12 @@ public void RobinHoodSet_ShouldSilentlyDedupe_DuplicateElements()
844850 [ Fact ]
845851 public void RobinHoodSet_ShouldSilentlyDedupe_DuplicateNullElements ( )
846852 {
847- var source = new string ? [ ] { "a" , null , "b" , null , "c" , null } ;
853+ var source = CreateSourceWithRuntimeNulls ( "a" , null , "b" , null , "c" , null ) ;
848854
849- var set = new RobinHoodSet < string ? , StringFnV1AHasher > ( source ) ;
855+ var set = new RobinHoodSet < string , StringFnV1AHasher > ( source ) ;
850856
851857 Assert . Equal ( 4 , set . Count ) ;
852- Assert . True ( set . Contains ( null ) ) ;
858+ Assert . True ( set . Contains ( null ! ) ) ;
853859 Assert . True ( set . Contains ( "a" ) ) ;
854860 Assert . True ( set . Contains ( "b" ) ) ;
855861 Assert . True ( set . Contains ( "c" ) ) ;
@@ -871,12 +877,12 @@ public void RobinHoodSet_ShouldSilentlyDedupe_DuplicateDefaultValueTypeElements(
871877 [ Fact ]
872878 public void RobinHoodSet_ShouldCaptureNullElement_FromSource ( )
873879 {
874- var source = new string ? [ ] { null , "x" , "y" } ;
880+ var source = CreateSourceWithRuntimeNulls ( null , "x" , "y" ) ;
875881
876- var set = new RobinHoodSet < string ? , StringFnV1AHasher > ( source ) ;
882+ var set = new RobinHoodSet < string , StringFnV1AHasher > ( source ) ;
877883
878884 Assert . Equal ( 3 , set . Count ) ;
879- Assert . True ( set . Contains ( null ) ) ;
885+ Assert . True ( set . Contains ( null ! ) ) ;
880886 Assert . True ( set . Contains ( "x" ) ) ;
881887 Assert . True ( set . Contains ( "y" ) ) ;
882888 }
@@ -1026,12 +1032,12 @@ public void HashCachingSet_ShouldSilentlyDedupe_DuplicateElements()
10261032 [ Fact ]
10271033 public void HashCachingSet_ShouldSilentlyDedupe_DuplicateNullElements ( )
10281034 {
1029- var source = new string ? [ ] { "a" , null , "b" , null , "c" , null } ;
1035+ var source = CreateSourceWithRuntimeNulls ( "a" , null , "b" , null , "c" , null ) ;
10301036
1031- var set = new HashCachingSet < string ? , StringFnV1AHasher > ( source ) ;
1037+ var set = new HashCachingSet < string , StringFnV1AHasher > ( source ) ;
10321038
10331039 Assert . Equal ( 4 , set . Count ) ;
1034- Assert . True ( set . Contains ( null ) ) ;
1040+ Assert . True ( set . Contains ( null ! ) ) ;
10351041 Assert . True ( set . Contains ( "a" ) ) ;
10361042 Assert . True ( set . Contains ( "b" ) ) ;
10371043 Assert . True ( set . Contains ( "c" ) ) ;
@@ -1053,12 +1059,12 @@ public void HashCachingSet_ShouldSilentlyDedupe_DuplicateDefaultValueTypeElement
10531059 [ Fact ]
10541060 public void HashCachingSet_ShouldCaptureNullElement_FromSource ( )
10551061 {
1056- var source = new string ? [ ] { null , "x" , "y" } ;
1062+ var source = CreateSourceWithRuntimeNulls ( null , "x" , "y" ) ;
10571063
1058- var set = new HashCachingSet < string ? , StringFnV1AHasher > ( source ) ;
1064+ var set = new HashCachingSet < string , StringFnV1AHasher > ( source ) ;
10591065
10601066 Assert . Equal ( 3 , set . Count ) ;
1061- Assert . True ( set . Contains ( null ) ) ;
1067+ Assert . True ( set . Contains ( null ! ) ) ;
10621068 Assert . True ( set . Contains ( "x" ) ) ;
10631069 Assert . True ( set . Contains ( "y" ) ) ;
10641070 }
@@ -1208,12 +1214,12 @@ public void PooledCeleritySet_ShouldSilentlyDedupe_DuplicateElements()
12081214 [ Fact ]
12091215 public void PooledCeleritySet_ShouldSilentlyDedupe_DuplicateNullElements ( )
12101216 {
1211- var source = new string ? [ ] { "a" , null , "b" , null , "c" , null } ;
1217+ var source = CreateSourceWithRuntimeNulls ( "a" , null , "b" , null , "c" , null ) ;
12121218
1213- using var set = new PooledCeleritySet < string ? , StringFnV1AHasher > ( source ) ;
1219+ using var set = new PooledCeleritySet < string , StringFnV1AHasher > ( source ) ;
12141220
12151221 Assert . Equal ( 4 , set . Count ) ;
1216- Assert . True ( set . Contains ( null ) ) ;
1222+ Assert . True ( set . Contains ( null ! ) ) ;
12171223 Assert . True ( set . Contains ( "a" ) ) ;
12181224 Assert . True ( set . Contains ( "b" ) ) ;
12191225 Assert . True ( set . Contains ( "c" ) ) ;
@@ -1235,12 +1241,12 @@ public void PooledCeleritySet_ShouldSilentlyDedupe_DuplicateDefaultValueTypeElem
12351241 [ Fact ]
12361242 public void PooledCeleritySet_ShouldCaptureNullElement_FromSource ( )
12371243 {
1238- var source = new string ? [ ] { null , "x" , "y" } ;
1244+ var source = CreateSourceWithRuntimeNulls ( null , "x" , "y" ) ;
12391245
1240- using var set = new PooledCeleritySet < string ? , StringFnV1AHasher > ( source ) ;
1246+ using var set = new PooledCeleritySet < string , StringFnV1AHasher > ( source ) ;
12411247
12421248 Assert . Equal ( 3 , set . Count ) ;
1243- Assert . True ( set . Contains ( null ) ) ;
1249+ Assert . True ( set . Contains ( null ! ) ) ;
12441250 Assert . True ( set . Contains ( "x" ) ) ;
12451251 Assert . True ( set . Contains ( "y" ) ) ;
12461252 }
0 commit comments