summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2025-06-24 11:06:59 +0200
committerYuval Adam <_@yuv.al>2025-06-24 11:06:59 +0200
commit0357929946dbaa437637d75310a6e819481a5925 (patch)
tree918429cf942e0d1a49e026d528c73adc8aa00b54
parentb9e321ff444970998a43cbf581648b3a15111804 (diff)
Add CI and some clippy cleanup
-rw-r--r--.github/workflows/ci.yml50
-rw-r--r--README.md3
-rw-r--r--src/decoder.rs8
-rw-r--r--src/generator.rs2
-rw-r--r--src/main.rs2
5 files changed, 59 insertions, 6 deletions
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;