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
22 changes: 22 additions & 0 deletions HW1/HW1.sln
Original file line number Diff line number Diff line change
@@ -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.Test", "Trie.Test\Trie.Test.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
40 changes: 40 additions & 0 deletions HW1/Trie.Test/Trie.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Trie.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="NUnit" Version="3.14.0"/>
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Trie\Trie.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

</Project>
172 changes: 172 additions & 0 deletions HW1/Trie.Test/TrieTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// <copyright file="TrieTest.cs" company="khusainovilas">
// Copyright (c) khusainovilas. All rights reserved.
// </copyright>

namespace Trie.Tests;

/// <summary>
/// Unit tests for Trie data structure.
/// </summary>
public class TrieTest
{
private Trie trie;

/// <summary>
/// Initializes a new trie before each test.
/// </summary>
[SetUp]
public void Setup()
=> this.trie = new();

/// <summary>
/// Tests Add method when inserting fresh words.
/// </summary>
[Test]
public void Trie_Add_NewWords_ShouldReturnTrue()
{
List<string> words = ["apple", "app", "application"];

foreach (var word in words)
{
Assert.That(this.trie.Add(word), Is.True);
}
}

/// <summary>
/// Tests WordCount after adding multiple words.
/// </summary>
[Test]
public void Trie_WordCount_AfterAddingSeveralWords()
{
List<string> words = ["alpha", "beta", "gamma", "delta"];

foreach (var word in words)
{
this.trie.Add(word);
}

Assert.That(this.trie.WordCount, Is.EqualTo(words.Count));
}

/// <summary>
/// Tests Add method when the same word is inserted twice.
/// </summary>
[Test]
public void Trie_Add_SameWordTwice_ShouldReturnFalse()
{
const string word = "matrix";

this.trie.Add(word);

Assert.That(this.trie.Add(word), Is.False);
}

/// <summary>
/// Tests Add method after removing a word.
/// </summary>
[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);
}

/// <summary>
/// Tests WordCount after removing words.
/// </summary>
[Test]
public void Trie_WordCount_AfterRemovingSomeWords()
{
List<string> 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));
}

/// <summary>
/// Tests WordCount of an empty trie.
/// </summary>
[Test]
public void Trie_WordCount_OfEmptyTrie_ShouldBeZero()
{
const int expected = 0;

Assert.That(this.trie.WordCount, Is.EqualTo(expected));
}

/// <summary>
/// Tests Contains method after adding a word.
/// </summary>
[Test]
public void Trie_Contains_AfterAddingWord_ShouldReturnTrue()
{
const string word = "cloud";

this.trie.Add(word);

Assert.That(this.trie.Contains(word), Is.True);
}

/// <summary>
/// Tests Contains method with a word that was never added.
/// </summary>
[Test]
public void Trie_Contains_NonExistingWord_ShouldReturnFalse()
{
const string word = "universe";

Assert.That(this.trie.Contains(word), Is.False);
}

/// <summary>
/// Tests Contains method after removing a word.
/// </summary>
[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);
}

/// <summary>
/// Tests Remove method with a word that exists.
/// </summary>
[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);
}

/// <summary>
/// Tests Remove method with a word that does not exist.
/// </summary>
[Test]
public void Trie_Remove_NonExistingWord_ShouldReturnFalse()
{
const string word = "mountain";

Assert.That(this.trie.Remove(word), Is.False);
}
}
9 changes: 9 additions & 0 deletions HW1/Trie.Test/stylecop.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
Loading