Skip to content
Merged
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
143 changes: 143 additions & 0 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
@@ -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'
105 changes: 105 additions & 0 deletions Lab9/Blue/Blue.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,108 @@
namespace Lab9.Blue
{
public class String
{
public static void Add<T>(ref T[] arr, T elem)
{
Array.Resize(ref arr, arr.Length + 1);
arr[arr.Length - 1] = elem;
}
public static string[] Split(string t)
{
var ans = new string[] { };
var str = "";
foreach(var i in t)
{
if(i == ' ')
{
Add(ref ans, str);
str = "";
}
else
{
str += i;
}
}
Add(ref ans, str);
return ans;
}
public static string[] SplitAll(string t)
{
var ans = new string[] { };
var str = "";
foreach (var i in t)
{
if (i == ' ' || char.IsPunctuation(i))
{
Add(ref ans, str);
str = "";
}
else
{
str += i;
}
}
Add(ref ans, str);
return ans;
}
public static string Join(string[] strs, string sep, bool flag = false)
{
var ans = "";
for (int i = 0; i < strs.Length; i++)
{
if (string.IsNullOrEmpty(strs[i]) && flag) continue;
ans += strs[i];
if (i != strs.Length - 1) ans += sep;
}
return ans;
}
public static string Join(string[] strs, char sep, bool flag = false)
{
string t = "";
t += sep;
return Join(strs, t, flag);
}
public static bool Find(string where, string what)
{
return where.Contains(what);
}
public static bool Find(string where, char what)
{
return where.Contains(what);
}
public static string OnlyPunct(string s)
{
var ans = "";
foreach(var i in s)
if (Find(".,:;'!\"", i)) ans += i;
return ans;
}
public static string OnlyLetters(string s)
{
var ans = "";
foreach (var i in s) if (char.IsNumber(i)) return ""; else if (char.IsLetter(char.ToLower(i))) ans += char.ToLower(i);
return ans;
}
public static int OnlyNumbers(string s)
{
var ans = 0;
foreach (var i in s) if (char.IsNumber(i)) { ans *= 10; ans += i - '0'; }
return ans;
}
}
public abstract class Blue
{
protected string _input;

public string Input => _input;

protected Blue(string input) => _input = input;

public abstract void Review();
public virtual void ChangeText(string text)
{
_input = text;
Review();
}
}
}
43 changes: 43 additions & 0 deletions Lab9/Blue/Task1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab9.Blue
{
public class Task1 : Blue
{
private string[] _output;

public string[] Output => _output.ToArray();
public Task1(string input) : base(input)
{
_output = new string[0];
}

public override void Review()
{
_output = new string[0];
var t = String.Split(_input);
var s = "";
foreach (var i in t)
{
if(s.Length + i.Length + 1 <= 50)
{
s += (s.Length == 0?"":" ") + i;
}
else
{
String.Add(ref _output, s);
s = i;
}
}
String.Add(ref _output, s);
}
public override string ToString()
{
return String.Join(_output, Environment.NewLine);
}
}
}
47 changes: 47 additions & 0 deletions Lab9/Blue/Task2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab9.Blue
{
public class Task2 : Blue
{
private string _substr;
private string _output;

public string Output => _output;
public Task2(string input, string substr) : base(input)
{
_substr = substr;
_output = "";
}

public override void Review()
{
var t1 = String.Split(_input);
var ans = new string[1];
for (int i = 0; i < t1.Length; i++)
{
if (String.Find(t1[i], _substr))
{
if (String.OnlyPunct(t1[i]) == "\"\"," || String.OnlyPunct(t1[i]) == "\"\".")
{
String.Add(ref ans, String.OnlyPunct(t1[i]));
continue;
}
ans[ans.Length - 1] += String.OnlyPunct(t1[i]);
continue;
}
String.Add(ref ans, t1[i]);
}
_output = String.Join(ans, ' ', true);
}
public override string ToString()
{
return _output;
}
}
}
Loading
Loading