Skip to content

anurag5sh/cses-go-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CSES Go Runner v1.0

A specialized CLI tool for running and testing CSES (Code Submission Evaluation System) problems with GoLang solutions. Now with direct CSES authentication and test case downloading!

New Features in v1.0

  • πŸ” Direct CSES Authentication - Login with your CSES credentials
  • πŸ“₯ Official Test Case Download - Download test cases directly from CSES
  • πŸ”„ Auto Re-authentication - Automatically handles session expiration
  • πŸ“¦ Zip File Processing - Extract and process test cases from CSES zip files

Features

  • πŸš€ Go-optimized: Built specifically for Go solutions
  • πŸ§ͺ Parallel test execution with configurable concurrency
  • πŸ“¦ Direct CSES integration with official test cases
  • πŸ’Ύ Smart caching system for faster subsequent runs
  • 🎨 Beautiful colorized output with detailed progress reporting
  • ⚑ Timeout handling with context-based cancellation
  • πŸ“Š Comprehensive result reporting with performance metrics
  • πŸ” Verbose mode for debugging and optimization
  • 🧹 Cache management utilities
  • 🏁 Race detection support for concurrent programs

Installation

Quick Install

curl -sSL https://raw.githubusercontent.com/anurag5sh/cses-go-runner/main/install.sh | bash

Manual Install

git clone https://github.com/anurag5sh/cses-go-runner.git
cd cses-go-runner
go mod tidy
go build -ldflags="-s -w" -o cses-go-runner .

Using Make

make build-optimized
make install  # Optional: install to /usr/local/bin

Setup

Environment Variables

Set your CSES credentials:

export CSES_USERNAME='your_username'
export CSES_PASSWORD='your_password'

Authentication

Authenticate with CSES:

cses-go-runner auth

Usage

Basic Usage

# Authenticate first
cses-go-runner auth

# Run tests
cses-go-runner -file=solution.go -problem=1068

Commands

# Authenticate with CSES
cses-go-runner auth

# Run tests (default command)
cses-go-runner -file=solution.go -problem=1068

# Run tests with explicit command
cses-go-runner run -file=solution.go -problem=1068

# Clean cache
cses-go-runner clean

Advanced Usage

# With verbose output and diff display
cses-go-runner -file=solution.go -problem=1068 -verbose -diff

# With custom timeout and parallel execution
cses-go-runner -file=solution.go -problem=1068 -timeout=5s -parallel=8

# With race detection (for concurrent programs)
cses-go-runner -file=solution.go -problem=1068 -race

# Force re-authentication
cses-go-runner -file=solution.go -problem=1068 -force-auth

Available Options

Flag Description Default
-file Path to Go solution file -
-problem CSES problem ID -
-timeout Timeout per test case 1s
-verbose Enable verbose output false
-cache-dir Cache directory ./cses-cache
-parallel Number of parallel executions 4
-diff Show diff for failed tests false
-max-output Maximum output length to display 1000
-optimize Enable compiler optimizations true
-race Enable race detector false
-force-auth Force re-authentication false
-help Show help message false
-version Show version false

Authentication Flow

  1. Set Environment Variables:

    export CSES_USERNAME='your_username'
    export CSES_PASSWORD='your_password'
  2. Authenticate:

    cses-go-runner auth
  3. Use Normally:

    cses-go-runner -file=solution.go -problem=1068

The tool will automatically:

  • Check for valid authentication before running tests
  • Re-authenticate if the session expires
  • Download test cases directly from CSES
  • Cache everything for offline development

Test Case Download

The tool downloads test cases directly from CSES using the official API:

  • URL: https://cses.fi/problemset/tests/{problem_id}/
  • Method: POST request with CSRF token and session ID
  • Format: ZIP file containing input/output pairs
  • Caching: Automatically cached for subsequent runs

Output Format

πŸš€ Starting CSES Go Test Runner for problem 1068
πŸ“ Solution file: solution.go
πŸ” go version go1.21.0 linux/amd64
πŸ“₯ Fetching test cases from CSES...
πŸ“¦ Extracted 15 test cases from zip file
πŸ’Ύ Cached 15 test cases to ./cses-cache/1068
βœ… Found 15 test cases
πŸ”¨ Compiling Go solution...
βœ… Compilation successful
πŸ§ͺ Running 15 test cases (parallel: 4)...
⏱️  Total execution time: 0.25s

============================================================
πŸ“Š TEST RESULTS SUMMARY
============================================================
βœ… PASSED: 15/15 tests
⏱️  Average execution time: 16.67ms

============================================================
πŸŽ‰ ALL TESTS PASSED! πŸŽ‰
============================================================

Cache Structure

cses-cache/
β”œβ”€β”€ .auth/
β”‚   └── session.json          # Authentication session
β”œβ”€β”€ 1068/
β”‚   β”œβ”€β”€ 1.in
β”‚   β”œβ”€β”€ 1.out
β”‚   β”œβ”€β”€ 2.in
β”‚   β”œβ”€β”€ 2.out
β”‚   └── ...
└── 1083/
    β”œβ”€β”€ 1.in
    β”œβ”€β”€ 1.out
    └── ...

Example Go Solutions

Weird Algorithm (Problem 1068)

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	
	var result []string
	for n != 1 {
		result = append(result, strconv.Itoa(n))
		if n%2 == 0 {
			n = n / 2
		} else {
			n = n*3 + 1
		}
	}
	result = append(result, "1")
	
	fmt.Println(strings.Join(result, " "))
}

Troubleshooting

Authentication Issues

# Check environment variables
echo $CSES_USERNAME
echo $CSES_PASSWORD

# Force re-authentication
cses-go-runner auth -force-auth

# Check verbose output
cses-go-runner -file=solution.go -problem=1068 -verbose

Test Case Issues

# Clean cache and retry
cses-go-runner clean
cses-go-runner -file=solution.go -problem=1068

Common Error Messages

  • authentication required - Run cses-go-runner auth first
  • session expired - Tool will automatically re-authenticate
  • failed to download test cases - Check your internet connection and credentials

Security Notes

  • Credentials are only stored in environment variables
  • Session tokens are stored locally in cses-cache/.auth/session.json
  • Use cses-go-runner clean to remove all cached data including sessions
  • Never commit your credentials to version control

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test with various Go solutions
  4. Submit a pull request

License

MIT License - see LICENSE file for details

About

Run CSES Problem set in Golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published