Skip to content

Commit

Permalink
silencing more warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Jun 5, 2024
1 parent a29aadd commit 8d78bba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 71 deletions.
2 changes: 1 addition & 1 deletion test/AsciiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void HardCodedSequencesTest()
}

[Fact]
public void Test_ASCII_generator()
public void TestASCIIGenerator()
{
const int NUM_TRIALS = 1000;
const int MAX_LENGTH = 255;
Expand Down
16 changes: 11 additions & 5 deletions test/UTF8ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum TestSystemRequirements
// Add more as needed
}

public class FactOnSystemRequirementAttribute : FactAttribute
private sealed class FactOnSystemRequirementAttribute : FactAttribute
{
private TestSystemRequirements RequiredSystems;

Expand Down Expand Up @@ -62,7 +62,7 @@ private bool IsSystemSupported(TestSystemRequirements requiredSystems)
}


public class TestIfCondition : FactAttribute
public sealed class TestIfCondition : FactAttribute
{
public TestIfCondition(Func<bool> condition, string skipReason)
{
Expand Down Expand Up @@ -1034,6 +1034,7 @@ public void BruteForceTestArm64()
// credit: based on code from Google Fuchsia (Apache Licensed)
public static bool ValidateUtf8Fuschia(byte[] data)
{
if(data == null) return false;
int pos = 0;
int len = data.Length;
uint codePoint;
Expand Down Expand Up @@ -1104,13 +1105,14 @@ private bool InvalidateUtf8(byte[] utf8, int badindex,Utf8ValidationDelegate utf
int utf16CodeUnitCountAdjustment, scalarCountAdjustment;
byte* dotnetResult = DotnetRuntime.Utf8Utility.GetPointerToFirstInvalidByte(pInput, utf8.Length, out utf16CodeUnitCountAdjustment, out scalarCountAdjustment);
int dotnetOffset = (int)(dotnetResult - pInput);
var message = "Suprisingly, scalarResult != simdResult {0} != {1}, badindex = {2}, length = {3}";
if (scalarOffset != simdOffset)
{
Console.WriteLine("Suprisingly, scalarResult != simdResult {0} != {1}, badindex = {2}, length = {3}", scalarOffset, simdOffset, badindex, utf8.Length);
Console.WriteLine(message, scalarOffset, simdOffset, badindex, utf8.Length);
}
if (dotnetOffset != simdOffset)
{
Console.WriteLine("Suprisingly, dotnetOffset != simdResult {0} != {1}, badindex = {2}, length = {3}", dotnetOffset, simdOffset, badindex, utf8.Length);
Console.WriteLine(message, dotnetOffset, simdOffset, badindex, utf8.Length);
}
return (scalarResult == simdResult) && (simdResult == dotnetResult);
}
Expand Down Expand Up @@ -1151,7 +1153,7 @@ private bool ValidateUtf8(byte[] utf8,Utf8ValidationDelegate utf8ValidationDeleg
}

// Helper method to calculate the actual offset and length from a Range
private (int offset, int length) GetOffsetAndLength(int totalLength, Range range)
private static (int offset, int length) GetOffsetAndLength(int totalLength, Range range)
{
var start = range.Start.GetOffset(totalLength);
var end = range.End.GetOffset(totalLength);
Expand All @@ -1167,6 +1169,10 @@ public bool ValidateCount(byte[] utf8, Utf8ValidationDelegate utf8ValidationDele
{
int dotnetUtf16Adjustment, dotnetScalarCountAdjustment;
int simdUnicodeUtf16Adjustment, simdUnicodeScalarCountAdjustment;
if(utf8 == null || utf8ValidationDelegate == null)
{
return false;
}

var isDefaultRange = range.Equals(default(Range));
var (offset, length) = isDefaultRange ? (0, utf8.Length) : GetOffsetAndLength(utf8.Length, range);
Expand Down
68 changes: 3 additions & 65 deletions test/helpers/randomutf8.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
namespace tests;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,27 +10,12 @@ public class RandomUtf8
private double[] probabilities;
private const int maxByteLength = 4;

public RandomUtf8(uint seed, int prob_1byte, int prob_2bytes, int prob_3bytes, int prob_4bytes)
public RandomUtf8(uint seed, int prob1byte, int prob2bytes, int prob3bytes, int prob4bytes)
{
gen = new Random((int)seed);
probabilities = new double[maxByteLength] { prob_1byte, prob_2bytes, prob_3bytes, prob_4bytes };
probabilities = new double[maxByteLength] { prob1byte, prob2bytes, prob3bytes, prob4bytes };
}

// public byte[] Generate(int howManyUnits, int? byteCountInUnit = null)
// {
// var result = new List<byte>();
// while (result.Count < howManyUnits)
// {
// int count = byteCountInUnit ?? PickRandomByteCount();
// int codePoint = GenerateCodePoint(count);
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));

// result.AddRange(utf8Bytes);
// if (result.Count + utf8Bytes.Length > howManyUnits)
// break;
// }
// return result.ToArray();
// }

public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
{
Expand All @@ -47,54 +33,6 @@ public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
return result;
}

// public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
// {
// var result = new List<byte>();
// var unitsAdded = 0; // Track the number of characters added.

// while (unitsAdded < howManyUnits)
// {
// int count = byteCountInUnit ?? PickRandomByteCount();
// int codePoint = GenerateCodePoint(count);
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));

// // Ensure adding the new character won't exceed the howManyUnits limit.
// if (unitsAdded + 1 > howManyUnits)
// break;

// result.AddRange(utf8Bytes);
// unitsAdded++; // Increment the units (characters) count.
// }

// return result;
// }


// public object Generate(int howManyUnits, int? byteCountInUnit = null, bool returnAsList = false)
// {
// var result = new List<byte>();
// while (result.Count < howManyUnits)
// {
// int count = byteCountInUnit ?? PickRandomByteCount();
// int codePoint = GenerateCodePoint(count);
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));

// if (result.Count + utf8Bytes.Length > howManyUnits)
// break;

// result.AddRange(utf8Bytes);
// }

// if (returnAsList)
// {
// return result;
// }
// else
// {
// return result.ToArray();
// }
// }

private int GenerateCodePoint(int byteCount)
{
switch (byteCount)
Expand Down

0 comments on commit 8d78bba

Please sign in to comment.