Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions csharp/Platform.Data/LinkAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ public TLinkAddress this[int index]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (index == 0)
{
return Index;
}
else
if (index != 0)
{
throw new IndexOutOfRangeException();
}
return Index;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => throw new NotSupportedException();
Expand Down
7 changes: 2 additions & 5 deletions csharp/Platform.Data/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ public TLinkAddress this[int index]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (index < Size)
{
return Index;
}
else
if (index < 0 || index >= Size)
{
throw new IndexOutOfRangeException();
}
return Index;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => throw new NotSupportedException();
Expand Down
101 changes: 101 additions & 0 deletions examples/experiments/IndexerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using Platform.Data;

namespace Platform.Data.Tests
{
public class IndexerTest
{
public static void Main()
{
Console.WriteLine("Testing Point<ulong> indexer...");
var point = new Point<ulong>(42UL, 3);

// Test valid indices
try
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine($"point[{i}] = {point[i]}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error with valid indices: {ex.Message}");
}

// Test negative index (should throw)
try
{
var result = point[-1];
Console.WriteLine($"ERROR: Negative index should have thrown exception, but got: {result}");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("✓ Negative index correctly throws IndexOutOfRangeException");
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: Unexpected exception type: {ex.GetType().Name}: {ex.Message}");
}

// Test out-of-bounds index (should throw)
try
{
var result = point[3];
Console.WriteLine($"ERROR: Out-of-bounds index should have thrown exception, but got: {result}");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("✓ Out-of-bounds index correctly throws IndexOutOfRangeException");
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: Unexpected exception type: {ex.GetType().Name}: {ex.Message}");
}

Console.WriteLine();
Console.WriteLine("Testing LinkAddress<ulong> indexer...");
var linkAddress = new LinkAddress<ulong>(123UL);

// Test valid index (0)
try
{
Console.WriteLine($"linkAddress[0] = {linkAddress[0]}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error with valid index 0: {ex.Message}");
}

// Test negative index (should throw)
try
{
var result = linkAddress[-1];
Console.WriteLine($"ERROR: Negative index should have thrown exception, but got: {result}");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("✓ Negative index correctly throws IndexOutOfRangeException");
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: Unexpected exception type: {ex.GetType().Name}: {ex.Message}");
}

// Test positive index other than 0 (should throw)
try
{
var result = linkAddress[1];
Console.WriteLine($"ERROR: Index 1 should have thrown exception, but got: {result}");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("✓ Index 1 correctly throws IndexOutOfRangeException");
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: Unexpected exception type: {ex.GetType().Name}: {ex.Message}");
}
}
}
}
11 changes: 11 additions & 0 deletions examples/experiments/IndexerTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../csharp/Platform.Data/Platform.Data.csproj" />
</ItemGroup>
</Project>
Loading