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'
25 changes: 25 additions & 0 deletions Classwork 06.04/Classwork 06.04.sln
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Classwork 06.04/Classwork 06.04/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
53 changes: 53 additions & 0 deletions Classwork 06.04/Classwork 06.04/Classwork 06.04.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6C7809F8-8EF6-4E0C-8332-879DC02ED08F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Classwork_06._04</RootNamespace>
<AssemblyName>Classwork 06.04</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
152 changes: 152 additions & 0 deletions Classwork 06.04/Classwork 06.04/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}


}
}
}
Loading
Loading