Skip to content

Commit 9790606

Browse files
author
AndrewMorgan1
committed
Added roundtrip test to HumanBytesExtensionsTests
1 parent 14f9307 commit 9790606

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tests/ByteFlow.Tests/HumanBytesExtensionsTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,21 @@ public void ToBytes_ShouldHandleVeryLargePetabytes()
126126
double expected = 8192 * Math.Pow(1024, 5);
127127
Assert.Equal((long)expected, result);
128128
}
129+
130+
[Theory]
131+
[InlineData(1)]
132+
[InlineData(1024)] // 1 KB
133+
[InlineData(1048576)] // 1 MB
134+
[InlineData(1073741824)] // 1 GB
135+
[InlineData(1099511627776)] // 1 TB
136+
public void RoundTrip_BytesToHumanAndBack_ShouldBeConsistent(long original)
137+
{
138+
string human = original.ToHumanBytes();
139+
long parsed = human.ToBytes();
140+
141+
// Allow slight tolerance because ToHumanBytes() rounds
142+
double tolerance = original * 0.01; // 1% margin
143+
Assert.InRange(parsed, original - tolerance, original + tolerance);
144+
}
129145
}
130146
}

0 commit comments

Comments
 (0)