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
2 changes: 1 addition & 1 deletion csharp/Platform.Collections/Trees/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Node SetChildValue(object value, params object[] keys)
var node = this;
for (var i = 0; i < keys.Length; i++)
{
node = SetChildValue(value, keys[i]);
node = node[keys[i]];
}
node.Value = value;
return node;
Expand Down
38 changes: 38 additions & 0 deletions experiments/TestCurrentBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Platform.Collections.Trees;

namespace Experiments
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Testing current SetChildValue behavior...");

var root = new Node();

// Test setting value with multiple keys
root.SetChildValue("FinalValue", "key1", "key2", "key3");

// Check values at each level
Console.WriteLine($"Root value: {root.Value}");
Console.WriteLine($"Level 1 (key1) value: {root.GetChildValue("key1")}");
Console.WriteLine($"Level 2 (key1->key2) value: {root.GetChildValue("key1", "key2")}");
Console.WriteLine($"Level 3 (key1->key2->key3) value: {root.GetChildValue("key1", "key2", "key3")}");

Console.WriteLine();
Console.WriteLine("What we EXPECT:");
Console.WriteLine("Root value: null");
Console.WriteLine("Level 1 (key1) value: null");
Console.WriteLine("Level 2 (key1->key2) value: null");
Console.WriteLine("Level 3 (key1->key2->key3) value: FinalValue");

Console.WriteLine();
Console.WriteLine("What we ACTUALLY GET:");
Console.WriteLine("Root value: " + (root.Value ?? "null"));
Console.WriteLine("Level 1 (key1) value: " + (root.GetChildValue("key1") ?? "null"));
Console.WriteLine("Level 2 (key1->key2) value: " + (root.GetChildValue("key1", "key2") ?? "null"));
Console.WriteLine("Level 3 (key1->key2->key3) value: " + (root.GetChildValue("key1", "key2", "key3") ?? "null"));
}
}
}
14 changes: 14 additions & 0 deletions experiments/TestCurrentBehavior.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\csharp\Platform.Collections\Platform.Collections.csproj" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions experiments/TestFixedBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Platform.Collections.Trees;

namespace Experiments
{
class FixedBehaviorTest
{
static void Main(string[] args)
{
Console.WriteLine("Testing FIXED SetChildValue behavior...");

var root = new Node();

// Test setting value with multiple keys
root.SetChildValue("FinalValue", "key1", "key2", "key3");

// Check values at each level
Console.WriteLine($"Root value: {root.Value ?? "null"}");
Console.WriteLine($"Level 1 (key1) value: {root.GetChildValue("key1") ?? "null"}");
Console.WriteLine($"Level 2 (key1->key2) value: {root.GetChildValue("key1", "key2") ?? "null"}");
Console.WriteLine($"Level 3 (key1->key2->key3) value: {root.GetChildValue("key1", "key2", "key3") ?? "null"}");

Console.WriteLine();
Console.WriteLine("EXPECTED vs ACTUAL:");
Console.WriteLine($"Root value: null -> {root.Value ?? "null"} {(root.Value == null ? "✓" : "✗")}");
Console.WriteLine($"Level 1 (key1) value: null -> {root.GetChildValue("key1") ?? "null"} {(root.GetChildValue("key1") == null ? "✓" : "✗")}");
Console.WriteLine($"Level 2 (key1->key2) value: null -> {root.GetChildValue("key1", "key2") ?? "null"} {(root.GetChildValue("key1", "key2") == null ? "✓" : "✗")}");
Console.WriteLine($"Level 3 (key1->key2->key3) value: FinalValue -> {root.GetChildValue("key1", "key2", "key3") ?? "null"} {(root.GetChildValue("key1", "key2", "key3")?.ToString() == "FinalValue" ? "✓" : "✗")}");

Console.WriteLine();
Console.WriteLine("Additional test - setting different values at different paths:");
root.SetChildValue("Value1", "a");
root.SetChildValue("Value2", "a", "b");
root.SetChildValue("Value3", "x", "y", "z");

Console.WriteLine($"Path 'a' value: {root.GetChildValue("a") ?? "null"} (expected: Value1)");
Console.WriteLine($"Path 'a' -> 'b' value: {root.GetChildValue("a", "b") ?? "null"} (expected: Value2)");
Console.WriteLine($"Path 'x' -> 'y' -> 'z' value: {root.GetChildValue("x", "y", "z") ?? "null"} (expected: Value3)");
Console.WriteLine($"Path 'x' value: {root.GetChildValue("x") ?? "null"} (expected: null)");
Console.WriteLine($"Path 'x' -> 'y' value: {root.GetChildValue("x", "y") ?? "null"} (expected: null)");
}
}
}
14 changes: 14 additions & 0 deletions experiments/TestFixedBehavior.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\csharp\Platform.Collections\Platform.Collections.csproj" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions test_fixed/TestFixedBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Platform.Collections.Trees;

namespace Experiments
{
class FixedBehaviorTest
{
static void Main(string[] args)
{
Console.WriteLine("Testing FIXED SetChildValue behavior...");

var root = new Node();

// Test setting value with multiple keys
root.SetChildValue("FinalValue", "key1", "key2", "key3");

// Check values at each level
Console.WriteLine($"Root value: {root.Value ?? "null"}");
Console.WriteLine($"Level 1 (key1) value: {root.GetChildValue("key1") ?? "null"}");
Console.WriteLine($"Level 2 (key1->key2) value: {root.GetChildValue("key1", "key2") ?? "null"}");
Console.WriteLine($"Level 3 (key1->key2->key3) value: {root.GetChildValue("key1", "key2", "key3") ?? "null"}");

Console.WriteLine();
Console.WriteLine("EXPECTED vs ACTUAL:");
Console.WriteLine($"Root value: null -> {root.Value ?? "null"} {(root.Value == null ? "✓" : "✗")}");
Console.WriteLine($"Level 1 (key1) value: null -> {root.GetChildValue("key1") ?? "null"} {(root.GetChildValue("key1") == null ? "✓" : "✗")}");
Console.WriteLine($"Level 2 (key1->key2) value: null -> {root.GetChildValue("key1", "key2") ?? "null"} {(root.GetChildValue("key1", "key2") == null ? "✓" : "✗")}");
Console.WriteLine($"Level 3 (key1->key2->key3) value: FinalValue -> {root.GetChildValue("key1", "key2", "key3") ?? "null"} {(root.GetChildValue("key1", "key2", "key3")?.ToString() == "FinalValue" ? "✓" : "✗")}");

Console.WriteLine();
Console.WriteLine("Additional test - setting different values at different paths:");
root.SetChildValue("Value1", "a");
root.SetChildValue("Value2", "a", "b");
root.SetChildValue("Value3", "x", "y", "z");

Console.WriteLine($"Path 'a' value: {root.GetChildValue("a") ?? "null"} (expected: Value1)");
Console.WriteLine($"Path 'a' -> 'b' value: {root.GetChildValue("a", "b") ?? "null"} (expected: Value2)");
Console.WriteLine($"Path 'x' -> 'y' -> 'z' value: {root.GetChildValue("x", "y", "z") ?? "null"} (expected: Value3)");
Console.WriteLine($"Path 'x' value: {root.GetChildValue("x") ?? "null"} (expected: null)");
Console.WriteLine($"Path 'x' -> 'y' value: {root.GetChildValue("x", "y") ?? "null"} (expected: null)");
}
}
}
14 changes: 14 additions & 0 deletions test_fixed/TestFixedBehavior.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\csharp\Platform.Collections\Platform.Collections.csproj" />
</ItemGroup>

</Project>
Loading