Skip to content
169 changes: 169 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# CLAUDE.md — BIVT-25 Lab-6

This file describes the codebase structure, build/test workflows, and conventions for AI assistants working in this repository.

---

## Repository Overview

**BIVT-25 Lab-6** is a C# (.NET 8.0) academic programming assignment. Students implement 10 algorithmic tasks (array and matrix operations) inside the `Green` class. The test suite is pre-written and immutable; the goal is to make all tests in `GreenTest` pass.

---

## Directory Structure

```
BIVT-25-Lab-6/
├── .github/workflows/
│ └── Tests_runner.yml # CI: build + cascade test runner
├── Lab6/ # Main implementation project
│ ├── Green.cs # PRIMARY FILE — implement Task1–Task10 and helpers here
│ ├── Program.cs # Entry point (Main is empty; not used)
│ ├── Shims.cs # Placeholder stubs (do not modify)
│ ├── Lab6.csproj # Project file (OutputType: Exe, net8.0)
│ └── Lab6.sln # Visual Studio solution
└── Lab6test/ # Test project (do not modify)
├── GreenTest.cs # Test class for Green (1028 lines, 20+ test methods)
├── Data.cs # Test fixtures (10 matrices, 5 jagged arrays)
├── MSTestSettings.cs # Parallelization config
└── Lab6test.csproj # Test project file
```

---

## The Only File to Edit

**`Lab6/Green.cs`** is the sole file requiring implementation work.

- Class: `Lab6.Green`
- Namespace: `Lab6`
- Public delegate defined at namespace level: `public delegate void Sorting(int[] row);`
- Methods `Task1` through `Task10` contain `// code here` … `// end` markers where logic is implemented
- Helper methods below the task methods are also part of the class

**Do not modify** `GreenTest.cs`, `Data.cs`, `MSTestSettings.cs`, `Shims.cs`, or any `.csproj`/`.sln` file.

---

## Build & Test Commands

All commands run from the repository root.

### Restore dependencies
```bash
dotnet restore Lab6/Lab6.sln
```

### Build
```bash
dotnet build Lab6/Lab6.sln --configuration Debug --no-restore
```

### Run all GreenTest tests
```bash
dotnet test Lab6test/Lab6test.csproj --configuration Debug --filter "FullyQualifiedName~GreenTest"
```

### Run a single test method (e.g., Test01)
```bash
dotnet test Lab6test/Lab6test.csproj --filter "FullyQualifiedName~GreenTest.Test01"
```

### Run all tests (no filter)
```bash
dotnet test Lab6test/Lab6test.csproj --configuration Debug
```

---

## CI/CD Pipeline (`.github/workflows/Tests_runner.yml`)

- **Triggers:** `push` (non-main branches), `pull_request_target`, `workflow_dispatch`, `issue_comment`
- **Runner:** `windows-latest`
- **Protection:** PRs targeting `main` are blocked outright
- **Cascade strategy:** The workflow tries test classes in order — `Purple → Blue → Green → White` — and stops at the first passing class. This means GreenTest must fully pass to count as a successful run.
- **Artifacts:** TRX test result files are uploaded after every run

---

## Task Descriptions (Green.cs)

| Method | Signature | Description |
|----------|----------------------------------------------------|-------------|
| `Task1` | `void Task1(ref int[] A, ref int[] B)` | Delete max element from each array, then combine A and B into A; B becomes A-without-max |
| `Task2` | `void Task2(int[,] matrix, int[] array)` | In each row, replace the max element with `array[i]` if `array[i]` is larger |
| `Task3` | `void Task3(int[,] matrix)` | Find global max in square matrix; swap its column with the main diagonal |
| `Task4` | `void Task4(ref int[,] matrix)` | Remove all rows that contain at least one zero |
| `Task5` | `int[] Task5(int[,] matrix)` | For each row of a square matrix, find the minimum of elements from the diagonal position onward |
| `Task6` | `int[] Task6(int[,] A, int[,] B)` | Return combined array of column-wise positive sums from matrix A then matrix B |
| `Task7` | `void Task7(int[,] matrix, Sorting sort)` | Apply the given `Sorting` delegate to every row of the matrix |
| `Task8` | `int Task8(double[] A, double[] B)` | Compare triangle areas (sides given); return 1 if A >= B, 2 if B > A (Heron's formula) |
| `Task9` | `void Task9(int[,] matrix, Action<int[]> sorter)` | Apply `sorter` to every even-indexed row (0, 2, 4, …) |
| `Task10` | `double Task10(int[][] array, Func<int[][], double> func)` | Apply `func` to the jagged array and return the result |

### Key Helper Methods

| Method | Purpose |
|--------|---------|
| `DeleteMaxElement(ref int[] array)` | Remove the first occurrence of the maximum value |
| `CombineArrays(int[] A, int[] B)` | Concatenate two arrays |
| `FindMaxInRow(int[,], int row, out int col)` | Returns max value and its column index |
| `FindMax(int[,], out int row, out int col)` | Global max with position |
| `SwapColWithDiagonal(int[,], int col)` | Swap column `col` with main diagonal elements |
| `RemoveRow(ref int[,], int row)` | Remove a single row from a 2D array |
| `SumPositiveElementsInColumns(int[,])` | Per-column sum of positive values |
| `SortEndAscending/Descending(int[])` | Sort elements after the max element position |
| `GeronArea(double a, b, c)` | Triangle area via Heron's formula; returns 0 for degenerate triangles |
| `ReplaceRow(int[,], int row, int[])` | Overwrite one row in a 2D matrix |
| `CountZeroSum(int[][])` | Count jagged rows whose element sum is zero |
| `FindMedian(int[][])` | Median of all elements across a jagged array |
| `CountLargeElements(int[][])` | Count elements greater than their row's average |

---

## Code Conventions

### Naming
- Classes and methods: **PascalCase** (`Green`, `Task1`, `DeleteMaxElement`)
- Local variables: **camelCase** (`max`, `idx`, `rows`, `cols`)
- Matrix parameters: uppercase single letters (`A`, `B`)
- Loop counters: single letters (`i`, `j`, `k`, `r`, `w`)

### Style
- No LINQ — use explicit loops
- Return `null` (or early-return `void`) for null/invalid inputs rather than throwing exceptions
- Use `out` parameters for multiple return values from helpers
- `// code here` and `// end` comments mark the implementation region in task methods
- No explicit access modifiers on class members (implicitly `internal`/package-private)

### Testing Patterns
- Test class: `GreenTest` (sealed, `[TestClass]`)
- Float comparison epsilon: `const double E = 0.0001`
- AAA pattern: Arrange / Act / Assert
- Fixtures provided by `Data` class via `GetMatrixes()` and `GetArrayArrays()`
- Test data is cloned in `Data` — mutations during tests do not affect other tests

---

## Development Branch

Work on branch: **`claude/add-claude-documentation-VG80N`**

Push with:
```bash
git push -u origin claude/add-claude-documentation-VG80N
```

Do **not** push to `main` — the CI pipeline will reject PRs targeting main.

---

## Common Pitfalls

1. **`Task4` uses `ref int[,]`** — the method must reassign the parameter (`matrix = res`), not just mutate in place.
2. **`Task3` requires a square matrix** (`n == m`); return early otherwise.
3. **`Task8` tie-breaking** — when both triangle areas are equal, return `1` (first triangle wins).
4. **`Task9` sorts only even-indexed rows** (0-based: rows 0, 2, 4, …).
5. **`GeronArea` returns `0`** for degenerate triangles (any side ≤ 0 or triangle inequality fails).
6. **`Task10` delegates all logic to `func`** — the method is a thin pass-through.
7. **RootNamespace mismatch** — `Lab6test.csproj` sets `RootNamespace` to `Lab1_test`, but the actual namespace in source files is `Lab6test`. Do not change this.
94 changes: 0 additions & 94 deletions Lab6/Blue.cs

This file was deleted.

Loading
Loading