diff --git a/csharp/Platform.Collections/Trees/Node.cs b/csharp/Platform.Collections/Trees/Node.cs index 51eba40d..3570b552 100644 --- a/csharp/Platform.Collections/Trees/Node.cs +++ b/csharp/Platform.Collections/Trees/Node.cs @@ -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; diff --git a/experiments/TestCurrentBehavior.cs b/experiments/TestCurrentBehavior.cs new file mode 100644 index 00000000..79a9f242 --- /dev/null +++ b/experiments/TestCurrentBehavior.cs @@ -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")); + } + } +} \ No newline at end of file diff --git a/experiments/TestCurrentBehavior.csproj b/experiments/TestCurrentBehavior.csproj new file mode 100644 index 00000000..989fa3a2 --- /dev/null +++ b/experiments/TestCurrentBehavior.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8 + latest + enable + + + + + + + \ No newline at end of file diff --git a/experiments/TestFixedBehavior.cs b/experiments/TestFixedBehavior.cs new file mode 100644 index 00000000..38c55399 --- /dev/null +++ b/experiments/TestFixedBehavior.cs @@ -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)"); + } + } +} \ No newline at end of file diff --git a/experiments/TestFixedBehavior.csproj b/experiments/TestFixedBehavior.csproj new file mode 100644 index 00000000..989fa3a2 --- /dev/null +++ b/experiments/TestFixedBehavior.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8 + latest + enable + + + + + + + \ No newline at end of file diff --git a/test_fixed/TestFixedBehavior.cs b/test_fixed/TestFixedBehavior.cs new file mode 100644 index 00000000..38c55399 --- /dev/null +++ b/test_fixed/TestFixedBehavior.cs @@ -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)"); + } + } +} \ No newline at end of file diff --git a/test_fixed/TestFixedBehavior.csproj b/test_fixed/TestFixedBehavior.csproj new file mode 100644 index 00000000..989fa3a2 --- /dev/null +++ b/test_fixed/TestFixedBehavior.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8 + latest + enable + + + + + + + \ No newline at end of file