Skip to content

Commit 59e6f11

Browse files
committed
Ensure we have duplicate key check
1 parent 3a98e78 commit 59e6f11

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Src/FastData.InternalShared/Helpers/TestHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ public static bool TryWriteFile(string path, string content)
103103
/// <summary>This variant of Generate bypasses the public API to test more advanced combinations of parameters</summary>
104104
public static GeneratorSpec Generate<TKey, TValue>(Func<string, ICodeGenerator> func, TestVector<TKey> vector, TValue[]? values) where TValue : notnull
105105
{
106+
//Sanity check to avoid duplicate keys
107+
HashSet<TKey> uniq = new HashSet<TKey>();
108+
109+
foreach (TKey key in vector.Keys)
110+
{
111+
if (!uniq.Add(key))
112+
throw new InvalidOperationException($"Duplicate key found: {key}");
113+
}
114+
106115
KeyType keyType = Enum.Parse<KeyType>(typeof(TKey).Name);
107116

108117
IProperties props;

Src/FastData/FastDataGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ private static string GenerateInternal<TKey, TValue>(TKey[] keys, TValue[]? valu
6464
//Validate that we only have unique data
6565
HashSet<TKey> uniq = new HashSet<TKey>();
6666

67-
foreach (TKey val in keys)
67+
foreach (TKey key in keys)
6868
{
69-
if (!uniq.Add(val))
70-
throw new InvalidOperationException($"Duplicate data found: {val}");
69+
if (!uniq.Add(key))
70+
throw new InvalidOperationException($"Duplicate data found: {key}");
7171
}
7272

7373
ILogger logger = factory.CreateLogger(typeof(FastDataGenerator));

0 commit comments

Comments
 (0)