From dcf36e50cb58b8108f644d146f859c065190f84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Sat, 6 May 2023 21:41:56 -0400 Subject: [PATCH 1/7] BST encapsulated version --- .../binary-search-tree/.meta/Example.cs | 96 +++++++--------- .../binary-search-tree/BinarySearchTree.cs | 53 +-------- .../BinarySearchTreeTests.cs | 104 ++++++++---------- 3 files changed, 85 insertions(+), 168 deletions(-) diff --git a/exercises/practice/binary-search-tree/.meta/Example.cs b/exercises/practice/binary-search-tree/.meta/Example.cs index a77fc35bf5..96428aaaae 100644 --- a/exercises/practice/binary-search-tree/.meta/Example.cs +++ b/exercises/practice/binary-search-tree/.meta/Example.cs @@ -1,79 +1,57 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -public class BinarySearchTree : IEnumerable +public class BinarySearchTree where T : IComparable { - public BinarySearchTree(int value) + class Node { - Value = value; + public T Value { get; set; } + public Node Left { get; set; } + public Node Right { get; set; } } - public BinarySearchTree(IEnumerable values) - { - var array = values.ToArray(); - - if (array.Length == 0) - { - throw new ArgumentException("Cannot create tree from empty list"); - } + Node head; + + public int Count { get; private set; } + public int Depth { get; private set; } - Value = array[0]; - - foreach (var value in array.Skip(1)) - { - Add(value); - } - } - - public int Value { get; } - - public BinarySearchTree Left { get; private set; } - - public BinarySearchTree Right { get; private set; } - - public BinarySearchTree Add(int value) + public void Add(T value) { - if (value <= Value) - { - Left = Add(value, Left); + Count++; + + var depth = 1; + + if (head == null) { + head = new Node { Value = value }; + Depth = 1; + return; } - else - { - Right = Add(value, Right); - } - - return this; - } - private static BinarySearchTree Add(int value, BinarySearchTree tree) - { - if (tree == null) + var node = head; + while(node.Value.CompareTo(value) != 0) { - return new BinarySearchTree(value); + depth++; + if (node.Value.CompareTo(value) < 0) + { + node.Left ??= new Node { Value = value }; + node = node.Left; + } else { + node.Right ??= new Node { Value = value }; + node = node.Right; + } } - - return tree.Add(value); + Depth = depth; } - public IEnumerator GetEnumerator() + public bool Contains(T value) { - foreach (var left in Left?.AsEnumerable() ?? Enumerable.Empty()) + var node = head; + while(node != null) { - yield return left; - } - - yield return Value; + if (node.Value.CompareTo(value) == 0) { return true; } - foreach (var right in Right?.AsEnumerable() ?? Enumerable.Empty()) - { - yield return right; + if (node.Value.CompareTo(value) < 0) { node = node.Left; } + else { node = node.Right; } } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); + return false; } } \ No newline at end of file diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index 02c277c40a..be48892178 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -1,53 +1,10 @@ using System; -using System.Collections; -using System.Collections.Generic; -public class BinarySearchTree : IEnumerable +public class BinarySearchTree where T : IComparable { - public BinarySearchTree(int value) - { - } + public int Count => throw new NotImplementedException("You need to implement this function."); + public int Depth => throw new NotImplementedException("You need to implement this function."); - public BinarySearchTree(IEnumerable values) - { - } - - public int Value - { - get - { - throw new NotImplementedException("You need to implement this function."); - } - } - - public BinarySearchTree Left - { - get - { - throw new NotImplementedException("You need to implement this function."); - } - } - - public BinarySearchTree Right - { - get - { - throw new NotImplementedException("You need to implement this function."); - } - } - - public BinarySearchTree Add(int value) - { - throw new NotImplementedException("You need to implement this function."); - } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException("You need to implement this function."); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException("You need to implement this function."); - } + public void Add(T value) => throw new NotImplementedException("You need to implement this function."); + public bool Contains(T value) => throw new NotImplementedException("You need to implement this function."); } \ No newline at end of file diff --git a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs index 4725c2a5c1..aaf8796f74 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs @@ -1,84 +1,66 @@ -using System.Linq; using Xunit; public class BinarySearchTreeTests { [Fact] - public void Data_is_retained() + public void New_bst_is_empty() { - var tree = new BinarySearchTree(4); - Assert.Equal(4, tree.Value); + var sut = new BinarySearchTree(); + Assert.Equal(0, sut.Count); } - [Fact(Skip = "Remove this Skip property to run this test")] - public void Smaller_number_at_left_node() - { - var tree = new BinarySearchTree(new[] { 4, 2 }); - Assert.Equal(4, tree.Value); - Assert.Equal(2, tree.Left.Value); - } - - [Fact(Skip = "Remove this Skip property to run this test")] - public void Same_number_at_left_node() - { - var tree = new BinarySearchTree(new[] { 4, 4 }); - Assert.Equal(4, tree.Value); - Assert.Equal(4, tree.Left.Value); - } - - [Fact(Skip = "Remove this Skip property to run this test")] - public void Greater_number_at_right_node() - { - var tree = new BinarySearchTree(new[] { 4, 5 }); - Assert.Equal(4, tree.Value); - Assert.Equal(5, tree.Right.Value); - } - - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_create_complex_tree() - { - var tree = new BinarySearchTree(new[] { 4, 2, 6, 1, 3, 5, 7 }); - Assert.Equal(4, tree.Value); - Assert.Equal(2, tree.Left.Value); - Assert.Equal(1, tree.Left.Left.Value); - Assert.Equal(3, tree.Left.Right.Value); - Assert.Equal(6, tree.Right.Value); - Assert.Equal(5, tree.Right.Left.Value); - Assert.Equal(7, tree.Right.Right.Value); - } - - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_sort_single_number() + [Fact] + public void New_bst_has_no_depth() { - var tree = new BinarySearchTree(2); - Assert.Equal(new[] { 2 }, tree.AsEnumerable()); + var sut = new BinarySearchTree(); + Assert.Equal(0, sut.Depth); } - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_sort_if_second_number_is_smaller_than_first() + [Fact] + public void Single_value_results_in_depth_one() { - var tree = new BinarySearchTree(new[] { 2, 1 }); - Assert.Equal(new[] { 1, 2 }, tree.AsEnumerable()); + var sut = new BinarySearchTree(); + sut.Add(1); + Assert.Equal(1, sut.Depth); } - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_sort_if_second_number_is_same_as_first() + [Fact] + public void Single_value_can_be_found() { - var tree = new BinarySearchTree(new[] { 2, 2 }); - Assert.Equal(new[] { 2, 2 }, tree.AsEnumerable()); + var sut = new BinarySearchTree(); + sut.Add(2); + Assert.True(sut.Contains(2)); } - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_sort_if_second_number_is_greater_than_first() + [Fact] + public void Balanced_three_is_well_behaved() { - var tree = new BinarySearchTree(new[] { 2, 3 }); - Assert.Equal(new[] { 2, 3 }, tree.AsEnumerable()); + var sut = new BinarySearchTree(); + sut.Add(5); + sut.Add(3); + sut.Add(7); + Assert.Equal(3, sut.Count); + Assert.Equal(2, sut.Depth); + Assert.True(sut.Contains(3)); + Assert.True(sut.Contains(5)); + Assert.True(sut.Contains(7)); + Assert.False(sut.Contains(4)); + Assert.False(sut.Contains(6)); } - [Fact(Skip = "Remove this Skip property to run this test")] - public void Can_sort_complex_tree() + [Fact] + public void Left_heavy_five_is_well_behaved() { - var tree = new BinarySearchTree(new[] { 2, 1, 3, 6, 7, 5 }); - Assert.Equal(new[] { 1, 2, 3, 5, 6, 7 }, tree.AsEnumerable()); + var sut = new BinarySearchTree(); + sut.Add(5); + sut.Add(3); + sut.Add(2); + sut.Add(5); + sut.Add(1); + Assert.Equal(5, sut.Count); + Assert.Equal(4, sut.Depth); + Assert.True(sut.Contains(1)); + Assert.True(sut.Contains(2)); + Assert.False(sut.Contains(8)); } } \ No newline at end of file From 4fb721256f15424f54c4afe4da13cf6bfa19cf96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Tue, 9 May 2023 08:40:44 -0400 Subject: [PATCH 2/7] adding myself to the contributor's list --- exercises/practice/binary-search-tree/.meta/config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/practice/binary-search-tree/.meta/config.json b/exercises/practice/binary-search-tree/.meta/config.json index e2cb6083e1..ebab4e31f6 100644 --- a/exercises/practice/binary-search-tree/.meta/config.json +++ b/exercises/practice/binary-search-tree/.meta/config.json @@ -7,7 +7,8 @@ "j2jensen", "robkeim", "ShamilS", - "wolf99" + "wolf99", + "michalporeba" ], "files": { "solution": [ From 4a0c7a33c4472e549bf99ddf7ce42997ff4a8459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Tue, 9 Jan 2024 10:43:15 +0000 Subject: [PATCH 3/7] Update exercises/practice/binary-search-tree/BinarySearchTree.cs Co-authored-by: Erik Schierboom --- exercises/practice/binary-search-tree/BinarySearchTree.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index be48892178..0f8a363df1 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -2,8 +2,8 @@ public class BinarySearchTree where T : IComparable { - public int Count => throw new NotImplementedException("You need to implement this function."); - public int Depth => throw new NotImplementedException("You need to implement this function."); + public int Count => throw new NotImplementedException("You need to implement this property."); + public int Depth => throw new NotImplementedException("You need to implement this property."); public void Add(T value) => throw new NotImplementedException("You need to implement this function."); public bool Contains(T value) => throw new NotImplementedException("You need to implement this function."); From d16a2b8451449a2a7396f5eac3f301a6711006bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Tue, 9 Jan 2024 10:43:54 +0000 Subject: [PATCH 4/7] Update exercises/practice/binary-search-tree/BinarySearchTree.cs Co-authored-by: Erik Schierboom --- exercises/practice/binary-search-tree/BinarySearchTree.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index 0f8a363df1..1aa2167740 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -5,6 +5,6 @@ public class BinarySearchTree where T : IComparable public int Count => throw new NotImplementedException("You need to implement this property."); public int Depth => throw new NotImplementedException("You need to implement this property."); - public void Add(T value) => throw new NotImplementedException("You need to implement this function."); - public bool Contains(T value) => throw new NotImplementedException("You need to implement this function."); + public void Add(T value) => throw new NotImplementedException("You need to implement this method."); + public bool Contains(T value) => throw new NotImplementedException("You need to implement this method."); } \ No newline at end of file From 4f81127133ed38df5538dcdfac8f16acae302d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Fri, 26 Jan 2024 23:11:58 +0000 Subject: [PATCH 5/7] standard tests through serialisation --- .../binary-search-tree/.meta/Example.cs | 82 ++++++-- .../binary-search-tree/BinarySearchTree.cs | 2 + .../BinarySearchTreeTests.cs | 179 +++++++++++++++--- 3 files changed, 227 insertions(+), 36 deletions(-) diff --git a/exercises/practice/binary-search-tree/.meta/Example.cs b/exercises/practice/binary-search-tree/.meta/Example.cs index 96428aaaae..eab267ea5a 100644 --- a/exercises/practice/binary-search-tree/.meta/Example.cs +++ b/exercises/practice/binary-search-tree/.meta/Example.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Newtonsoft.Json; public class BinarySearchTree where T : IComparable { @@ -7,45 +9,79 @@ class Node public T Value { get; set; } public Node Left { get; set; } public Node Right { get; set; } + + public static object ToData(Node node) + { + if (node == null) return null; + + return new + { + data = node.Value, + left = Node.ToData(node.Left), + right = Node.ToData(node.Right) + }; + } + + public IEnumerable GetOrderedValues() + { + if (Left != null) + { + foreach(var value in Left.GetOrderedValues()) + { + yield return value; + } + } + yield return Value; + if (Right != null) + { + foreach(var value in Right.GetOrderedValues()) + { + yield return value; + } + } + } } Node head; - + public int Count { get; private set; } - public int Depth { get; private set; } public void Add(T value) { Count++; - var depth = 1; - if (head == null) { head = new Node { Value = value }; - Depth = 1; return; } var node = head; - while(node.Value.CompareTo(value) != 0) + + while(true) { - depth++; - if (node.Value.CompareTo(value) < 0) + if (node.Value.CompareTo(value) >= 0) { - node.Left ??= new Node { Value = value }; + if (node.Left == null) + { + node.Left = new Node { Value = value }; + break; + } node = node.Left; - } else { - node.Right ??= new Node { Value = value }; + } else { + if (node.Right == null) + { + node.Right = new Node { Value = value }; + break; + } node = node.Right; } } - Depth = depth; } public bool Contains(T value) { var node = head; - while(node != null) + while(node != null) { if (node.Value.CompareTo(value) == 0) { return true; } @@ -54,4 +90,24 @@ public bool Contains(T value) } return false; } + + public string ToJson() + { + if (head == null) return null; + + var settings = new JsonSerializerSettings + { + Formatting = Formatting.Indented, + }; + + var data = Node.ToData(head); + + return JsonConvert.SerializeObject(data, settings); + } + + public IEnumerable GetOrderedValues() + { + if (head == null) return new T[0]; + return head.GetOrderedValues(); + } } \ No newline at end of file diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index 1aa2167740..d485c68dfd 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Newtonsoft.Json; public class BinarySearchTree where T : IComparable { diff --git a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs index aaf8796f74..0c68f06b24 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs @@ -1,4 +1,5 @@ using Xunit; +using System.Text.RegularExpressions; public class BinarySearchTreeTests { @@ -10,57 +11,189 @@ public void New_bst_is_empty() } [Fact] - public void New_bst_has_no_depth() + public void New_bst_can_be_serialized_to_json() { var sut = new BinarySearchTree(); - Assert.Equal(0, sut.Depth); + Assert.Null(sut.ToJson()); } [Fact] - public void Single_value_results_in_depth_one() + public void Single_value_can_be_found() { var sut = new BinarySearchTree(); - sut.Add(1); - Assert.Equal(1, sut.Depth); + sut.Add(4); + Assert.False(sut.Contains(1)); + Assert.True(sut.Contains(4)); } [Fact] - public void Single_value_can_be_found() + public void Single_value_can_be_serialized() + { + var sut = new BinarySearchTree(); + sut.Add(4); + var expected = """ + { + "data": 4, + "left": null, + "right": null + } + """; + Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); + } + + [Fact] + public void Insert_data_at_proper_node_42() { var sut = new BinarySearchTree(); + sut.Add(4); sut.Add(2); - Assert.True(sut.Contains(2)); + var expected = """ + { + "data": 4, + "left": { + "data": 2, + "left": null, + "right": null + }, + "right": null + } + """; + Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } [Fact] - public void Balanced_three_is_well_behaved() + public void Insert_data_at_proper_node_44() { var sut = new BinarySearchTree(); + sut.Add(4); + sut.Add(4); + var expected = """ + { + "data": 4, + "left": { + "data": 4, + "left": null, + "right": null + }, + "right": null + } + """; + Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); + } + + [Fact] + public void Insert_data_at_proper_node_45() + { + var sut = new BinarySearchTree(); + sut.Add(4); sut.Add(5); + var expected = """ + { + "data": 4, + "left": null, + "right": { + "data": 5, + "left": null, + "right": null + } + } + """; + Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); + } + + [Fact] + public void Insert_data_at_proper_node_4261357() + { + var sut = new BinarySearchTree(); + sut.Add(4); + sut.Add(2); + sut.Add(6); + sut.Add(1); sut.Add(3); + sut.Add(5); sut.Add(7); - Assert.Equal(3, sut.Count); - Assert.Equal(2, sut.Depth); - Assert.True(sut.Contains(3)); - Assert.True(sut.Contains(5)); - Assert.True(sut.Contains(7)); - Assert.False(sut.Contains(4)); - Assert.False(sut.Contains(6)); + var expected = """ + { + "data": 4, + "left": { + "data": 2, + "left": { + "data": 1, + "left": null, + "right": null + }, + "right": { + "data": 3, + "left": null, + "right": null + } + }, + "right": { + "data": 6, + "left": { + "data": 5, + "left": null, + "right": null + }, + "right": { + "data": 7, + "left": null, + "right": null + } + } + } + """; + Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } [Fact] - public void Left_heavy_five_is_well_behaved() + public void Can_sort_a_single_number() { var sut = new BinarySearchTree(); - sut.Add(5); + sut.Add(2); + Assert.Equal(new int[] {2}, sut.GetOrderedValues()); + } + + [Fact] + public void Can_sort_if_second_number_is_smaller_than_first() + { + var sut = new BinarySearchTree(); + sut.Add(2); + sut.Add(1); + Assert.Equal(new int[] {1, 2}, sut.GetOrderedValues()); + } + + [Fact] + public void Can_sort_if_second_number_is_same_as_first() + { + var sut = new BinarySearchTree(); + sut.Add(2); + sut.Add(2); + Assert.Equal(new int[] {2, 2}, sut.GetOrderedValues()); + } + + [Fact] + public void Can_sort_if_second_number_is_greater_than_first() + { + var sut = new BinarySearchTree(); + sut.Add(2); sut.Add(3); + Assert.Equal(new int[] {2, 3}, sut.GetOrderedValues()); + } + + [Fact] + public void Can_sort_complex_tree() + { + var sut = new BinarySearchTree(); sut.Add(2); - sut.Add(5); sut.Add(1); - Assert.Equal(5, sut.Count); - Assert.Equal(4, sut.Depth); - Assert.True(sut.Contains(1)); - Assert.True(sut.Contains(2)); - Assert.False(sut.Contains(8)); + sut.Add(3); + sut.Add(6); + sut.Add(7); + sut.Add(5); + Assert.Equal(new int[] {1, 2, 3, 5, 6, 7}, sut.GetOrderedValues()); } + + private static string WithoutSpaces(string text) + => Regex.Replace(text, @"\s+", ""); } \ No newline at end of file From 1df3bd46e6f364e3bd57d05fdb0cb77a195f0b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Fri, 26 Jan 2024 23:17:11 +0000 Subject: [PATCH 6/7] skip all but the first tests --- .../binary-search-tree/BinarySearchTree.cs | 20 ++++++++++++---- .../BinarySearchTreeTests.cs | 24 +++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index d485c68dfd..4ddb420e43 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -4,9 +4,21 @@ public class BinarySearchTree where T : IComparable { - public int Count => throw new NotImplementedException("You need to implement this property."); - public int Depth => throw new NotImplementedException("You need to implement this property."); + public int Count + => throw new NotImplementedException("You need to implement this property."); - public void Add(T value) => throw new NotImplementedException("You need to implement this method."); - public bool Contains(T value) => throw new NotImplementedException("You need to implement this method."); + public int Depth + => throw new NotImplementedException("You need to implement this property."); + + public void Add(T value) + => throw new NotImplementedException("You need to implement this method."); + + public bool Contains(T value) + => throw new NotImplementedException("You need to implement this method."); + + public string ToJson() + => throw new NotImplementedException("You need to implement this property."); + + public IEnumerable GetOrderedValues() + => throw new NotImplementedException("You need to implement this propertly."); } \ No newline at end of file diff --git a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs index 0c68f06b24..7c7768c5fd 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs @@ -10,14 +10,14 @@ public void New_bst_is_empty() Assert.Equal(0, sut.Count); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void New_bst_can_be_serialized_to_json() { var sut = new BinarySearchTree(); Assert.Null(sut.ToJson()); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Single_value_can_be_found() { var sut = new BinarySearchTree(); @@ -26,7 +26,7 @@ public void Single_value_can_be_found() Assert.True(sut.Contains(4)); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Single_value_can_be_serialized() { var sut = new BinarySearchTree(); @@ -41,7 +41,7 @@ public void Single_value_can_be_serialized() Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Insert_data_at_proper_node_42() { var sut = new BinarySearchTree(); @@ -61,7 +61,7 @@ public void Insert_data_at_proper_node_42() Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Insert_data_at_proper_node_44() { var sut = new BinarySearchTree(); @@ -81,7 +81,7 @@ public void Insert_data_at_proper_node_44() Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Insert_data_at_proper_node_45() { var sut = new BinarySearchTree(); @@ -101,7 +101,7 @@ public void Insert_data_at_proper_node_45() Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Insert_data_at_proper_node_4261357() { var sut = new BinarySearchTree(); @@ -146,7 +146,7 @@ public void Insert_data_at_proper_node_4261357() Assert.Equal(WithoutSpaces(expected), WithoutSpaces(sut.ToJson())); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Can_sort_a_single_number() { var sut = new BinarySearchTree(); @@ -154,7 +154,7 @@ public void Can_sort_a_single_number() Assert.Equal(new int[] {2}, sut.GetOrderedValues()); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Can_sort_if_second_number_is_smaller_than_first() { var sut = new BinarySearchTree(); @@ -163,7 +163,7 @@ public void Can_sort_if_second_number_is_smaller_than_first() Assert.Equal(new int[] {1, 2}, sut.GetOrderedValues()); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Can_sort_if_second_number_is_same_as_first() { var sut = new BinarySearchTree(); @@ -172,7 +172,7 @@ public void Can_sort_if_second_number_is_same_as_first() Assert.Equal(new int[] {2, 2}, sut.GetOrderedValues()); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Can_sort_if_second_number_is_greater_than_first() { var sut = new BinarySearchTree(); @@ -181,7 +181,7 @@ public void Can_sort_if_second_number_is_greater_than_first() Assert.Equal(new int[] {2, 3}, sut.GetOrderedValues()); } - [Fact] + [Fact(Skip = "Remove this Skip property to run this test")] public void Can_sort_complex_tree() { var sut = new BinarySearchTree(); From a8fd85846636f906ae794b2eb7f229f7e1d74436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Por=C4=99ba?= Date: Fri, 26 Jan 2024 23:20:45 +0000 Subject: [PATCH 7/7] the new standard not implemented messages --- .../binary-search-tree/BinarySearchTree.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index 4ddb420e43..074f506e25 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -5,20 +5,17 @@ public class BinarySearchTree where T : IComparable { public int Count - => throw new NotImplementedException("You need to implement this property."); - - public int Depth - => throw new NotImplementedException("You need to implement this property."); + => throw new NotImplementedException("Please implement the Count property of the BinarySearchTree class."); public void Add(T value) - => throw new NotImplementedException("You need to implement this method."); + => throw new NotImplementedException("Please implement the Add(T) method of the BinarySearchTree class."); public bool Contains(T value) - => throw new NotImplementedException("You need to implement this method."); + => throw new NotImplementedException("Please implement the Contains(T) method of the BinarySearchTree class."); public string ToJson() - => throw new NotImplementedException("You need to implement this property."); + => throw new NotImplementedException("Please implement the ToJson() method of the BinarySearchTree class."); - public IEnumerable GetOrderedValues() - => throw new NotImplementedException("You need to implement this propertly."); + public IEnumerable GetOrderedValues() + => throw new NotImplementedException("Please implement the GetOrderedValues() method of the BinarySearchTree class."); } \ No newline at end of file