From 0357929946dbaa437637d75310a6e819481a5925 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 24 Jun 2025 11:06:59 +0200 Subject: Add CI and some clippy cleanup --- .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 3 +++ src/decoder.rs | 8 ++++---- src/generator.rs | 2 +- src/main.rs | 2 +- 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..126f4a2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Cache cargo + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Build + run: cargo build --verbose + + - name: Run all tests + run: cargo test --verbose + + - name: Run comprehensive test suite + run: cargo test run_comprehensive_test_suite --verbose -- --nocapture + + - name: Test release build + run: cargo build --release \ No newline at end of file diff --git a/README.md b/README.md index b75013a..a19d4ae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # ditdah - Morse Code Decoder +[![CI](https://github.com/yuvadm/ditdah/workflows/CI/badge.svg)](https://github.com/yuvadm/ditdah/actions) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + A high-performance Rust implementation of a Morse code decoder that can process WAV audio files and decode them into text with **100% accuracy** on the comprehensive test suite. ## Features diff --git a/src/decoder.rs b/src/decoder.rs index 80458a0..1a217d3 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -1,8 +1,8 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use rubato::{ Resampler, SincFixedIn, SincInterpolationParameters, SincInterpolationType, WindowFunction, }; -use rustfft::{num_complex::Complex, FftPlanner}; +use rustfft::{FftPlanner, num_complex::Complex}; use std::collections::VecDeque; use std::io::Write; // --- DSP Constants --- @@ -552,8 +552,8 @@ fn trace_signal(signal: &[f32], threshold: f32, wpm: f32) -> std::io::Result<()> let bar_len = (val / max_val * 100.0).round() as usize; let thresh_pos = (threshold / max_val * 100.0).round() as usize; let mut line = vec![' '; 101]; - for i in 0..bar_len.min(100) { - line[i] = '#'; + for item in line.iter_mut().take(bar_len.min(100)) { + *item = '#'; } if thresh_pos <= 100 { line[thresh_pos] = '|'; diff --git a/src/generator.rs b/src/generator.rs index 7a21f07..13fa814 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -187,7 +187,7 @@ mod tests { let generator = MorseGenerator::new(12000, 600.0, 20.0); let result = generator.generate_wav_file("SOS", "test_sos.wav"); assert!(result.is_ok()); - + // Clean up test file std::fs::remove_file("test_sos.wav").ok(); } diff --git a/src/main.rs b/src/main.rs index 72869af..fdc0012 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::Parser; use hound::{SampleFormat, WavReader}; use std::path::PathBuf; -- cgit v1.3.1