Skip to content

Commit

Permalink
0.7.2
Browse files Browse the repository at this point in the history
- Fixes and improvements to the tests;
- Code style changes.
  • Loading branch information
RomashkinAndrew committed Apr 26, 2024
1 parent 8547108 commit cc1e7a2
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 10,749 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
/TrulyRandom/bin/Release/net6.0-windows10.0.17763.0/TrulyRandom.deps.json
/TrulyRandom/bin/Release/net5.0/TrulyRandom.deps.json
*.nupkg
bin
Binary file removed TrulyRandom/bin/Release/net5.0/TrulyRandom.dll
Binary file not shown.
Binary file removed TrulyRandom/bin/Release/net5.0/TrulyRandom.pdb
Binary file not shown.
5,299 changes: 0 additions & 5,299 deletions TrulyRandom/bin/Release/net5.0/TrulyRandom.xml

This file was deleted.

23 changes: 0 additions & 23 deletions TrulyRandom/bin/Release/net6.0/TrulyRandom.deps.json

This file was deleted.

Binary file removed TrulyRandom/bin/Release/net6.0/TrulyRandom.dll
Binary file not shown.
Binary file removed TrulyRandom/bin/Release/net6.0/TrulyRandom.pdb
Binary file not shown.
5,299 changes: 0 additions & 5,299 deletions TrulyRandom/bin/Release/net6.0/TrulyRandom.xml

This file was deleted.

6 changes: 3 additions & 3 deletions UnitTests/Tests/Extractors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void HashE()

Assert.IsTrue(extractor.NoDataToProcess);
Assert.IsTrue(extractor.Entropy > 0.9);
Assert.IsTrue(extractor.BytesInBuffer == 64 * 1000);
Assert.AreEqual(64 * 1000, extractor.BytesInBuffer);
}

[TestMethod]
Expand All @@ -172,7 +172,7 @@ public void HashBadSequence()

Assert.IsTrue(extractor.NoDataToProcess);
Assert.IsTrue(extractor.Entropy < 0.9);
Assert.IsTrue(extractor.BytesInBuffer == 64 * 12500);
Assert.AreEqual(64 * 12500, extractor.BytesInBuffer);
}

[TestMethod]
Expand Down Expand Up @@ -245,7 +245,7 @@ public void ShuffleArrayOfOnes()
extractor.Dispose();

Assert.IsTrue(extractor.NoDataToProcess);
Assert.IsTrue(extractor.BytesInBuffer == 0);
Assert.AreEqual(0, extractor.BytesInBuffer);
}

[TestMethod]
Expand Down
83 changes: 43 additions & 40 deletions UnitTests/Tests/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ public void MultipleSourceMixing()

byte[] data = buffer4.ReadAll();
(int Zeros, int Ones, int Twos) = GetLongestRuns(data);
Assert.IsTrue(buffer1.BytesInBuffer == 0);
Assert.IsTrue(buffer2.BytesInBuffer == 0);
Assert.IsTrue(buffer3.BytesInBuffer == 0);
Assert.IsTrue(buffer4.BytesInBuffer == 0);
Assert.IsTrue(data.Length == 162);
Assert.IsTrue(Zeros == 2);
Assert.IsTrue(Ones == 1);
Assert.IsTrue(Twos == 1);
Assert.IsTrue(data.Where(x => x == 0).Count() == 100);
Assert.IsTrue(data.Where(x => x == 1).Count() == 57);
Assert.IsTrue(data.Where(x => x == 2).Count() == 5);
Assert.AreEqual(0,buffer1.BytesInBuffer);
Assert.AreEqual(0,buffer2.BytesInBuffer);
Assert.AreEqual(0,buffer3.BytesInBuffer);
Assert.AreEqual(0,buffer4.BytesInBuffer);
Assert.AreEqual(162, data.Length);
Assert.AreEqual(2, Zeros);
Assert.AreEqual(1, Ones);
Assert.AreEqual(1, Twos);
Assert.AreEqual(100, data.Where(x => x == 0).Count());
Assert.AreEqual(57, data.Where(x => x == 1).Count());
Assert.AreEqual(5, data.Where(x => x == 2).Count());

buffer1.Dispose();
buffer2.Dispose();
Expand Down Expand Up @@ -134,17 +134,17 @@ public void MultipleSourceNoMixing()

byte[] data = buffer4.ReadAll();
(int Zeros, int Ones, int Twos) = GetLongestRuns(data);
Assert.IsTrue(buffer1.BytesInBuffer == 0);
Assert.IsTrue(buffer2.BytesInBuffer == 0);
Assert.IsTrue(buffer3.BytesInBuffer == 0);
Assert.IsTrue(buffer4.BytesInBuffer == 0);
Assert.IsTrue(data.Length == 162);
Assert.IsTrue(Zeros == 100);
Assert.IsTrue(Ones == 57);
Assert.IsTrue(Twos == 5);
Assert.IsTrue(data.Where(x => x == 0).Count() == 100);
Assert.IsTrue(data.Where(x => x == 1).Count() == 57);
Assert.IsTrue(data.Where(x => x == 2).Count() == 5);
Assert.AreEqual(0, buffer1.BytesInBuffer);
Assert.AreEqual(0, buffer2.BytesInBuffer);
Assert.AreEqual(0, buffer3.BytesInBuffer);
Assert.AreEqual(0, buffer4.BytesInBuffer);
Assert.AreEqual(162, data.Length);
Assert.AreEqual(100, Zeros);
Assert.AreEqual(57, Ones);
Assert.AreEqual(5, Twos);
Assert.AreEqual(100, data.Where(x => x == 0).Count());
Assert.AreEqual(57, data.Where(x => x == 1).Count());
Assert.AreEqual(5, data.Where(x => x == 2).Count());

buffer1.Dispose();
buffer2.Dispose();
Expand Down Expand Up @@ -219,16 +219,16 @@ public void DynamicCoefficient()

Thread.Sleep(100);

Assert.IsTrue(extractor.ActualCompression == 1);
Assert.IsTrue(extractor.BytesInBuffer == 0);
Assert.IsTrue(buffer2.BytesInBuffer == 640);
Assert.AreEqual(1,extractor.ActualCompression);
Assert.AreEqual(0,extractor.BytesInBuffer);
Assert.AreEqual(640, buffer2.BytesInBuffer);

Utils.InvokePrivate(buffer1, "AddData", Enumerable.Repeat((byte)0, 640).ToArray());

Thread.Sleep(100);

Assert.IsTrue(extractor.ActualCompression == 3); //dynamic coefficient = 0.64, that means compression multiplier by 3
Assert.IsTrue(buffer2.BytesInBuffer == 640 + 192); // 640 bytes is 3 blocks of 64*3 = 192 bytes. 192*3 compressed is 3 blocks of 64 bytes = 192 bytes.
Assert.AreEqual(3, extractor.ActualCompression); //dynamic coefficient = 0.64, that means compression multiplier by 3
Assert.AreEqual(640+192,buffer2.BytesInBuffer); //640 bytes is 3 blocks of 64*3 = 192 bytes. 192*3 compressed is 3 blocks of 64 bytes = 192 bytes.

buffer1.Dispose();
buffer2.Dispose();
Expand Down Expand Up @@ -307,9 +307,9 @@ public void TesterE()

Assert.IsTrue(tester.BytesInBuffer <= 125000);
Assert.IsTrue(tester.BytesInBuffer > 124000);
Assert.IsTrue(tester.TestParameters.TestsToPerform == TrulyRandom.NistTests.TestsEnum.All);
Assert.AreEqual(TrulyRandom.NistTests.TestsEnum.All,tester.TestParameters.TestsToPerform);
Assert.IsTrue(lastTestResult.Success);
Assert.IsTrue(lastTestResult.SuccessfulTestProportion == 1);
Assert.AreEqual(1, lastTestResult.SuccessfulTestProportion);

tester.Dispose();
buffer.Dispose();
Expand All @@ -336,8 +336,8 @@ public void TesterBadSequence()

TrulyRandom.NistTests.FullTestResult lastTestResult = tester.LastTestResult;

Assert.IsTrue(buffer.BytesInBuffer == 0);
Assert.IsTrue(tester.TestParameters.TestsToPerform == TrulyRandom.NistTests.TestsEnum.All);
Assert.AreEqual(0, buffer.BytesInBuffer);
Assert.AreEqual(TrulyRandom.NistTests.TestsEnum.All, tester.TestParameters.TestsToPerform);
Assert.IsTrue(!lastTestResult.Success);
Assert.IsTrue(lastTestResult.SuccessfulTestProportion < 1);

Expand Down Expand Up @@ -376,23 +376,23 @@ public void TestResultAnalysis()
tester.Parameters.LongTermEvaluation.PassByDefault = false;
TrulyRandom.NistTests.FullTestResult result = tester.Perform(data);

Assert.IsTrue(!result.Success);
Assert.IsFalse(result.Success);

tester.ClearHistory();
tester.Parameters.AllowedFailedTestProportion = 0;
tester.Parameters.AllowedFailedSubtestProportion = 0;
tester.Parameters.LongTermEvaluation.PassByDefault = true;
result = tester.Perform(data);

Assert.IsTrue(!result.Success);
Assert.IsFalse(result.Success);

tester.ClearHistory();
tester.Parameters.AllowedFailedTestProportion = 0;
tester.Parameters.AllowedFailedSubtestProportion = 0.1;
tester.Parameters.LongTermEvaluation.PassByDefault = false;
result = tester.Perform(data);

Assert.IsTrue(!result.Success);
Assert.IsFalse(result.Success);

tester.ClearHistory();
tester.Parameters.AllowedFailedTestProportion = 0.1;
Expand All @@ -409,7 +409,7 @@ public void TestResultAnalysis()
result = tester.Perform(data);
Assert.IsTrue(result.Success);
result = tester.Perform(data);
Assert.IsTrue(!result.Success);
Assert.IsFalse(result.Success);
}

[TestMethod]
Expand All @@ -435,9 +435,9 @@ public void Compression()

byte[] data = extractor.ReadAll();
Assert.IsTrue(extractor.NoDataToProcess);
Assert.IsTrue(extractor.ActualCompression == 2);
Assert.AreEqual(2, extractor.ActualCompression);
Assert.IsTrue(!data.Where(x => x != 0).Any());
Assert.IsTrue(data.Length == 5000);
Assert.AreEqual(5000, data.Length);
}

[TestMethod]
Expand Down Expand Up @@ -479,8 +479,8 @@ public void Entropy()

Thread.Sleep(1500);

Assert.IsTrue(buffer1.Entropy == 0);
Assert.IsTrue(buffer2.Entropy == 1);
Assert.AreEqual(0, buffer1.Entropy);
Assert.AreEqual(1, buffer2.Entropy);
}

[TestMethod]
Expand All @@ -493,7 +493,10 @@ public void CircularBuffer()
buffer.Write(new byte[] { 4 });
buffer.Write(5);
byte[] arr = buffer.Read(3);
Assert.IsTrue(arr[0] == 3 && arr[1] == 4 && arr[2] == 5 && buffer.Count == 0);
Assert.AreEqual(3, arr[0]);
Assert.AreEqual(4, arr[1]);
Assert.AreEqual(5, arr[2]);
Assert.AreEqual(3, buffer.Count);
}
}
}
Loading

0 comments on commit cc1e7a2

Please sign in to comment.