diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml
new file mode 100644
index 0000000..fff9e2e
--- /dev/null
+++ b/.github/workflows/dotnet-desktop.yml
@@ -0,0 +1,143 @@
+name: .NET Tests & Auto-commit
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened]
+ push:
+ branches-ignore: [main]
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ pull-requests: write
+ issues: read
+
+jobs:
+
+ check-target:
+ runs-on: ubuntu-latest
+ outputs:
+ pr_valid: ${{ steps.check.outputs.pr_valid }}
+ steps:
+ - name: 🚫 Проверка PR в main
+ id: check
+ shell: bash
+ run: |
+ PR_BASE="${{ github.event.pull_request.base.ref }}"
+ echo "Base branch: $PR_BASE"
+ if [ "$PR_BASE" = "main" ]; then
+ echo "❌ Нельзя отправлять работу в main ветку."
+ echo "pr_valid=false" >> $GITHUB_OUTPUT
+ exit 1
+ else
+ echo "✅ PR направлен в '$PR_BASE', можно запускать тесты."
+ echo "pr_valid=true" >> $GITHUB_OUTPUT
+ fi
+
+ tests:
+ name: Run test
+ runs-on: windows-latest
+ needs: check-target
+ if: |
+ (github.event_name == 'pull_request' && needs.check-target.outputs.pr_valid == 'true') ||
+ github.event_name == 'push' ||
+ github.event_name == 'workflow_dispatch'
+ strategy:
+ matrix:
+ configuration: [Debug]
+
+ steps:
+ - name: Checkout code safely
+ uses: actions/checkout@v4
+ with:
+ repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
+ ref: ${{ github.event.pull_request.head.sha || github.ref }}
+ fetch-depth: 0
+
+ - name: Install .NET Core
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: |
+ 8.0.x
+ 9.0.x
+
+ - name: Setup MSBuild.exe
+ uses: microsoft/setup-msbuild@v2
+
+ - name: Restore
+ run: dotnet restore Lab9/Lab9.sln
+
+ - name: Build
+ run: dotnet build Lab9/Lab9.sln --configuration ${{ matrix.configuration }} --no-restore
+
+ - name: Run tests (league cascade)
+ id: cascade
+ shell: pwsh
+ env:
+ CFG: ${{ matrix.configuration }}
+ run: |
+ $testProjectPath = "Lab9Test/Lab9Test.csproj"
+ $testDir = "Lab9Test"
+
+ Write-Host "Building test project..."
+ dotnet build $testProjectPath -c $Env:CFG --no-restore
+
+ $tfm = (dotnet list $testProjectPath framework --framework net9.0 | Select-Object -Last 1).Trim()
+ if (-not $tfm) { $tfm = "net9.0" }
+
+ $dll = Join-Path $PWD "$testDir\bin\$Env:CFG\$tfm\Lab9Test.dll"
+
+ Write-Host "Ожидаемая DLL: $dll"
+
+ if (-not (Test-Path $dll)) {
+ Write-Error "DLL не найдена: $dll"
+ Write-Host "`nСодержимое bin папки:"
+ Get-ChildItem "$testDir\bin" -Recurse -ErrorAction SilentlyContinue |
+ Select-Object FullName | Out-Host
+ exit 1
+ }
+
+ Write-Host "DLL успешно найдена`n"
+
+ $leagues = @{
+ "Purple" = @("Task1","Task2","Task3","Task4")
+ "Blue" = @("Task1","Task2","Task3","Task4")
+ "Green" = @("Task1","Task2","Task3","Task4")
+ "White" = @("Task1","Task2","Task3","Task4")
+ }
+
+ foreach ($leagueName in $leagues.Keys) {
+ Write-Host "Лига: $leagueName"
+ $allPassed = $true
+
+ foreach ($cls in $leagues[$leagueName]) {
+ $filter = "FullyQualifiedName~$leagueName.$cls"
+ Write-Host " Запуск: $leagueName.$cls"
+
+ dotnet vstest $dll --TestCaseFilter:"$filter" --Logger:"trx;LogFileName=test-$leagueName-$cls.trx"
+
+ if ($LASTEXITCODE -ne 0) {
+ Write-Host " ❌ $leagueName.$cls не прошёл" -ForegroundColor Red
+ $allPassed = $false
+ } else {
+ Write-Host " ✅ $leagueName.$cls прошёл" -ForegroundColor Green
+ }
+ }
+
+ if ($allPassed) {
+ Write-Host "✅ Все тесты лиги $leagueName прошли! Останавливаем каскад." -ForegroundColor Green
+ exit 0
+ } else {
+ Write-Host "⚠️ Лига $leagueName не прошла полностью. Переходим к следующей..." -ForegroundColor Yellow
+ }
+ }
+
+ Write-Host "❌ Ни одна лига полностью не прошла." -ForegroundColor Red
+ exit 1
+
+ - name: Upload TRX
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: trx-${{ matrix.configuration }}
+ path: '**/test-*.trx'
diff --git a/Classwork 06.04/Classwork 06.04.sln b/Classwork 06.04/Classwork 06.04.sln
new file mode 100644
index 0000000..814b0be
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.14.37012.4 d17.14
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Classwork 06.04", "Classwork 06.04\Classwork 06.04.csproj", "{6C7809F8-8EF6-4E0C-8332-879DC02ED08F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6C7809F8-8EF6-4E0C-8332-879DC02ED08F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6C7809F8-8EF6-4E0C-8332-879DC02ED08F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6C7809F8-8EF6-4E0C-8332-879DC02ED08F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6C7809F8-8EF6-4E0C-8332-879DC02ED08F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {7F328878-78D9-4A84-8D60-361827FC6980}
+ EndGlobalSection
+EndGlobal
diff --git a/Classwork 06.04/Classwork 06.04/App.config b/Classwork 06.04/Classwork 06.04/App.config
new file mode 100644
index 0000000..5754728
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Classwork 06.04/Classwork 06.04/Classwork 06.04.csproj b/Classwork 06.04/Classwork 06.04/Classwork 06.04.csproj
new file mode 100644
index 0000000..4aad1fb
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/Classwork 06.04.csproj
@@ -0,0 +1,53 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {6C7809F8-8EF6-4E0C-8332-879DC02ED08F}
+ Exe
+ Classwork_06._04
+ Classwork 06.04
+ v4.7.2
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Classwork 06.04/Classwork 06.04/Program.cs b/Classwork 06.04/Classwork 06.04/Program.cs
new file mode 100644
index 0000000..3f16d00
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/Program.cs
@@ -0,0 +1,152 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Classwork_06._04
+{
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ string s = "Hello, World!";
+ Console.WriteLine(s);
+ Console.WriteLine(s[7]);
+
+ var students = new Student[]
+ {
+ new Student("a", "A", new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }),
+ new Student("B", "b", new int[,] { { 2, 4, 3 }, { 4, 1, 1 } }),
+ new Student("C", "C", new int[,] { { 5, 2, 1 }, { 2, 4, 4 } }),
+ };
+
+ foreach (var student in students)
+ {
+ Console.WriteLine(student[0]);
+ }
+
+ string str = "I am a good student";
+ string str2 = "No! I am!";
+ str = "No! I am!";
+ str2 = str;
+
+ Console.WriteLine(str2);
+ //str2 = str2.Substring(2, 5);
+ //str2 = str2.Replace("am", "sAS", StringComparison.InvariantCultureIgnoreCase);
+ //int index = str2.IndexOf("I");
+
+ var strings = str.Split(new char[] { '.', '?', '!'}, StringSplitOptions.RemoveEmptyEntries);
+ Console.WriteLine(str2);
+
+ foreach (var c in "Решения должны находиться в файле с названием, соответствующем его номеру внутри папки\r\nс названием вашей лиги. Решение номеров необходимо писать внутри класса с соответствующим\r\nномером (Task1 – Task4). Автотестами будет сравниваться состояние Ваших объектов с выходными\r\nданными.")
+ {
+ bool isLetter = Char.IsLetter(c);
+ bool isDigit = Char.IsDigit(c);
+ bool isSpaceTabNewLine = Char.IsSeparator(c);
+ bool isPunctuation = Char.IsPunctuation(c);
+ }
+
+ string output = $"New \n text \r on \r\n each{Environment.NewLine} line!";
+
+ StringBuilder sb = new StringBuilder();
+ sb.Append("sdadsdad");
+ sb.Remove(1, 5);
+ //преобразование динамического массива символово в строку
+ sb.ToString();
+
+
+ //Regex regex = new Regex("[/d+]");
+ //var result = regex.Match("Решения должны находиться в файле с названием, соответствующем его номеру внутри папки\r\nс названием вашей лиги. Решение номеров необходимо писать внутри класса с соответствующим\r\nномером (Task1 – Task4). Автотестами будет сравниваться состояние Ваших объектов с выходными\r\nданными.");
+ //foreach (var match in result.Value)
+ //{
+ // Console.WriteLine(match);
+ //}
+ }
+ }
+
+ public class Student
+ {
+ string _name;
+ string _surname;
+
+ int[,] _marks;
+
+ public int[,] Marks => _marks;
+ public double[] AverageMarks
+ {
+ get
+ {
+ if ( _marks == null || _marks.GetLength(0) == 0 || _marks.GetLength(1) == 0)
+ {
+ return null;
+ }
+ var average = new double[_marks.GetLength(0)];
+ for (int i = 0; i < average.Length; i++)
+ {
+ for (int j = 0; j<_marks.GetLength(1); j++)
+ {
+ average[i] += (double)_marks[i, j] / _marks.GetLength(1);
+ }
+ }
+ return average;
+ }
+ }
+
+ public char this[int idx]
+ {
+ get { return _name[idx]; }
+ }
+
+ //public double this[int idx]
+ //{
+ // get { return AverageMarks[idx]; }
+ //}
+
+ public int this[int i, int j]
+ {
+ get { return _marks[i, j]; }
+ }
+
+ public Student(string name, string surname, int[,] marks = null)
+ {
+ _name = name;
+ _surname = surname;
+ if (_marks != null)
+ {
+ _marks = (int[,])marks.Clone();
+ }
+ }
+
+ public override string ToString()
+ {
+ string output = _name + " " + _surname;
+ for (int i = 0; i < _marks.GetLength(0); i++)
+ {
+ for (int j = 0; j<_marks.GetLength(1); j++)
+ {
+ output += _marks[i, j] + " ";
+ }
+ output = output.TrimEnd();
+ output += Environment.NewLine;
+ }
+ return output;
+
+ StringBuilder sb = new StringBuilder(_name);
+ sb.Append(" ");
+ sb.AppendLine(_surname);
+ for (int i = 0; i < _marks.GetLength(0); i++)
+ {
+ for (int j = 0; j < _marks.GetLength(1); j++)
+ {
+ sb.Append(_marks[i, j]).Append(" ");
+ }
+ sb = sb.Remove(sb.Length-1, 1);
+ sb.AppendLine();
+ }
+
+
+ }
+ }
+}
diff --git a/Classwork 06.04/Classwork 06.04/Properties/AssemblyInfo.cs b/Classwork 06.04/Classwork 06.04/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..d21da1d
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Общие сведения об этой сборке предоставляются следующим набором
+// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
+// связанные с этой сборкой.
+[assembly: AssemblyTitle("Classwork 06.04")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Classwork 06.04")]
+[assembly: AssemblyCopyright("Copyright © 2026")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
+// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
+// из модели COM задайте для атрибута ComVisible этого типа значение true.
+[assembly: ComVisible(false)]
+
+// Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM
+[assembly: Guid("6c7809f8-8ef6-4e0c-8332-879dc02ed08f")]
+
+// Сведения о версии сборки состоят из указанных ниже четырех значений:
+//
+// Основной номер версии
+// Дополнительный номер версии
+// Номер сборки
+// Номер редакции
+//
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe
new file mode 100644
index 0000000..0931e0a
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe differ
diff --git a/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe.config b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe.config
new file mode 100644
index 0000000..5754728
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.exe.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.pdb b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.pdb
new file mode 100644
index 0000000..5001d38
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/bin/Debug/Classwork 06.04.pdb differ
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.AssemblyReference.cache b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.AssemblyReference.cache
new file mode 100644
index 0000000..25132c6
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.AssemblyReference.cache differ
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.CoreCompileInputs.cache b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.CoreCompileInputs.cache
new file mode 100644
index 0000000..fe38182
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.CoreCompileInputs.cache
@@ -0,0 +1 @@
+137ddb1975586287657f37337b64d051167bb6a147915d9fb5b8eb94b1093509
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.FileListAbsolute.txt b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.FileListAbsolute.txt
new file mode 100644
index 0000000..7c19781
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.csproj.FileListAbsolute.txt
@@ -0,0 +1,8 @@
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\bin\Debug\Classwork 06.04.exe.config
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\bin\Debug\Classwork 06.04.exe
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\bin\Debug\Classwork 06.04.pdb
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\obj\Debug\Classwork 06.04.csproj.AssemblyReference.cache
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\obj\Debug\Classwork 06.04.csproj.CoreCompileInputs.cache
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\obj\Debug\Classwork 06.04.exe
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\obj\Debug\Classwork 06.04.pdb
+C:\Users\Lenovo\source\repos\Classwork 06.04\Classwork 06.04\obj\Debug\Classwork 06.04.exe.config
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe
new file mode 100644
index 0000000..0931e0a
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe differ
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe.config b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe.config
new file mode 100644
index 0000000..5754728
--- /dev/null
+++ b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.exe.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.pdb b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.pdb
new file mode 100644
index 0000000..5001d38
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/obj/Debug/Classwork 06.04.pdb differ
diff --git a/Classwork 06.04/Classwork 06.04/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Classwork 06.04/Classwork 06.04/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
new file mode 100644
index 0000000..98f9bbd
Binary files /dev/null and b/Classwork 06.04/Classwork 06.04/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
diff --git a/Lab9/Purple/Purple.cs b/Lab9/Purple/Purple.cs
index c00ca3e..448eeca 100644
--- a/Lab9/Purple/Purple.cs
+++ b/Lab9/Purple/Purple.cs
@@ -1,3 +1,21 @@
-namespace Lab9.Purple
-{
+namespace Lab9.Purple
+{
+ public abstract class Purple
+ {
+ private string _input;
+ public string Input => _input;
+
+ protected Purple(string input)
+ {
+ _input = input;
+ }
+
+ public abstract void Review();
+
+ public virtual void ChangeText(string text)
+ {
+ _input = text;
+ Review();
+ }
+ }
}
\ No newline at end of file
diff --git a/Lab9/Purple/Task1.cs b/Lab9/Purple/Task1.cs
new file mode 100644
index 0000000..8e392f4
--- /dev/null
+++ b/Lab9/Purple/Task1.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lab9.Purple
+{
+ public class Task1 : Purple
+ {
+ private string _output;
+ public Task1(string input) : base(input)
+ {
+ _output = "";
+ }
+ public string Output => _output;
+
+ internal StringBuilder Reverse(StringBuilder word)
+ {
+ StringBuilder result = new StringBuilder();
+ for (int i = word.Length - 1; i>=0; i--)
+ {
+ if (word[i] == ')') result.Append('(');
+ else if (word[i] == '(') result.Append(')');
+ else result.Append(word[i]);
+ }
+ return result;
+ }
+ public override void Review()
+ {
+ StringBuilder result = new StringBuilder();
+
+ string[] temp = Input.Split(" ");
+ for (int i = 0; i < temp.Length; i++)
+ {
+ StringBuilder word = new StringBuilder();
+ word.Append(temp[i]);
+ if (Char.IsDigit(word[0]))
+ {
+ for (int j = 0; j= 0; j--)
+ {
+ if (!Char.IsPunctuation(word[j]) || (Char.IsPunctuation(word[j]) && word[j] == '-') || (Char.IsPunctuation(word[j]) && word[j].ToString() == "'"))
+ {
+ result.Append(word[j]);
+ }
+ }
+ result.Append(' ');
+ }
+ }
+
+ result.Remove(result.Length - 1, 1);
+ for (int i = 0; i< Input.Length; i++)
+ {
+ if (Char.IsPunctuation(Input[i]) && Input[i] != '-' && Input[i].ToString() != "'")
+ {
+ result.Insert(i, Input[i]);
+ }
+ }
+ _output = result.ToString();
+ }
+
+ public override string ToString()
+ {
+ return _output;
+ }
+
+ }
+}
diff --git a/Lab9/Purple/Task2.cs b/Lab9/Purple/Task2.cs
new file mode 100644
index 0000000..e2bcdab
--- /dev/null
+++ b/Lab9/Purple/Task2.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lab9.Purple
+{
+ public class Task2 : Purple
+ {
+ private string[] _output;
+
+ public string[] Output => _output;
+ public Task2(string input) : base(input)
+ {
+ _output = new string[0];
+ }
+
+ public override void Review()
+ {
+ if (string.IsNullOrWhiteSpace(Input))
+ {
+ _output = new string[0];
+ return;
+ }
+
+ int width = 50;
+
+ string[] words = Input.Split(' ');
+
+ string[] tempLines = new string[words.Length];
+ int lineCount = 0;
+
+ int i = 0;
+
+ while (i < words.Length)
+ {
+ string[] lineWords = new string[words.Length];
+ int wordCount = 0;
+ int currentLength = 0;
+
+ while (i < words.Length)
+ {
+ string word = words[i].Trim();
+ int newLength;
+
+ if (wordCount == 0)
+ {
+ newLength = word.Length;
+ }
+ else
+ {
+ newLength = currentLength + 1 + word.Length;
+ }
+
+ if (newLength <= width)
+ {
+ lineWords[wordCount] = word;
+ wordCount++;
+ currentLength = newLength;
+ i++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ string line = "";
+ if (wordCount == 1)
+ {
+ line = lineWords[0];
+ }
+ else
+ {
+ int lettersCount = 0;
+ for (int j = 0; j < wordCount; j++)
+ {
+ lettersCount = lettersCount + lineWords[j].Length;
+ }
+
+ int spacesCount = width - lettersCount;
+ int gaps = wordCount - 1;
+
+ int baseSpace = spacesCount / gaps;
+ int extraSpaces = spacesCount % gaps;
+
+ StringBuilder sb = new StringBuilder();
+
+ for (int j = 0; j < wordCount; j++)
+ {
+ sb.Append(lineWords[j]);
+
+ if (j < gaps)
+ {
+ int spaces = baseSpace;
+
+ if (j < extraSpaces)
+ {
+ spaces++;
+ }
+
+ sb.Append(' ', spaces);
+ }
+ }
+
+ line = sb.ToString();
+ }
+
+ tempLines[lineCount] = line;
+ lineCount++;
+ }
+
+ _output = new string[lineCount];
+ for (int j = 0; j < lineCount; j++)
+ {
+ _output[j] = tempLines[j];
+ }
+ }
+ public override string ToString()
+ {
+ if (_output == null || _output.Length == 0)
+ return "";
+
+ string result = _output[0];
+
+ for (int i = 1; i < _output.Length; i++)
+ {
+ result += Environment.NewLine + _output[i];
+ }
+
+ return result;
+ }
+
+ }
+}
diff --git a/Lab9/Purple/Task3.cs b/Lab9/Purple/Task3.cs
new file mode 100644
index 0000000..897d37d
--- /dev/null
+++ b/Lab9/Purple/Task3.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lab9.Purple
+{
+ public class Task3 : Purple
+ {
+ private string _output;
+ private (string, char)[] _codes;
+ public string Output => _output;
+ public (string, char)[] Codes => _codes;
+ public Task3(string input) : base(input)
+ {
+ _output = "";
+ _codes = new (string, char)[5];
+ }
+
+ public override void Review()
+ {
+ string[] pairs = new string[0];
+ int[] firstIndex = new int[0];
+
+ _output = Input;
+
+ for (int i = 1; i < Input.Length; i++)
+ {
+ if (Char.IsLetter(Input[i - 1]) && Char.IsLetter(Input[i]))
+ {
+ string pair = Input[i - 1].ToString() + Input[i].ToString();
+
+ if (!pairs.Contains(pair))
+ {
+ Array.Resize(ref pairs, pairs.Length + 1);
+ pairs[^1] = pair;
+
+ Array.Resize(ref firstIndex, firstIndex.Length + 1);
+ firstIndex[^1] = i - 1;
+ }
+ }
+ }
+
+ int[] pairsCount = new int[pairs.Length];
+
+ for (int i = 0; i < pairs.Length; i++)
+ {
+ int count = 0;
+
+ for (int j = 0; j < Input.Length - 1; j++)
+ {
+ string sub = Input.Substring(j, 2);
+
+ if (sub == pairs[i])
+ {
+ count++;
+ }
+ }
+
+ pairsCount[i] = count;
+ }
+
+ for (int i = 0; i < pairs.Length - 1; i++)
+ {
+ for (int j = i + 1; j < pairs.Length; j++)
+ {
+ if (pairsCount[i] < pairsCount[j] || (pairsCount[i] == pairsCount[j] && firstIndex[i] > firstIndex[j]))
+ {
+ (pairsCount[i], pairsCount[j]) = (pairsCount[j], pairsCount[i]);
+ (pairs[i], pairs[j]) = (pairs[j], pairs[i]);
+ (firstIndex[i], firstIndex[j]) = (firstIndex[j], firstIndex[i]);
+ }
+ }
+ }
+
+ int limit = pairs.Length;
+ if (limit > 5)
+ {
+ limit = 5;
+ }
+
+ string[] topPairs = new string[limit];
+
+ for (int i = 0; i < limit; i++)
+ {
+ topPairs[i] = pairs[i];
+ }
+
+ string[] tempCodes = new string[limit];
+
+ for (int i = 0; i < limit; i++)
+ {
+ tempCodes[i] = "#" + i + "#";
+ _output = _output.Replace(topPairs[i], tempCodes[i]);
+ }
+
+ int symbolIndex = 32;
+
+ for (int i = 0; i < limit; i++)
+ {
+ while (Input.Contains(((char)symbolIndex).ToString()))
+ {
+ symbolIndex++;
+ }
+
+ _output = _output.Replace(tempCodes[i], ((char)symbolIndex).ToString());
+ _codes[i] = (pairs[i], (char)symbolIndex);
+ symbolIndex++;
+ }
+ }
+
+ public override string ToString()
+ {
+ return _output;
+ }
+ }
+}
diff --git a/Lab9/Purple/Task4.cs b/Lab9/Purple/Task4.cs
new file mode 100644
index 0000000..dcea5d9
--- /dev/null
+++ b/Lab9/Purple/Task4.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lab9.Purple
+{
+ public class Task4 : Purple
+ {
+ private string _output;
+ private (string, char)[] _codes;
+ public string Output => _output;
+ public (string, char)[] Codes => _codes;
+ public Task4(string input, (string, char)[] codes) : base(input)
+ {
+ _output = "";
+ _codes = codes;
+ }
+
+ public override void Review()
+ {
+ _output = Input;
+
+ for (int i = 0; i < Codes.Length; i++)
+ {
+ int j = 0;
+
+ while (j < _output.Length)
+ {
+ if (_output[j] == Codes[i].Item2)
+ {
+ string replacement = Codes[i].Item1;
+
+ _output = _output.Remove(j, 1);
+ _output = _output.Insert(j, replacement);
+
+ j += replacement.Length;
+ }
+ else
+ {
+ j++;
+ }
+ }
+ }
+ }
+
+ public override string ToString()
+ {
+ return _output;
+ }
+ }
+}
diff --git a/Lab9Test/Purple/Task1.cs b/Lab9Test/Purple/Task1.cs
index 53908f0..c0bcf40 100644
--- a/Lab9Test/Purple/Task1.cs
+++ b/Lab9Test/Purple/Task1.cs
@@ -1,177 +1,177 @@
-//using System.Text.Json;
-//using System.Linq;
-
-//namespace Lab9Test.Purple
-//{
-// [TestClass]
-// public sealed class Task1
-// {
-// private Lab9.Purple.Task1 _student;
-
-// private string[] _input;
-// private string[] _output;
-
-// [TestInitialize]
-// public void LoadData()
-// {
-// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
-// var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
-
-// var json = JsonSerializer.Deserialize(
-// File.ReadAllText(file));
-
-// _input = json.GetProperty("Purple1")
-// .GetProperty("input")
-// .Deserialize();
-
-// _output = json.GetProperty("Purple1")
-// .GetProperty("output")
-// .Deserialize();
-// }
-
-// [TestMethod]
-// public void Test_00_OOP()
-// {
-// var type = typeof(Lab9.Purple.Task1);
-
-// Assert.IsTrue(type.IsClass, "Task1 must be a class");
-// Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)),
-// "Task1 must inherit from Purple");
-
-// Assert.IsNotNull(
-// type.GetConstructor(new[] { typeof(string) }),
-// "Constructor Task1(string input) not found"
-// );
-
-// Assert.IsNotNull(type.GetMethod("Review"),
-// "Method Review() not found");
-
-// Assert.IsNotNull(type.GetMethod("ToString"),
-// "Method ToString() not found");
-// }
-
-// [TestMethod]
-// public void Test_01_Input()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-
-// Assert.AreEqual(_input[i], _student.Input,
-// $"Input stored incorrectly\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_02_Output()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.Output,
-// $"Output mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_03_ToString()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.ToString(),
-// $"ToString mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_04_ChangeText()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var oldOutput = _student.Output;
-
-// var newText = _input[(i + 1) % _input.Length];
-// _student.ChangeText(newText);
-
-// Assert.AreEqual(newText, _student.Input,
-// $"ChangeText failed\nTest: {i}");
-
-// Assert.AreNotEqual(oldOutput, _student.Output,
-// $"Output not updated after ChangeText\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_05_TypeSafety()
-// {
-// Init(0);
-// _student.Review();
-
-// Assert.IsInstanceOfType(_student.Output, typeof(string),
-// $"Output must be string\nActual: {_student.Output.GetType()}");
-// }
-
-// [TestMethod]
-// public void Test_06_Length()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i].Length, _student.ToString().Length,
-// $"Length mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_07_PunctuationPreserved()
-// {
-// Init(0);
-// _student.Review();
-
-// var input = _student.Input;
-// var output = _student.Output;
-
-// var inputPunct = new string(input.Where(c => !char.IsLetterOrDigit(c) && c != ' ').ToArray());
-// var outputPunct = new string(output.Where(c => !char.IsLetterOrDigit(c) && c != ' ').ToArray());
-
-// Assert.AreEqual(inputPunct, outputPunct,
-// "Punctuation must stay in the same places");
-// }
-
-// [TestMethod]
-// public void Test_08_WordsReversed()
-// {
-// Init(0);
-// _student.Review();
-
-// var wordsIn = _student.Input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
-// var wordsOut = _student.Output.Split(' ', StringSplitOptions.RemoveEmptyEntries);
-
-// for (int i = 0; i < Math.Min(wordsIn.Length, wordsOut.Length); i++)
-// {
-// var cleanIn = new string(wordsIn[i].Where(char.IsLetter).ToArray());
-// var cleanOut = new string(wordsOut[i].Where(char.IsLetter).ToArray());
-
-// var reversed = new string(cleanIn.Reverse().ToArray());
-
-// Assert.AreEqual(reversed, cleanOut,
-// $"Word not reversed\nIndex: {i}\nExpected: {reversed}\nActual: {cleanOut}");
-// }
-// }
-
-// private void Init(int i)
-// {
-// _student = new Lab9.Purple.Task1(_input[i]);
-// }
-// }
-//}
\ No newline at end of file
+using System.Text.Json;
+using System.Linq;
+
+namespace Lab9Test.Purple
+{
+ [TestClass]
+ public sealed class Task1
+ {
+ private Lab9.Purple.Task1 _student;
+
+ private string[] _input;
+ private string[] _output;
+
+ [TestInitialize]
+ public void LoadData()
+ {
+ var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
+ var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
+
+ var json = JsonSerializer.Deserialize(
+ File.ReadAllText(file));
+
+ _input = json.GetProperty("Purple1")
+ .GetProperty("input")
+ .Deserialize();
+
+ _output = json.GetProperty("Purple1")
+ .GetProperty("output")
+ .Deserialize();
+ }
+
+ [TestMethod]
+ public void Test_00_OOP()
+ {
+ var type = typeof(Lab9.Purple.Task1);
+
+ Assert.IsTrue(type.IsClass, "Task1 must be a class");
+ Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)),
+ "Task1 must inherit from Purple");
+
+ Assert.IsNotNull(
+ type.GetConstructor(new[] { typeof(string) }),
+ "Constructor Task1(string input) not found"
+ );
+
+ Assert.IsNotNull(type.GetMethod("Review"),
+ "Method Review() not found");
+
+ Assert.IsNotNull(type.GetMethod("ToString"),
+ "Method ToString() not found");
+ }
+
+ [TestMethod]
+ public void Test_01_Input()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+
+ Assert.AreEqual(_input[i], _student.Input,
+ $"Input stored incorrectly\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_02_Output()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.Output,
+ $"Output mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_03_ToString()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.ToString(),
+ $"ToString mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_04_ChangeText()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var oldOutput = _student.Output;
+
+ var newText = _input[(i + 1) % _input.Length];
+ _student.ChangeText(newText);
+
+ Assert.AreEqual(newText, _student.Input,
+ $"ChangeText failed\nTest: {i}");
+
+ Assert.AreNotEqual(oldOutput, _student.Output,
+ $"Output not updated after ChangeText\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_05_TypeSafety()
+ {
+ Init(0);
+ _student.Review();
+
+ Assert.IsInstanceOfType(_student.Output, typeof(string),
+ $"Output must be string\nActual: {_student.Output.GetType()}");
+ }
+
+ [TestMethod]
+ public void Test_06_Length()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i].Length, _student.ToString().Length,
+ $"Length mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_07_PunctuationPreserved()
+ {
+ Init(0);
+ _student.Review();
+
+ var input = _student.Input;
+ var output = _student.Output;
+
+ var inputPunct = new string(input.Where(c => !char.IsLetterOrDigit(c) && c != ' ').ToArray());
+ var outputPunct = new string(output.Where(c => !char.IsLetterOrDigit(c) && c != ' ').ToArray());
+
+ Assert.AreEqual(inputPunct, outputPunct,
+ "Punctuation must stay in the same places");
+ }
+
+ [TestMethod]
+ public void Test_08_WordsReversed()
+ {
+ Init(0);
+ _student.Review();
+
+ var wordsIn = _student.Input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
+ var wordsOut = _student.Output.Split(' ', StringSplitOptions.RemoveEmptyEntries);
+
+ for (int i = 0; i < Math.Min(wordsIn.Length, wordsOut.Length); i++)
+ {
+ var cleanIn = new string(wordsIn[i].Where(char.IsLetter).ToArray());
+ var cleanOut = new string(wordsOut[i].Where(char.IsLetter).ToArray());
+
+ var reversed = new string(cleanIn.Reverse().ToArray());
+
+ Assert.AreEqual(reversed, cleanOut,
+ $"Word not reversed\nIndex: {i}\nExpected: {reversed}\nActual: {cleanOut}");
+ }
+ }
+
+ private void Init(int i)
+ {
+ _student = new Lab9.Purple.Task1(_input[i]);
+ }
+ }
+}
diff --git a/Lab9Test/Purple/Task2.cs b/Lab9Test/Purple/Task2.cs
index dafb515..4e7d055 100644
--- a/Lab9Test/Purple/Task2.cs
+++ b/Lab9Test/Purple/Task2.cs
@@ -1,187 +1,187 @@
-//using System.Text.Json;
-//using System.Linq;
-
-//namespace Lab9Test.Purple
-//{
-// [TestClass]
-// public sealed class Task2
-// {
-// private Lab9.Purple.Task2 _student;
-
-// private string[] _input;
-// private string[][] _output;
-
-// [TestInitialize]
-// public void LoadData()
-// {
-// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
-// var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
-
-// var json = JsonSerializer.Deserialize(
-// File.ReadAllText(file));
-
-// _input = json.GetProperty("Purple2")
-// .GetProperty("input")
-// .Deserialize();
-
-// _output = json.GetProperty("Purple2")
-// .GetProperty("output")
-// .Deserialize();
-// }
-
-// [TestMethod]
-// public void Test_00_OOP()
-// {
-// var type = typeof(Lab9.Purple.Task2);
-
-// Assert.IsTrue(type.IsClass);
-// Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
-
-// Assert.IsNotNull(type.GetConstructor(new[] { typeof(string) }));
-// Assert.IsNotNull(type.GetMethod("Review"));
-// Assert.IsNotNull(type.GetMethod("ToString"));
-// }
-
-// [TestMethod]
-// public void Test_01_Output()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var actual = _student.Output;
-// var expected = _output[i];
-
-// Assert.AreEqual(expected.Length, actual.Length,
-// $"Line count mismatch\nTest: {i}");
-
-// for (int j = 0; j < expected.Length; j++)
-// {
-// Assert.AreEqual(expected[j], actual[j],
-// $"Line mismatch\nTest: {i}, Line: {j}");
-// }
-// }
-// }
-
-// [TestMethod]
-// public void Test_02_LineLength()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// for (int j = 0; j < _output[i].Length; j++)
-// {
-// Assert.AreEqual(_output[i][j].Length, _student.Output[j].Length,
-// $"Line length must be 50\nActual: {_student.Output[j].Length}\nLine: {_student.Output[j]}");
-// }
-// }
-// }
-
-// [TestMethod]
-// public void Test_03_NoWordBreak()
-// {
-// Init(0);
-// _student.Review();
-
-// foreach (var line in _student.Output)
-// {
-// Assert.IsFalse(line.StartsWith(" "),
-// "Line starts with space");
-
-// Assert.IsFalse(line.EndsWith(" "),
-// "Line ends with space");
-// }
-// }
-
-// [TestMethod]
-// public void Test_04_SpacesDistributed()
-// {
-// Init(0);
-// _student.Review();
-
-// foreach (var line in _student.Output)
-// {
-// var words = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
-
-// if (words.Length <= 1) continue;
-
-// int spaces = line.Count(c => c == ' ');
-// int minSpaces = (50 - words.Sum(w => w.Length)) / (words.Length - 1);
-
-// Assert.IsTrue(spaces >= minSpaces,
-// $"Spaces distributed incorrectly\nLine: {line}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_05_ToString()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var expected = string.Join(Environment.NewLine, _output[i]);
-// var actual = _student.ToString();
-
-// Assert.AreEqual(expected, actual,
-// $"ToString mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_06_ChangeText()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var old = _student.Output;
-
-// var newText = _input[(i + 1) % _input.Length];
-// _student.ChangeText(newText);
-
-// Assert.AreEqual(newText, _student.Input,
-// $"ChangeText failed\nTest: {i}");
-
-// Assert.IsFalse(old.SequenceEqual(_student.Output),
-// $"Output not updated\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_07_TypeSafety()
-// {
-// Init(0);
-// _student.Review();
-
-// Assert.IsInstanceOfType(_student.Output, typeof(string[]),
-// $"Output must be string[]\nActual: {_student.Output.GetType()}");
-// }
-
-// [TestMethod]
-// public void Test_08_ToStringLength()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var expectedLength = string.Join(Environment.NewLine, _output[i]).Length;
-// var actualLength = _student.ToString().Length;
-
-// Assert.AreEqual(expectedLength, actualLength,
-// $"Wrong ToString length\nTest: {i}");
-// }
-// }
-
-// private void Init(int i)
-// {
-// _student = new Lab9.Purple.Task2(_input[i]);
-// }
-// }
-//}
\ No newline at end of file
+using System.Text.Json;
+using System.Linq;
+
+namespace Lab9Test.Purple
+{
+ [TestClass]
+ public sealed class Task2
+ {
+ private Lab9.Purple.Task2 _student;
+
+ private string[] _input;
+ private string[][] _output;
+
+ [TestInitialize]
+ public void LoadData()
+ {
+ var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
+ var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
+
+ var json = JsonSerializer.Deserialize(
+ File.ReadAllText(file));
+
+ _input = json.GetProperty("Purple2")
+ .GetProperty("input")
+ .Deserialize();
+
+ _output = json.GetProperty("Purple2")
+ .GetProperty("output")
+ .Deserialize();
+ }
+
+ [TestMethod]
+ public void Test_00_OOP()
+ {
+ var type = typeof(Lab9.Purple.Task2);
+
+ Assert.IsTrue(type.IsClass);
+ Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
+
+ Assert.IsNotNull(type.GetConstructor(new[] { typeof(string) }));
+ Assert.IsNotNull(type.GetMethod("Review"));
+ Assert.IsNotNull(type.GetMethod("ToString"));
+ }
+
+ [TestMethod]
+ public void Test_01_Output()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var actual = _student.Output;
+ var expected = _output[i];
+
+ Assert.AreEqual(expected.Length, actual.Length,
+ $"Line count mismatch\nTest: {i}");
+
+ for (int j = 0; j < expected.Length; j++)
+ {
+ Assert.AreEqual(expected[j], actual[j],
+ $"Line mismatch\nTest: {i}, Line: {j}");
+ }
+ }
+ }
+
+ [TestMethod]
+ public void Test_02_LineLength()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ for (int j = 0; j < _output[i].Length; j++)
+ {
+ Assert.AreEqual(_output[i][j].Length, _student.Output[j].Length,
+ $"Line length must be 50\nActual: {_student.Output[j].Length}\nLine: {_student.Output[j]}");
+ }
+ }
+ }
+
+ [TestMethod]
+ public void Test_03_NoWordBreak()
+ {
+ Init(0);
+ _student.Review();
+
+ foreach (var line in _student.Output)
+ {
+ Assert.IsFalse(line.StartsWith(" "),
+ "Line starts with space");
+
+ Assert.IsFalse(line.EndsWith(" "),
+ "Line ends with space");
+ }
+ }
+
+ [TestMethod]
+ public void Test_04_SpacesDistributed()
+ {
+ Init(0);
+ _student.Review();
+
+ foreach (var line in _student.Output)
+ {
+ var words = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
+
+ if (words.Length <= 1) continue;
+
+ int spaces = line.Count(c => c == ' ');
+ int minSpaces = (50 - words.Sum(w => w.Length)) / (words.Length - 1);
+
+ Assert.IsTrue(spaces >= minSpaces,
+ $"Spaces distributed incorrectly\nLine: {line}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_05_ToString()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var expected = string.Join(Environment.NewLine, _output[i]);
+ var actual = _student.ToString();
+
+ Assert.AreEqual(expected, actual,
+ $"ToString mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_06_ChangeText()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var old = _student.Output;
+
+ var newText = _input[(i + 1) % _input.Length];
+ _student.ChangeText(newText);
+
+ Assert.AreEqual(newText, _student.Input,
+ $"ChangeText failed\nTest: {i}");
+
+ Assert.IsFalse(old.SequenceEqual(_student.Output),
+ $"Output not updated\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_07_TypeSafety()
+ {
+ Init(0);
+ _student.Review();
+
+ Assert.IsInstanceOfType(_student.Output, typeof(string[]),
+ $"Output must be string[]\nActual: {_student.Output.GetType()}");
+ }
+
+ [TestMethod]
+ public void Test_08_ToStringLength()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var expectedLength = string.Join(Environment.NewLine, _output[i]).Length;
+ var actualLength = _student.ToString().Length;
+
+ Assert.AreEqual(expectedLength, actualLength,
+ $"Wrong ToString length\nTest: {i}");
+ }
+ }
+
+ private void Init(int i)
+ {
+ _student = new Lab9.Purple.Task2(_input[i]);
+ }
+ }
+}
diff --git a/Lab9Test/Purple/Task3.cs b/Lab9Test/Purple/Task3.cs
index 07799d1..c82aff6 100644
--- a/Lab9Test/Purple/Task3.cs
+++ b/Lab9Test/Purple/Task3.cs
@@ -1,172 +1,172 @@
-//using System.Text.Json;
-//using System.Linq;
-
-//namespace Lab9Test.Purple
-//{
-// [TestClass]
-// public sealed class Task3
-// {
-// private Lab9.Purple.Task3 _student;
-
-// private string[] _input;
-// private string[] _output;
-
-// [TestInitialize]
-// public void LoadData()
-// {
-// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
-// var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
-
-// var json = JsonSerializer.Deserialize(
-// File.ReadAllText(file));
-
-// _input = json.GetProperty("Purple3")
-// .GetProperty("input")
-// .Deserialize();
-
-// _output = json.GetProperty("Purple3")
-// .GetProperty("output")
-// .Deserialize();
-// }
-
-// [TestMethod]
-// public void Test_00_OOP()
-// {
-// var type = typeof(Lab9.Purple.Task3);
-
-// Assert.IsTrue(type.IsClass);
-// Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
-
-// Assert.IsNotNull(type.GetConstructor(new[] { typeof(string) }));
-// Assert.IsNotNull(type.GetMethod("Review"));
-// Assert.IsNotNull(type.GetMethod("ToString"));
-// }
-
-// [TestMethod]
-// public void Test_01_Output()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.Output,
-// $"Output mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_02_ToString()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.ToString(),
-// $"ToString mismatch\nTest: {i}");
-// }
-// }
-
-// //[TestMethod]
-// //public void Test_03_Codes()
-// //{
-// // for (int i = 0; i < _input.Length; i++)
-// // {
-// // Init(i);
-// // _student.Review();
-
-// // var actual = _student.Codes;
-// // var expected = _codes[i];
-
-// // Assert.AreEqual(expected.Length, actual.Length,
-// // $"Codes length mismatch\nTest: {i}");
-
-// // for (int j = 0; j < expected.Length; j++)
-// // {
-// // Assert.AreEqual(expected[j].Item1, actual[j].Item1,
-// // $"Pair mismatch\nTest: {i}, Index: {j}");
-
-// // Assert.AreEqual(expected[j].Item2, actual[j].Item2,
-// // $"Code mismatch\nTest: {i}, Index: {j}");
-// // }
-// // }
-// //}
-
-// [TestMethod]
-// public void Test_04_CodesLimit()
-// {
-// Init(0);
-// _student.Review();
-
-// Assert.IsTrue(_student.Codes.Length <= 5);
-// }
-
-// [TestMethod]
-// public void Test_05_NoOriginalPairsInOutput()
-// {
-// Init(0);
-// _student.Review();
-
-// var output = _student.Output;
-
-// foreach (var pair in _student.Codes)
-// {
-// Assert.IsFalse(output.Contains(pair.Item1),
-// $"Pair not replaced: {pair.Item1}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_06_ChangeText()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// foreach (var pair in _student.Codes)
-// Console.WriteLine($"{pair.Item1}:{pair.Item2}");
-// Console.WriteLine();
-
-// var oldOutput = _student.Output;
-
-// var newText = _input[(i + 1) % _input.Length];
-// _student.ChangeText(newText);
-
-// Assert.AreEqual(newText, _student.Input);
-// Assert.AreNotEqual(oldOutput, _student.Output);
-// }
-// }
-
-// [TestMethod]
-// public void Test_07_TypeSafety()
-// {
-// Init(0);
-// _student.Review();
-
-// Assert.IsInstanceOfType(_student.Output, typeof(string));
-// Assert.IsInstanceOfType(_student.Codes, typeof((string, char)[]));
-// }
-
-// [TestMethod]
-// public void Test_08_CodeSymbolsNotInOriginal()
-// {
-// Init(0);
-// _student.Review();
-
-// var input = _student.Input;
-
-// foreach (var code in _student.Codes)
-// {
-// Assert.IsFalse(input.Contains(code.Item2),
-// $"Code symbol already exists in input: {code.Item2}");
-// }
-// }
-
-// private void Init(int i)
-// {
-// _student = new Lab9.Purple.Task3(_input[i]);
-// }
-// }
-//}
\ No newline at end of file
+using System.Text.Json;
+using System.Linq;
+
+namespace Lab9Test.Purple
+{
+ [TestClass]
+ public sealed class Task3
+ {
+ private Lab9.Purple.Task3 _student;
+
+ private string[] _input;
+ private string[] _output;
+
+ [TestInitialize]
+ public void LoadData()
+ {
+ var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
+ var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
+
+ var json = JsonSerializer.Deserialize(
+ File.ReadAllText(file));
+
+ _input = json.GetProperty("Purple3")
+ .GetProperty("input")
+ .Deserialize();
+
+ _output = json.GetProperty("Purple3")
+ .GetProperty("output")
+ .Deserialize();
+ }
+
+ [TestMethod]
+ public void Test_00_OOP()
+ {
+ var type = typeof(Lab9.Purple.Task3);
+
+ Assert.IsTrue(type.IsClass);
+ Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
+
+ Assert.IsNotNull(type.GetConstructor(new[] { typeof(string) }));
+ Assert.IsNotNull(type.GetMethod("Review"));
+ Assert.IsNotNull(type.GetMethod("ToString"));
+ }
+
+ [TestMethod]
+ public void Test_01_Output()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.Output,
+ $"Output mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_02_ToString()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.ToString(),
+ $"ToString mismatch\nTest: {i}");
+ }
+ }
+
+ //[TestMethod]
+ //public void Test_03_Codes()
+ //{
+ // for (int i = 0; i < _input.Length; i++)
+ // {
+ // Init(i);
+ // _student.Review();
+
+ // var actual = _student.Codes;
+ // var expected = _codes[i];
+
+ // Assert.AreEqual(expected.Length, actual.Length,
+ // $"Codes length mismatch\nTest: {i}");
+
+ // for (int j = 0; j < expected.Length; j++)
+ // {
+ // Assert.AreEqual(expected[j].Item1, actual[j].Item1,
+ // $"Pair mismatch\nTest: {i}, Index: {j}");
+
+ // Assert.AreEqual(expected[j].Item2, actual[j].Item2,
+ // $"Code mismatch\nTest: {i}, Index: {j}");
+ // }
+ // }
+ //}
+
+ [TestMethod]
+ public void Test_04_CodesLimit()
+ {
+ Init(0);
+ _student.Review();
+
+ Assert.IsTrue(_student.Codes.Length <= 5);
+ }
+
+ [TestMethod]
+ public void Test_05_NoOriginalPairsInOutput()
+ {
+ Init(0);
+ _student.Review();
+
+ var output = _student.Output;
+
+ foreach (var pair in _student.Codes)
+ {
+ Assert.IsFalse(output.Contains(pair.Item1),
+ $"Pair not replaced: {pair.Item1}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_06_ChangeText()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ foreach (var pair in _student.Codes)
+ Console.WriteLine($"{pair.Item1}:{pair.Item2}");
+ Console.WriteLine();
+
+ var oldOutput = _student.Output;
+
+ var newText = _input[(i + 1) % _input.Length];
+ _student.ChangeText(newText);
+
+ Assert.AreEqual(newText, _student.Input);
+ Assert.AreNotEqual(oldOutput, _student.Output);
+ }
+ }
+
+ [TestMethod]
+ public void Test_07_TypeSafety()
+ {
+ Init(0);
+ _student.Review();
+
+ Assert.IsInstanceOfType(_student.Output, typeof(string));
+ Assert.IsInstanceOfType(_student.Codes, typeof((string, char)[]));
+ }
+
+ [TestMethod]
+ public void Test_08_CodeSymbolsNotInOriginal()
+ {
+ Init(0);
+ _student.Review();
+
+ var input = _student.Input;
+
+ foreach (var code in _student.Codes)
+ {
+ Assert.IsFalse(input.Contains(code.Item2),
+ $"Code symbol already exists in input: {code.Item2}");
+ }
+ }
+
+ private void Init(int i)
+ {
+ _student = new Lab9.Purple.Task3(_input[i]);
+ }
+ }
+}
diff --git a/Lab9Test/Purple/Task4.cs b/Lab9Test/Purple/Task4.cs
index c027307..5748f88 100644
--- a/Lab9Test/Purple/Task4.cs
+++ b/Lab9Test/Purple/Task4.cs
@@ -1,153 +1,153 @@
-//using System.Text.Json;
-//using System.Linq;
-
-//namespace Lab9Test.Purple
-//{
-// [TestClass]
-// public sealed class Task4
-// {
-// private Lab9.Purple.Task4 _student;
-
-// private string[] _input;
-// private (string, char)[][] _codes;
-// private string[] _output;
-// [TestInitialize]
-// public void LoadData()
-// {
-// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
-// var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
-// var jsonText = File.ReadAllText(file);
-// var json = JsonSerializer.Deserialize(jsonText);
-
-// var purple4 = json.GetProperty("Purple4");
-
-// _input = purple4.GetProperty("input").Deserialize();
-// _output = purple4.GetProperty("output").Deserialize();
-
-// // Десериализация кодов
-// var codeGroups = purple4.GetProperty("codes").EnumerateArray();
-// var listOfArrays = new List<(string, char)[]>();
-
-// foreach (var group in codeGroups)
-// {
-// var pairs = new List<(string, char)>();
-// foreach (var entry in group.EnumerateArray())
-// {
-// string pair = entry.GetProperty("pair").GetString() ?? "";
-// string codeStr = entry.GetProperty("code").GetString() ?? "";
-// char code = string.IsNullOrEmpty(codeStr) ? '\0' : codeStr[0];
-// pairs.Add((pair, code));
-// }
-// listOfArrays.Add(pairs.ToArray());
-// }
-
-// _codes = listOfArrays.ToArray();
-// }
-
-// [TestMethod]
-// public void Test_00_OOP()
-// {
-// var type = typeof(Lab9.Purple.Task4);
-
-// Assert.IsTrue(type.IsClass);
-// Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
-
-// Assert.IsNotNull(type.GetConstructor(new[] { typeof(string), typeof((string, char)[]) }));
-// Assert.IsNotNull(type.GetMethod("Review"));
-// Assert.IsNotNull(type.GetMethod("ToString"));
-// }
-
-// [TestMethod]
-// public void Test_01_Output()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.Output,
-// $"Output mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_02_ToString()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i], _student.ToString(),
-// $"ToString mismatch\nTest: {i}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_03_DecodeAllCodes()
-// {
-// Init(0);
-// _student.Review();
-
-// var output = _student.Output;
-
-// foreach (var code in _codes[0])
-// {
-// Assert.IsFalse(output.Contains(code.Item2),
-// $"Code symbol not decoded: {code.Item2}");
-
-// Assert.IsTrue(output.Contains(code.Item1),
-// $"Pair not restored: {code.Item1}");
-// }
-// }
-
-// [TestMethod]
-// public void Test_04_ChangeText()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// var old = _student.Output;
-
-// var newText = _input[(i + 1) % _input.Length];
-// var newCodes = _codes[(i + 1) % _codes.Length];
-
-// _student.ChangeText(newText);
-// _student = new Lab9.Purple.Task4(newText, newCodes);
-// _student.Review();
-
-// Assert.AreEqual(newText, _student.Input);
-// Assert.AreNotEqual(old, _student.Output);
-// }
-// }
-
-// [TestMethod]
-// public void Test_05_TypeSafety()
-// {
-// Init(0);
-// _student.Review();
-
-// Assert.IsInstanceOfType(_student.Output, typeof(string));
-// }
-
-// [TestMethod]
-// public void Test_06_Length()
-// {
-// for (int i = 0; i < _input.Length; i++)
-// {
-// Init(i);
-// _student.Review();
-
-// Assert.AreEqual(_output[i].Length, _student.ToString().Length,
-// $"Length mismatch\nTest: {i}");
-// }
-// }
-
-// private void Init(int i)
-// {
-// _student = new Lab9.Purple.Task4(_input[i], _codes[i]);
-// }
-// }
-//}
\ No newline at end of file
+using System.Text.Json;
+using System.Linq;
+
+namespace Lab9Test.Purple
+{
+ [TestClass]
+ public sealed class Task4
+ {
+ private Lab9.Purple.Task4 _student;
+
+ private string[] _input;
+ private (string, char)[][] _codes;
+ private string[] _output;
+ [TestInitialize]
+ public void LoadData()
+ {
+ var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
+ var file = Path.Combine(folder, "Lab9Test", "Purple", "data.json");
+ var jsonText = File.ReadAllText(file);
+ var json = JsonSerializer.Deserialize(jsonText);
+
+ var purple4 = json.GetProperty("Purple4");
+
+ _input = purple4.GetProperty("input").Deserialize();
+ _output = purple4.GetProperty("output").Deserialize();
+
+ // Десериализация кодов
+ var codeGroups = purple4.GetProperty("codes").EnumerateArray();
+ var listOfArrays = new List<(string, char)[]>();
+
+ foreach (var group in codeGroups)
+ {
+ var pairs = new List<(string, char)>();
+ foreach (var entry in group.EnumerateArray())
+ {
+ string pair = entry.GetProperty("pair").GetString() ?? "";
+ string codeStr = entry.GetProperty("code").GetString() ?? "";
+ char code = string.IsNullOrEmpty(codeStr) ? '\0' : codeStr[0];
+ pairs.Add((pair, code));
+ }
+ listOfArrays.Add(pairs.ToArray());
+ }
+
+ _codes = listOfArrays.ToArray();
+ }
+
+ [TestMethod]
+ public void Test_00_OOP()
+ {
+ var type = typeof(Lab9.Purple.Task4);
+
+ Assert.IsTrue(type.IsClass);
+ Assert.IsTrue(type.IsSubclassOf(typeof(Lab9.Purple.Purple)));
+
+ Assert.IsNotNull(type.GetConstructor(new[] { typeof(string), typeof((string, char)[]) }));
+ Assert.IsNotNull(type.GetMethod("Review"));
+ Assert.IsNotNull(type.GetMethod("ToString"));
+ }
+
+ [TestMethod]
+ public void Test_01_Output()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.Output,
+ $"Output mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_02_ToString()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i], _student.ToString(),
+ $"ToString mismatch\nTest: {i}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_03_DecodeAllCodes()
+ {
+ Init(0);
+ _student.Review();
+
+ var output = _student.Output;
+
+ foreach (var code in _codes[0])
+ {
+ Assert.IsFalse(output.Contains(code.Item2),
+ $"Code symbol not decoded: {code.Item2}");
+
+ Assert.IsTrue(output.Contains(code.Item1),
+ $"Pair not restored: {code.Item1}");
+ }
+ }
+
+ [TestMethod]
+ public void Test_04_ChangeText()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ var old = _student.Output;
+
+ var newText = _input[(i + 1) % _input.Length];
+ var newCodes = _codes[(i + 1) % _codes.Length];
+
+ _student.ChangeText(newText);
+ _student = new Lab9.Purple.Task4(newText, newCodes);
+ _student.Review();
+
+ Assert.AreEqual(newText, _student.Input);
+ Assert.AreNotEqual(old, _student.Output);
+ }
+ }
+
+ [TestMethod]
+ public void Test_05_TypeSafety()
+ {
+ Init(0);
+ _student.Review();
+
+ Assert.IsInstanceOfType(_student.Output, typeof(string));
+ }
+
+ [TestMethod]
+ public void Test_06_Length()
+ {
+ for (int i = 0; i < _input.Length; i++)
+ {
+ Init(i);
+ _student.Review();
+
+ Assert.AreEqual(_output[i].Length, _student.ToString().Length,
+ $"Length mismatch\nTest: {i}");
+ }
+ }
+
+ private void Init(int i)
+ {
+ _student = new Lab9.Purple.Task4(_input[i], _codes[i]);
+ }
+ }
+}