Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit d6fcb3b

Browse files
committed
Remove magic number by adding a setting
1 parent c8ff386 commit d6fcb3b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

UniqueFileGenerator/FileHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ private IEnumerable<FileData> GetFileData()
2121

2222
for (uint i = 0; i < Settings.FileCount; i++)
2323
{
24-
var randomChars = stringFactory.CreateUniqueString(10);
25-
var fileName = Settings.Prefix + randomChars;
24+
var randomText = stringFactory.CreateUniqueString(length: Settings.RandomStringLength);
25+
var fileName = Settings.Prefix + randomText;
2626

2727
var contents = Settings.SizeInBytes.HasValue
28-
? stringFactory.CreateUniqueString(Settings.SizeInBytes.Value)
28+
? stringFactory.CreateUniqueString(length: Settings.SizeInBytes.Value)
2929
: fileName;
3030

3131
yield return new FileData(fileName, contents);

UniqueFileGenerator/Settings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ public sealed class Settings
4242
/// <summary>
4343
/// The amount of disk space that is necessary for the operation.
4444
/// </summary>
45-
public long DiskSpaceNecessary => FileCount * (SizeInBytes ?? (Prefix.Length + 10));
45+
public long DiskSpaceNecessary =>
46+
FileCount * (SizeInBytes ?? (Prefix.Length + RandomStringLength));
4647

4748
public bool IsHighFileCount => FileCount > 50_000;
4849
public bool IsLargeSize => SizeInBytes > 100_000_000;
4950
public bool IsLongDelay => FileCreationDelayMs > 60_000; // 1m
5051

52+
public const ushort RandomStringLength = 10; // This could be configurable too.
53+
5154
public Settings(ParsedArguments parsedArgs)
5255
{
5356
FileCount = parsedArgs.FileCount;
@@ -135,4 +138,4 @@ private static bool IsLastCharAlphanumeric(string text) =>
135138

136139
private static string EnforceStartingPeriod(string text) =>
137140
(text[0] == '.' ? string.Empty : ".") + text;
138-
}
141+
}

0 commit comments

Comments
 (0)