From 6698b048e7269b96e970cb5827508fa304d5ded9 Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Sat, 13 Sep 2025 17:54:13 +0300 Subject: [PATCH 1/9] init project --- HW1/HW1.sln | 22 ++++++++++++++++++ HW1/Trie.Tests/Trie.Tests.csproj | 39 ++++++++++++++++++++++++++++++++ HW1/Trie.Tests/TrieTests.cs | 19 ++++++++++++++++ HW1/Trie.Tests/stylecop.json | 9 ++++++++ HW1/Trie/Program.cs | 5 ++++ HW1/Trie/Trie.cs | 13 +++++++++++ HW1/Trie/Trie.csproj | 21 +++++++++++++++++ HW1/Trie/stylecop.json | 9 ++++++++ 8 files changed, 137 insertions(+) create mode 100644 HW1/HW1.sln create mode 100644 HW1/Trie.Tests/Trie.Tests.csproj create mode 100644 HW1/Trie.Tests/TrieTests.cs create mode 100644 HW1/Trie.Tests/stylecop.json create mode 100644 HW1/Trie/Program.cs create mode 100644 HW1/Trie/Trie.cs create mode 100644 HW1/Trie/Trie.csproj create mode 100644 HW1/Trie/stylecop.json diff --git a/HW1/HW1.sln b/HW1/HW1.sln new file mode 100644 index 0000000..1dd2d42 --- /dev/null +++ b/HW1/HW1.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie", "Trie\Trie.csproj", "{A87E7018-FB5B-47AB-8323-213DC3A49658}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie.Tests", "Trie.Tests\Trie.Tests.csproj", "{A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A87E7018-FB5B-47AB-8323-213DC3A49658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A87E7018-FB5B-47AB-8323-213DC3A49658}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A87E7018-FB5B-47AB-8323-213DC3A49658}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A87E7018-FB5B-47AB-8323-213DC3A49658}.Release|Any CPU.Build.0 = Release|Any CPU + {A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/HW1/Trie.Tests/Trie.Tests.csproj b/HW1/Trie.Tests/Trie.Tests.csproj new file mode 100644 index 0000000..7f821eb --- /dev/null +++ b/HW1/Trie.Tests/Trie.Tests.csproj @@ -0,0 +1,39 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/HW1/Trie.Tests/TrieTests.cs b/HW1/Trie.Tests/TrieTests.cs new file mode 100644 index 0000000..a5808b1 --- /dev/null +++ b/HW1/Trie.Tests/TrieTests.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) khusainovilas. All rights reserved. +// + +namespace Trie.Tests; + +public class Tests +{ + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + Assert.Pass(); + } +} \ No newline at end of file diff --git a/HW1/Trie.Tests/stylecop.json b/HW1/Trie.Tests/stylecop.json new file mode 100644 index 0000000..76c8e76 --- /dev/null +++ b/HW1/Trie.Tests/stylecop.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "khusainovilas", + "copyrightText": "Copyright (c) {companyName}. All rights reserved." + } + } +} \ No newline at end of file diff --git a/HW1/Trie/Program.cs b/HW1/Trie/Program.cs new file mode 100644 index 0000000..2e1f1c0 --- /dev/null +++ b/HW1/Trie/Program.cs @@ -0,0 +1,5 @@ +// +// Copyright (c) khusainovilas. All rights reserved. +// + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs new file mode 100644 index 0000000..22af5ae --- /dev/null +++ b/HW1/Trie/Trie.cs @@ -0,0 +1,13 @@ +// +// Copyright (c) khusainovilas. All rights reserved. +// + +namespace Trie; + +/// +/// realization of Trie. +/// +public class Trie +{ + +} \ No newline at end of file diff --git a/HW1/Trie/Trie.csproj b/HW1/Trie/Trie.csproj new file mode 100644 index 0000000..796d45e --- /dev/null +++ b/HW1/Trie/Trie.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/HW1/Trie/stylecop.json b/HW1/Trie/stylecop.json new file mode 100644 index 0000000..76c8e76 --- /dev/null +++ b/HW1/Trie/stylecop.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "khusainovilas", + "copyrightText": "Copyright (c) {companyName}. All rights reserved." + } + } +} \ No newline at end of file From b91d5be11b07887a97f77996bc5b30c36f379936 Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Sun, 14 Sep 2025 20:32:02 +0300 Subject: [PATCH 2/9] add core trie functionalities --- HW1/Trie/Program.cs | 5 -- HW1/Trie/Trie.cs | 154 ++++++++++++++++++++++++++++++++++++++++++- HW1/Trie/Trie.csproj | 2 +- 3 files changed, 153 insertions(+), 8 deletions(-) delete mode 100644 HW1/Trie/Program.cs diff --git a/HW1/Trie/Program.cs b/HW1/Trie/Program.cs deleted file mode 100644 index 2e1f1c0..0000000 --- a/HW1/Trie/Program.cs +++ /dev/null @@ -1,5 +0,0 @@ -// -// Copyright (c) khusainovilas. All rights reserved. -// - -Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs index 22af5ae..433604e 100644 --- a/HW1/Trie/Trie.cs +++ b/HW1/Trie/Trie.cs @@ -9,5 +9,155 @@ namespace Trie; /// public class Trie { - -} \ No newline at end of file + private class TrieNode + { + public readonly Dictionary Children = new(); + public bool IsEnd; + public int PrefixCount; + } + + private TrieNode node = new(); + + private int wordCount = 0; + + /// + /// Gets the number of words added to the tree. + /// + public int WordCount => this.wordCount; + + private readonly TrieNode root = new TrieNode(); + + /// + /// Add a new word into the trie. + /// + /// The word to be inserted. + /// Returns false if the word is already present. + public bool Add(string? word) + { + if (word is null || string.IsNullOrWhiteSpace(word)) + { + return false; + } + + var current = this.root; + + foreach (var letter in word) + { + if (!current.Children.TryGetValue(letter, out var value)) + { + value = new TrieNode(); + current.Children[letter] = value; + } + + current = value; + current.PrefixCount++; + } + + if (current.IsEnd) + { + return false; + } + + current.IsEnd = true; + this.wordCount++; + return true; + } + + /// + /// Determines whether the trie contains a specific word. + /// + /// The word to look for. + /// Returns true if the word exists in the trie. + public bool Contains(string? word) + { + if (word is null || string.IsNullOrWhiteSpace(word)) + { + return false; + } + + var current = this.root; + + foreach (var letter in word) + { + if (!current.Children.TryGetValue(letter, out var value)) + { + return false; + } + + current = value; + } + + return current.IsEnd; + } + + /// + /// Deletes a word from the trie. + /// + /// The word to delete. + /// Returns true if the word was present in the trie. + public bool Remove(string? word) + { + if (word is null || string.IsNullOrWhiteSpace(word)) + { + return false; + } + + var current = this.root; + var path = new Stack(); + + foreach (var letter in word) + { + if (!current.Children.TryGetValue(letter, out var value)) + { + return false; + } + + path.Push(current); + current = value; + } + + if (!current.IsEnd) + { + return false; + } + + current.IsEnd = false; + this.wordCount--; + + foreach (var trieNode in path) + { + trieNode.PrefixCount--; + } + + current.PrefixCount--; + + return true; + } + + /// + /// Returns the number of words in the trie that start with a given prefix. + /// + /// The prefix to search for. + /// The count of words that begin with the specified prefix. + public int HowManyStartsWithPrefix(string? prefix) + { + if (prefix is null || string.IsNullOrWhiteSpace(prefix)) + { + return this.wordCount; + } + + var current = this.root; + + foreach (var letter in prefix) + { + if (!current.Children.TryGetValue(letter, out var value)) + { + return 0; + } + + current = value; + } + + return current.PrefixCount; + } +} diff --git a/HW1/Trie/Trie.csproj b/HW1/Trie/Trie.csproj index 796d45e..82fd482 100644 --- a/HW1/Trie/Trie.csproj +++ b/HW1/Trie/Trie.csproj @@ -1,7 +1,7 @@  - Exe + Library net8.0 enable enable From e779336c3befea6ab3d43ca68464ed86ad50c2aa Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Sun, 14 Sep 2025 21:00:09 +0300 Subject: [PATCH 3/9] test for func add --- HW1/Trie.Tests/TrieTests.cs | 65 +++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/HW1/Trie.Tests/TrieTests.cs b/HW1/Trie.Tests/TrieTests.cs index a5808b1..56e0bbb 100644 --- a/HW1/Trie.Tests/TrieTests.cs +++ b/HW1/Trie.Tests/TrieTests.cs @@ -4,16 +4,75 @@ namespace Trie.Tests; -public class Tests +public class TrieTest { + private Trie trie; + + /// + /// Sets up the trie instance for every test. + /// [SetUp] public void Setup() { + this.trie = new Trie(); } + /// + /// Test that adding a new word returns true. + /// [Test] - public void Test1() + public void Trie_Add_NewWords_ReturnsTrue() { - Assert.Pass(); + var words = new List { "he", "his", "her", "hi" }; + + foreach (var word in words) + { + Assert.That(this.trie.Add(word), Is.True); + } + + Assert.That(this.trie.WordCount, Is.EqualTo(words.Count)); + } + + /// + /// Checks that re-adding an existing word returns false. + /// + [Test] + public void Trie_Add_ExistingWord_ShouldReturnFalse() + { + this.trie.Add("he"); + this.trie.Add("his"); + + Assert.Multiple(() => + { + Assert.That(this.trie.Add("he"), Is.False); + Assert.That(this.trie.Add("his"), Is.False); + }); + } + + /// + /// Checks that adding null, an empty string, or a string with spaces returns false. + /// + [Test] + public void Add_NullOrEmpty_ShouldReturnFalse() + { + Assert.Multiple(() => + { + Assert.That(this.trie.Add(null), Is.False); + Assert.That(this.trie.Add(string.Empty), Is.False); + Assert.That(this.trie.Add(" "), Is.False); + }); + } + + /// + /// Checks if WordCount is correct after adding new words. + /// + [Test] + public void Add_NewWords_ShouldUpdateWordCount() + { + this.trie.Add("he"); + this.trie.Add("his"); + this.trie.Add("her"); + + Assert.That(this.trie.WordCount, Is.EqualTo(3)); } } \ No newline at end of file From 5c7590025770658572474904816ada15a3f97e59 Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Mon, 15 Sep 2025 16:03:48 +0300 Subject: [PATCH 4/9] add NUnit tests for trie functionality --- HW1/HW1.sln | 2 +- .../Trie.Test.csproj} | 1 + HW1/Trie.Test/TrieTest.cs | 174 ++++++++++++++++++ HW1/{Trie.Tests => Trie.Test}/stylecop.json | 0 HW1/Trie.Tests/TrieTests.cs | 78 -------- HW1/Trie/Trie.cs | 10 +- 6 files changed, 180 insertions(+), 85 deletions(-) rename HW1/{Trie.Tests/Trie.Tests.csproj => Trie.Test/Trie.Test.csproj} (96%) create mode 100644 HW1/Trie.Test/TrieTest.cs rename HW1/{Trie.Tests => Trie.Test}/stylecop.json (100%) delete mode 100644 HW1/Trie.Tests/TrieTests.cs diff --git a/HW1/HW1.sln b/HW1/HW1.sln index 1dd2d42..291d9f0 100644 --- a/HW1/HW1.sln +++ b/HW1/HW1.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie", "Trie\Trie.csproj", "{A87E7018-FB5B-47AB-8323-213DC3A49658}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie.Tests", "Trie.Tests\Trie.Tests.csproj", "{A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trie.Test", "Trie.Test\Trie.Test.csproj", "{A2F4F365-7EDC-4ECD-9B8F-6D184B1F9CA3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/HW1/Trie.Tests/Trie.Tests.csproj b/HW1/Trie.Test/Trie.Test.csproj similarity index 96% rename from HW1/Trie.Tests/Trie.Tests.csproj rename to HW1/Trie.Test/Trie.Test.csproj index 7f821eb..c66f1a6 100644 --- a/HW1/Trie.Tests/Trie.Tests.csproj +++ b/HW1/Trie.Test/Trie.Test.csproj @@ -7,6 +7,7 @@ false true + Trie.Tests diff --git a/HW1/Trie.Test/TrieTest.cs b/HW1/Trie.Test/TrieTest.cs new file mode 100644 index 0000000..d13479e --- /dev/null +++ b/HW1/Trie.Test/TrieTest.cs @@ -0,0 +1,174 @@ +// +// Copyright (c) khusainovilas. All rights reserved. +// + +namespace Trie.Tests; + +/// +/// Unit tests for Trie data structure. +/// +public class TrieTest +{ + private Trie trie; + + /// + /// Initializes a new trie before each test. + /// + [SetUp] + public void Setup() + { + this.trie = new Trie(); + } + + /// + /// Tests Add method when inserting fresh words. + /// + [Test] + public void Trie_Add_NewWords_ShouldReturnTrue() + { + List words = ["apple", "app", "application"]; + + foreach (var word in words) + { + Assert.That(this.trie.Add(word), Is.True); + } + } + + /// + /// Tests WordCount after adding multiple words. + /// + [Test] + public void Trie_WordCount_AfterAddingSeveralWords() + { + List words = ["alpha", "beta", "gamma", "delta"]; + + foreach (var word in words) + { + this.trie.Add(word); + } + + Assert.That(this.trie.WordCount, Is.EqualTo(words.Count)); + } + + /// + /// Tests Add method when the same word is inserted twice. + /// + [Test] + public void Trie_Add_SameWordTwice_ShouldReturnFalse() + { + const string word = "matrix"; + + this.trie.Add(word); + + Assert.That(this.trie.Add(word), Is.False); + } + + /// + /// Tests Add method after removing a word. + /// + [Test] + public void Trie_Add_AfterRemovingWord_ShouldReturnTrue() + { + const string word = "sun"; + + this.trie.Add(word); + this.trie.Remove(word); + + Assert.That(this.trie.Add(word), Is.True); + } + + /// + /// Tests WordCount after removing words. + /// + [Test] + public void Trie_WordCount_AfterRemovingSomeWords() + { + List words = ["dog", "cat", "bird", "fish"]; + + foreach (var word in words) + { + this.trie.Add(word); + } + + this.trie.Remove("dog"); + this.trie.Remove("bird"); + + var expectedCount = words.Count - 2; + + Assert.That(this.trie.WordCount, Is.EqualTo(expectedCount)); + } + + /// + /// Tests WordCount of an empty trie. + /// + [Test] + public void Trie_WordCount_OfEmptyTrie_ShouldBeZero() + { + const int expected = 0; + + Assert.That(this.trie.WordCount, Is.EqualTo(expected)); + } + + /// + /// Tests Contains method after adding a word. + /// + [Test] + public void Trie_Contains_AfterAddingWord_ShouldReturnTrue() + { + const string word = "cloud"; + + this.trie.Add(word); + + Assert.That(this.trie.Contains(word), Is.True); + } + + /// + /// Tests Contains method with a word that was never added. + /// + [Test] + public void Trie_Contains_NonExistingWord_ShouldReturnFalse() + { + const string word = "universe"; + + Assert.That(this.trie.Contains(word), Is.False); + } + + /// + /// Tests Contains method after removing a word. + /// + [Test] + public void Trie_Contains_AfterRemovingWord_ShouldReturnFalse() + { + const string word = "planet"; + + this.trie.Add(word); + this.trie.Remove(word); + + Assert.That(this.trie.Contains(word), Is.False); + } + + /// + /// Tests Remove method with a word that exists. + /// + [Test] + public void Trie_Remove_ExistingWord_ShouldRemoveSuccessfully() + { + const string word = "river"; + + this.trie.Add(word); + this.trie.Remove(word); + + Assert.That(this.trie.Contains(word), Is.False); + } + + /// + /// Tests Remove method with a word that does not exist. + /// + [Test] + public void Trie_Remove_NonExistingWord_ShouldReturnFalse() + { + const string word = "mountain"; + + Assert.That(this.trie.Remove(word), Is.False); + } +} \ No newline at end of file diff --git a/HW1/Trie.Tests/stylecop.json b/HW1/Trie.Test/stylecop.json similarity index 100% rename from HW1/Trie.Tests/stylecop.json rename to HW1/Trie.Test/stylecop.json diff --git a/HW1/Trie.Tests/TrieTests.cs b/HW1/Trie.Tests/TrieTests.cs deleted file mode 100644 index 56e0bbb..0000000 --- a/HW1/Trie.Tests/TrieTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -// Copyright (c) khusainovilas. All rights reserved. -// - -namespace Trie.Tests; - -public class TrieTest -{ - private Trie trie; - - /// - /// Sets up the trie instance for every test. - /// - [SetUp] - public void Setup() - { - this.trie = new Trie(); - } - - /// - /// Test that adding a new word returns true. - /// - [Test] - public void Trie_Add_NewWords_ReturnsTrue() - { - var words = new List { "he", "his", "her", "hi" }; - - foreach (var word in words) - { - Assert.That(this.trie.Add(word), Is.True); - } - - Assert.That(this.trie.WordCount, Is.EqualTo(words.Count)); - } - - /// - /// Checks that re-adding an existing word returns false. - /// - [Test] - public void Trie_Add_ExistingWord_ShouldReturnFalse() - { - this.trie.Add("he"); - this.trie.Add("his"); - - Assert.Multiple(() => - { - Assert.That(this.trie.Add("he"), Is.False); - Assert.That(this.trie.Add("his"), Is.False); - }); - } - - /// - /// Checks that adding null, an empty string, or a string with spaces returns false. - /// - [Test] - public void Add_NullOrEmpty_ShouldReturnFalse() - { - Assert.Multiple(() => - { - Assert.That(this.trie.Add(null), Is.False); - Assert.That(this.trie.Add(string.Empty), Is.False); - Assert.That(this.trie.Add(" "), Is.False); - }); - } - - /// - /// Checks if WordCount is correct after adding new words. - /// - [Test] - public void Add_NewWords_ShouldUpdateWordCount() - { - this.trie.Add("he"); - this.trie.Add("his"); - this.trie.Add("her"); - - Assert.That(this.trie.WordCount, Is.EqualTo(3)); - } -} \ No newline at end of file diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs index 433604e..64b3ca4 100644 --- a/HW1/Trie/Trie.cs +++ b/HW1/Trie/Trie.cs @@ -18,12 +18,10 @@ private class TrieNode private TrieNode node = new(); - private int wordCount = 0; - /// /// Gets the number of words added to the tree. /// - public int WordCount => this.wordCount; + public int WordCount { get; private set; } private readonly TrieNode root = new TrieNode(); @@ -59,7 +57,7 @@ public bool Add(string? word) } current.IsEnd = true; - this.wordCount++; + this.WordCount++; return true; } @@ -122,7 +120,7 @@ public bool Remove(string? word) } current.IsEnd = false; - this.wordCount--; + this.WordCount--; foreach (var trieNode in path) { @@ -143,7 +141,7 @@ public int HowManyStartsWithPrefix(string? prefix) { if (prefix is null || string.IsNullOrWhiteSpace(prefix)) { - return this.wordCount; + return this.WordCount; } var current = this.root; From 538236555e869f08deb5369e929df1119efbd17a Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Mon, 15 Sep 2025 16:46:32 +0300 Subject: [PATCH 5/9] refactor apply stylecop rules --- HW1/Trie/Trie.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs index 64b3ca4..13c4bbe 100644 --- a/HW1/Trie/Trie.cs +++ b/HW1/Trie/Trie.cs @@ -9,22 +9,13 @@ namespace Trie; /// public class Trie { - private class TrieNode - { - public readonly Dictionary Children = new(); - public bool IsEnd; - public int PrefixCount; - } - - private TrieNode node = new(); + private readonly TrieNode root = new(); /// /// Gets the number of words added to the tree. /// public int WordCount { get; private set; } - private readonly TrieNode root = new TrieNode(); - /// /// Add a new word into the trie. /// @@ -158,4 +149,13 @@ public int HowManyStartsWithPrefix(string? prefix) return current.PrefixCount; } + + private class TrieNode + { + public Dictionary Children { get; } = new(); + + public bool IsEnd { get; set; } + + public int PrefixCount { get; set; } + } } From bb04ac6e74aa767e315fffba26ab5c9f269ed0a6 Mon Sep 17 00:00:00 2001 From: khusainovilas <87306903+khusainovilas@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:13:56 +0300 Subject: [PATCH 6/9] Update HW1/Trie.Test/TrieTest.cs Co-authored-by: Yurii Litvinov --- HW1/Trie.Test/TrieTest.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/HW1/Trie.Test/TrieTest.cs b/HW1/Trie.Test/TrieTest.cs index d13479e..8906613 100644 --- a/HW1/Trie.Test/TrieTest.cs +++ b/HW1/Trie.Test/TrieTest.cs @@ -16,9 +16,7 @@ public class TrieTest /// [SetUp] public void Setup() - { - this.trie = new Trie(); - } + => this.trie = new(); /// /// Tests Add method when inserting fresh words. From 4448131401469e24ea21fbd4a668601c73544f1f Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Mon, 6 Oct 2025 16:17:31 +0300 Subject: [PATCH 7/9] fix: removed check for spaces in the string --- HW1/Trie/Trie.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs index 13c4bbe..a295459 100644 --- a/HW1/Trie/Trie.cs +++ b/HW1/Trie/Trie.cs @@ -23,7 +23,7 @@ public class Trie /// Returns false if the word is already present. public bool Add(string? word) { - if (word is null || string.IsNullOrWhiteSpace(word)) + if (word is null) { return false; } From 2735c833395e580d1cbcfe664586a4f1aa403b35 Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Mon, 6 Oct 2025 16:23:29 +0300 Subject: [PATCH 8/9] fix: removed check for spaces in the string v2 --- HW1/Trie/Trie.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HW1/Trie/Trie.cs b/HW1/Trie/Trie.cs index a295459..3071921 100644 --- a/HW1/Trie/Trie.cs +++ b/HW1/Trie/Trie.cs @@ -59,7 +59,7 @@ public bool Add(string? word) /// Returns true if the word exists in the trie. public bool Contains(string? word) { - if (word is null || string.IsNullOrWhiteSpace(word)) + if (word is null) { return false; } @@ -86,7 +86,7 @@ public bool Contains(string? word) /// Returns true if the word was present in the trie. public bool Remove(string? word) { - if (word is null || string.IsNullOrWhiteSpace(word)) + if (word is null) { return false; } @@ -130,7 +130,7 @@ public bool Remove(string? word) /// The count of words that begin with the specified prefix. public int HowManyStartsWithPrefix(string? prefix) { - if (prefix is null || string.IsNullOrWhiteSpace(prefix)) + if (prefix is null) { return this.WordCount; } From 7d27cd805e9c7b4bb5552094c9ed19ce2885bb9d Mon Sep 17 00:00:00 2001 From: khusainovilas Date: Tue, 21 Oct 2025 20:00:10 +0300 Subject: [PATCH 9/9] Upgrade project to .NET 9 --- HW1/Trie.Test/Trie.Test.csproj | 2 +- HW1/Trie/Trie.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HW1/Trie.Test/Trie.Test.csproj b/HW1/Trie.Test/Trie.Test.csproj index c66f1a6..7cefcd9 100644 --- a/HW1/Trie.Test/Trie.Test.csproj +++ b/HW1/Trie.Test/Trie.Test.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/HW1/Trie/Trie.csproj b/HW1/Trie/Trie.csproj index 82fd482..b158c23 100644 --- a/HW1/Trie/Trie.csproj +++ b/HW1/Trie/Trie.csproj @@ -2,7 +2,7 @@ Library - net8.0 + net9.0 enable enable