Skip to content

Commit ff4a4f1

Browse files
committed
Enforce checkpoint completeness and fix core assessment spaced input
1 parent 3a4b1d6 commit ff4a4f1

11 files changed

Lines changed: 213 additions & 36 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ compiled_files.txt
1212
compile_errors.txt
1313
__pycache__/
1414
*.pyc
15+
report.txt
16+
core_assessment_report.txt

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ Validate module completeness with:
3939
- `./scripts/check-module-completeness.ps1` (PowerShell)
4040
- `bash ./scripts/check-module-completeness.sh` (Bash)
4141

42+
Validate checkpoint completeness with:
43+
44+
- `./scripts/check-checkpoint-completeness.ps1` (PowerShell)
45+
- `bash ./scripts/check-checkpoint-completeness.sh` (Bash)
46+
4247
Run full repository checks with:
4348

4449
- `./scripts/verify-repo.ps1` (PowerShell)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Run checks locally:
108108
./scripts/check-links.ps1
109109
./scripts/check-readme-structure.ps1
110110
./scripts/check-module-completeness.ps1
111+
./scripts/check-checkpoint-completeness.ps1
111112
./scripts/smoke-languages.ps1
112113
./scripts/build-all.ps1
113114
./scripts/verify-repo.ps1
@@ -117,12 +118,13 @@ Run checks locally:
117118
bash ./scripts/check-links.sh
118119
bash ./scripts/check-readme-structure.sh
119120
bash ./scripts/check-module-completeness.sh
121+
bash ./scripts/check-checkpoint-completeness.sh
120122
bash ./scripts/smoke-languages.sh
121123
bash ./scripts/build-all.sh
122124
bash ./scripts/verify-repo.sh
123125
~~~
124126

125-
GitHub Actions validates links, README structure, module completeness, C++ build, and multi-language smoke checks on Linux and Windows.
127+
GitHub Actions validates links, README structure, module completeness, checkpoint completeness, C++ build, and multi-language smoke checks on Linux and Windows.
126128

127129
## Contributing
128130

languages/csharp/assessments/02-core/main.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,44 @@ static void Main()
2323
int[] buckets = new int[10];
2424

2525
Console.WriteLine("Enter integer values (0-100). End with -1.");
26+
bool stopReading = false;
2627
while (true)
2728
{
2829
string raw = Console.ReadLine() ?? string.Empty;
29-
if (!int.TryParse(raw, out int value))
30+
string[] tokens = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
31+
if (tokens.Length == 0)
3032
{
31-
Console.WriteLine("Invalid input. Stopping read.");
32-
break;
33+
continue;
3334
}
3435

35-
if (value == -1)
36+
foreach (string token in tokens)
3637
{
37-
break;
38+
if (!int.TryParse(token, out int value))
39+
{
40+
Console.WriteLine($"Ignoring invalid token: {token}");
41+
continue;
42+
}
43+
44+
if (value == -1)
45+
{
46+
stopReading = true;
47+
break;
48+
}
49+
50+
if (value < 0 || value > 100)
51+
{
52+
Console.WriteLine($"Ignoring out-of-range value: {value}");
53+
continue;
54+
}
55+
56+
values.Add(value);
57+
buckets[BucketForScore(value)]++;
3858
}
3959

40-
if (value < 0 || value > 100)
60+
if (stopReading)
4161
{
42-
Console.WriteLine($"Ignoring out-of-range value: {value}");
43-
continue;
62+
break;
4463
}
45-
46-
values.Add(value);
47-
buckets[BucketForScore(value)]++;
4864
}
4965

5066
if (values.Count == 0)

languages/go/assessments/02-core/main.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,37 @@ func main() {
3636

3737
fmt.Println("Enter integer values (0-100). End with -1.")
3838
scanner := bufio.NewScanner(os.Stdin)
39+
stopReading := false
3940
for scanner.Scan() {
4041
text := strings.TrimSpace(scanner.Text())
41-
value, parseErr := strconv.Atoi(text)
42-
if parseErr != nil {
43-
fmt.Println("Invalid input. Stopping read.")
44-
break
42+
tokens := strings.Fields(text)
43+
if len(tokens) == 0 {
44+
continue
4545
}
4646

47-
if value == -1 {
48-
break
49-
}
50-
if value < 0 || value > 100 {
51-
fmt.Printf("Ignoring out-of-range value: %d\n", value)
52-
continue
47+
for _, token := range tokens {
48+
value, parseErr := strconv.Atoi(token)
49+
if parseErr != nil {
50+
fmt.Printf("Ignoring invalid token: %s\n", token)
51+
continue
52+
}
53+
54+
if value == -1 {
55+
stopReading = true
56+
break
57+
}
58+
if value < 0 || value > 100 {
59+
fmt.Printf("Ignoring out-of-range value: %d\n", value)
60+
continue
61+
}
62+
63+
values = append(values, value)
64+
buckets[bucketForScore(value)]++
5365
}
5466

55-
values = append(values, value)
56-
buckets[bucketForScore(value)]++
67+
if stopReading {
68+
break
69+
}
5770
}
5871

5972
if len(values) == 0 {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$root = Split-Path -Parent $PSScriptRoot
4+
Set-Location $root
5+
6+
$checkpointKinds = @("projects", "assessments")
7+
$languages = @("cpp", "csharp", "go", "python")
8+
$requiredMainByLanguage = @{
9+
csharp = "main.cs"
10+
go = "main.go"
11+
python = "main.py"
12+
}
13+
14+
$failures = @()
15+
$checkpointCount = 0
16+
17+
foreach ($language in $languages) {
18+
$langRoot = Join-Path $root "languages/$language"
19+
if (-not (Test-Path $langRoot)) {
20+
continue
21+
}
22+
23+
foreach ($kind in $checkpointKinds) {
24+
$kindPath = Join-Path $langRoot $kind
25+
if (-not (Test-Path $kindPath)) {
26+
continue
27+
}
28+
29+
$checkpointDirs = Get-ChildItem -Path $kindPath -Directory
30+
foreach ($checkpoint in $checkpointDirs) {
31+
$checkpointCount++
32+
33+
$readmePath = Join-Path $checkpoint.FullName "README.md"
34+
if (-not (Test-Path $readmePath)) {
35+
$failures += "$($checkpoint.FullName): missing README.md"
36+
}
37+
38+
if ($requiredMainByLanguage.ContainsKey($language)) {
39+
$mainPath = Join-Path $checkpoint.FullName $requiredMainByLanguage[$language]
40+
if (-not (Test-Path $mainPath)) {
41+
$failures += "$($checkpoint.FullName): missing $($requiredMainByLanguage[$language])"
42+
}
43+
}
44+
45+
if ($language -eq "csharp") {
46+
$csprojFiles = Get-ChildItem -Path $checkpoint.FullName -Filter *.csproj -File
47+
if ($csprojFiles.Count -eq 0) {
48+
$failures += "$($checkpoint.FullName): missing .csproj file"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
55+
if ($checkpointCount -eq 0) {
56+
Write-Host "No checkpoint directories found for completeness validation."
57+
exit 1
58+
}
59+
60+
if ($failures.Count -gt 0) {
61+
Write-Host "Checkpoint completeness validation failed:"
62+
$failures | ForEach-Object { Write-Host " - $_" }
63+
exit 1
64+
}
65+
66+
Write-Host "Checkpoint completeness validation passed for $checkpointCount checkpoint directories."
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
cd "$ROOT_DIR"
6+
7+
checkpoint_kinds=("projects" "assessments")
8+
languages=("cpp" "csharp" "go" "python")
9+
10+
main_for_language() {
11+
case "$1" in
12+
csharp) echo "main.cs" ;;
13+
go) echo "main.go" ;;
14+
python) echo "main.py" ;;
15+
*) echo "" ;;
16+
esac
17+
}
18+
19+
failures=0
20+
checkpoint_count=0
21+
22+
for language in "${languages[@]}"; do
23+
lang_root="./languages/$language"
24+
[[ -d "$lang_root" ]] || continue
25+
26+
main_file_name="$(main_for_language "$language")"
27+
for kind in "${checkpoint_kinds[@]}"; do
28+
kind_path="$lang_root/$kind"
29+
[[ -d "$kind_path" ]] || continue
30+
31+
while IFS= read -r checkpoint_dir; do
32+
checkpoint_count=$((checkpoint_count + 1))
33+
34+
if [[ ! -f "$checkpoint_dir/README.md" ]]; then
35+
echo "Checkpoint completeness failed: $checkpoint_dir missing README.md"
36+
failures=1
37+
fi
38+
39+
if [[ -n "$main_file_name" && ! -f "$checkpoint_dir/$main_file_name" ]]; then
40+
echo "Checkpoint completeness failed: $checkpoint_dir missing $main_file_name"
41+
failures=1
42+
fi
43+
44+
if [[ "$language" == "csharp" ]]; then
45+
shopt -s nullglob
46+
csproj_files=("$checkpoint_dir"/*.csproj)
47+
shopt -u nullglob
48+
if [[ "${#csproj_files[@]}" -eq 0 ]]; then
49+
echo "Checkpoint completeness failed: $checkpoint_dir missing .csproj file"
50+
failures=1
51+
fi
52+
fi
53+
done < <(find "$kind_path" -mindepth 1 -maxdepth 1 -type d | sort)
54+
done
55+
done
56+
57+
if (( checkpoint_count == 0 )); then
58+
echo "No checkpoint directories found for completeness validation."
59+
exit 1
60+
fi
61+
62+
if (( failures != 0 )); then
63+
exit 1
64+
fi
65+
66+
echo "Checkpoint completeness validation passed for $checkpoint_count checkpoint directories."

scripts/smoke-languages.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ finally {
128128
Push-Location languages/go/assessments/02-core
129129
try {
130130
$goAssessment02Input = Join-Path $env:TEMP ("go-assessment-02-" + [Guid]::NewGuid().ToString("N") + ".txt")
131-
@("91", "88", "72", "105", "60", "-1") | Set-Content -Path $goAssessment02Input
131+
@("12 17 31 77 91 105 64 -3 88 -1") | Set-Content -Path $goAssessment02Input
132132
Get-Content $goAssessment02Input | go run main.go | Out-Null
133133
if (-not (Test-Path "core_assessment_report.txt")) {
134134
throw "Go 02-core assessment did not create core_assessment_report.txt"
@@ -193,7 +193,7 @@ finally {
193193
Push-Location languages/csharp/assessments/02-core
194194
try {
195195
$csharpAssessment02Input = Join-Path $env:TEMP ("csharp-assessment-02-" + [Guid]::NewGuid().ToString("N") + ".txt")
196-
@("91", "88", "72", "105", "60", "-1") | Set-Content -Path $csharpAssessment02Input
196+
@("12 17 31 77 91 105 64 -3 88 -1") | Set-Content -Path $csharpAssessment02Input
197197
Get-Content $csharpAssessment02Input | dotnet run --project assessment-02-core.csproj | Out-Null
198198
if (-not (Test-Path "core_assessment_report.txt")) {
199199
throw "C# 02-core assessment did not create core_assessment_report.txt"

scripts/smoke-languages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ EOF
101101
)
102102
(
103103
cd languages/go/assessments/02-core
104-
printf '91\n88\n72\n105\n60\n-1\n' | go run main.go >/dev/null
104+
printf '12 17 31 77 91 105 64 -3 88 -1\n' | go run main.go >/dev/null
105105
[[ -f core_assessment_report.txt ]]
106106
rm -f core_assessment_report.txt
107107
)
@@ -139,7 +139,7 @@ EOF
139139
)
140140
(
141141
cd languages/csharp/assessments/02-core
142-
printf '91\n88\n72\n105\n60\n-1\n' | dotnet run --project assessment-02-core.csproj >/dev/null
142+
printf '12 17 31 77 91 105 64 -3 88 -1\n' | dotnet run --project assessment-02-core.csproj >/dev/null
143143
[[ -f core_assessment_report.txt ]]
144144
rm -f core_assessment_report.txt
145145
)

scripts/verify-repo.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ function Assert-LastExitCode([string]$action) {
1010
}
1111
}
1212

13-
Write-Host "[1/4] Checking markdown links..."
13+
Write-Host "[1/5] Checking markdown links..."
1414
& "$PSScriptRoot\check-links.ps1"
1515
Assert-LastExitCode "Markdown link check"
1616

17-
Write-Host "[2/4] Checking README structure..."
17+
Write-Host "[2/5] Checking README structure..."
1818
& "$PSScriptRoot\check-readme-structure.ps1"
1919
Assert-LastExitCode "README structure check"
2020

21-
Write-Host "[3/4] Checking module completeness..."
21+
Write-Host "[3/5] Checking module completeness..."
2222
& "$PSScriptRoot\check-module-completeness.ps1"
2323
Assert-LastExitCode "Module completeness check"
2424

25-
Write-Host "[4/4] Compiling C++ files..."
25+
Write-Host "[4/5] Checking checkpoint completeness..."
26+
& "$PSScriptRoot\check-checkpoint-completeness.ps1"
27+
Assert-LastExitCode "Checkpoint completeness check"
28+
29+
Write-Host "[5/5] Compiling C++ files..."
2630
& "$PSScriptRoot\build-all.ps1"
2731
Assert-LastExitCode "C++ build"
2832

0 commit comments

Comments
 (0)