Skip to content

Commit 70ca2a1

Browse files
committed
dotnet format
1 parent 7a687b8 commit 70ca2a1

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

benchmark/Benchmark.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace SimdUnicodeBenchmarks
1515
public class Checker
1616
{
1717
List<char[]> names;
18-
List<char[]> nonAsciichars;
19-
public List<byte[]> nonAsciiByteArrays; // Declare at the class level
18+
List<char[]> nonAsciichars;
19+
public List<byte[]> nonAsciiByteArrays; // Declare at the class level
2020

2121
List<bool> results;
2222

@@ -56,8 +56,8 @@ public static char[] GetRandomASCIIString(uint n)
5656
public static char[] GetRandomNonASCIIString(uint n)
5757
{
5858
// Chose a few Latin Extended-A and Latin Extended-B characters alongside ASCII chars
59-
var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ01234567é89šžŸũŭůűųŷŹźŻżŽ";
60-
59+
var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ01234567é89šžŸũŭůűųŷŹźŻżŽ";
60+
6161
var chars = new char[n];
6262
var rd = new Random(12345); // fixed seed
6363

@@ -71,7 +71,7 @@ public static char[] GetRandomNonASCIIString(uint n)
7171

7272

7373

74-
[Params(100, 200, 500,1000,2000)]
74+
[Params(100, 200, 500, 1000, 2000)]
7575
public uint N;
7676

7777

test/AsciiTest.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public void HardCodedSequencesTest()
7979
foreach (var sequence in goodsequences)
8080
{
8181
Assert.True(SimdUnicode.Ascii.IsAscii(sequence), "Expected valid ASCII sequence");
82-
Assert.True(SimdUnicode.Ascii.SIMDIsAscii(sequence), "Expected SIMDIsAscii to validate ASCII sequence");
83-
82+
Assert.True(SimdUnicode.Ascii.SIMDIsAscii(sequence), "Expected SIMDIsAscii to validate ASCII sequence");
83+
8484
}
8585

8686
foreach (var sequence in badsequences)
@@ -91,7 +91,7 @@ public void HardCodedSequencesTest()
9191
}
9292

9393
[Fact]
94-
public void Test_random_ASCII_sequences_of_varying_lengths()
94+
public void Test_ASCII_generator()
9595
{
9696
const int NUM_TRIALS = 1000;
9797
const int MAX_LENGTH = 255;
@@ -126,17 +126,16 @@ public void Test_random_ASCII_sequences_of_varying_lengths()
126126

127127

128128
[Fact]
129-
// This mimics the no_error_ASCII test
130-
public void TestNoErrorASCII()
129+
public void TestNoErrorGetIndexOfFirstNonAsciiByte()
131130
{
132131
const int NUM_TRIALS = 1000;
133132
const int LENGTH = 512;
134133
RandomUtf8 utf8Generator = new RandomUtf8(0, 100, 0, 0, 0); // Only ASCII/one-bytes
135134

136135
for (int trial = 0; trial < NUM_TRIALS; trial++)
137136
{
138-
byte[] ascii = utf8Generator.Generate(LENGTH);
139-
137+
byte[] ascii = utf8Generator.Generate(LENGTH);
138+
140139
unsafe
141140
{
142141
fixed (byte* pAscii = ascii)
@@ -152,8 +151,7 @@ public void TestNoErrorASCII()
152151
}
153152

154153
[Fact]
155-
// This mimics the error_ASCII test
156-
public void TestErrorASCII()
154+
public void TestErrorGetIndexOfFirstNonAsciiByte()
157155
{
158156
const int NUM_TRIALS = 1000;
159157
const int LENGTH = 512;
@@ -182,7 +180,7 @@ public void TestErrorASCII()
182180
ascii[i] -= 0b10000000;
183181
}
184182
}
185-
}
186-
187-
183+
}
184+
185+
188186
}

test/helpers/randomutf8.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ public class RandomUtf8
66
{
77
// Internal random number generator
88
private Random gen;
9-
9+
1010
// Array of probabilities for each UTF-8 byte count (1-byte, 2-bytes, etc.)
1111
private double[] probabilities;
12-
12+
1313
// Maximum number of bytes a UTF-8 character can be (based on the standard)
1414
private const int maxByteLength = 4;
1515

@@ -28,11 +28,11 @@ public byte[] Generate(int outputBytes)
2828
{
2929
uint codePoint = GenerateCodePoint();
3030
byte[] utf8Bytes = EncodeToUTF8(codePoint);
31-
31+
3232
// Ensure we don't exceed the desired length
3333
if (result.Count + utf8Bytes.Length > outputBytes)
3434
break;
35-
35+
3636
result.AddRange(utf8Bytes);
3737
}
3838
return result.ToArray();
@@ -56,13 +56,13 @@ public byte[] Generate(int outputBytes, long seed)
5656
private uint GenerateCodePoint()
5757
{
5858
int byteCount = PickRandomByteCount();
59-
59+
6060
// Depending on the byte count, generate an appropriate UTF-8 sequence
6161
switch (byteCount)
6262
{
6363
// Each case follows UTF-8 encoding rules for 1-byte, 2-byte, 3-byte, and 4-byte sequences
6464
case 1: return (uint)gen.Next(0x00, 0x80); // 1-byte sequence
65-
case 2: return (uint)((gen.Next(0xC2, 0xDF) << 8) | (0x80 | gen.Next(0x00, 0x40)));
65+
case 2: return (uint)((gen.Next(0xC2, 0xDF) << 8) | (0x80 | gen.Next(0x00, 0x40)));
6666
case 3: return (uint)((gen.Next(0xE0, 0xEF) << 16) | ((0x80 | gen.Next(0x00, 0x40)) << 8) | (0x80 | gen.Next(0x00, 0x40)));
6767
case 4: return (uint)((gen.Next(0xF0, 0xF4) << 24) | ((0x80 | gen.Next(0x00, 0x40)) << 16) | ((0x80 | gen.Next(0x00, 0x40)) << 8) | (0x80 | gen.Next(0x00, 0x40)));
6868
default: throw new InvalidOperationException($"Invalid byte count: {byteCount}"); // Guard clause for invalid byte count
@@ -74,30 +74,30 @@ private int PickRandomByteCount()
7474
{
7575
double randomValue = gen.NextDouble() * probabilities.Sum();
7676
double cumulative = 0.0;
77-
77+
7878
// Check each cumulative probability until the random value is less than the cumulative sum
7979
for (int i = 0; i < maxByteLength; i++)
8080
{
8181
cumulative += probabilities[i];
8282
if (randomValue <= cumulative)
8383
return i + 1; // Return the byte count
8484
}
85-
85+
8686
return maxByteLength; // Default to max byte length
8787
}
8888

8989
// Convert the generated code point into a valid UTF-8 sequence
9090
private byte[] EncodeToUTF8(uint codePoint)
9191
{
9292
var result = new List<byte>();
93-
93+
9494
// Break the code point into its constituent bytes
9595
while (codePoint != 0)
9696
{
9797
result.Add((byte)(codePoint & 0xFF));
9898
codePoint >>= 8;
9999
}
100-
100+
101101
result.Reverse(); // Reverse to get the bytes in the correct order
102102
return result.ToArray();
103103
}

0 commit comments

Comments
 (0)