Skip to content

Commit fbde6c3

Browse files
authored
refactor: implement dynamic edge case tests with improved organization (#3)
- Split integration tests into focused test files (basic_filter_tests.rs, edge_case_tests.rs) - Replace static test data with dynamic generation based on current time - Add comprehensive boundary testing for 7-day and 90-day filtering rules - Implement self-documenting test cases with clear business rule descriptions - Enhance test output formatting with aligned columns for better - readability
1 parent 679dd4c commit fbde6c3

File tree

5 files changed

+251
-147
lines changed

5 files changed

+251
-147
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
88

99
## [Unreleased]
1010

11+
### Changed
12+
- **Test Organization**: Split integration tests into focused test files
13+
- `tests/basic_filter_tests.rs` - Core integration tests with static test data
14+
- `tests/edge_case_tests.rs` - Dynamic boundary condition tests
15+
- **Test Infrastructure Enhancement**: Implemented dynamic test data generation
16+
- Added comprehensive boundary testing for time-based filtering rules
17+
- Self-documenting test cases with clear business rule descriptions
18+
- **Enhanced Test Reporting**: Added aligned, formatted test output for better readability
19+
20+
### Technical
21+
- Improved test maintainability with descriptive entity names and test descriptions
22+
23+
---
24+
1125
## [0.2.0] – 2025-06-28
1226

1327
### Added

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ src/
2929
├── main.rs ← Lambda entry point & business logic
3030
├── domain.rs ← Domain entities (Action, Priority)
3131
tests/
32-
├── integration_tests.rs ← End-to-end lambda testing
32+
├── basic_filter_tests.rs ← Core integration tests with static data
33+
├── edge_case_tests.rs ← Dynamic boundary condition tests
3334
testdata/
3435
├── *.json ← Test input files
3536
scripts/
@@ -82,17 +83,38 @@ The Lambda applies these filtering and processing rules:
8283
- Deduplication behavior with priority conflicts
8384
- Date parsing and filtering logic
8485

85-
### Integration Tests (`tests/integration_tests.rs`)
86+
### Integration Tests
87+
88+
**Basic Integration Tests (`tests/basic_filter_tests.rs`)**
8689
- **Real lambda execution** using `cargo lambda invoke`
8790
- **End-to-end validation** from JSON input to JSON output
8891
- **Error handling** verification (invalid enum variants)
8992
- **Order-agnostic testing** for robust HashMap-based results
9093

94+
**Dynamic Edge Case Tests (`tests/edge_case_tests.rs`)**
95+
- **Boundary condition testing** with dynamic test data generation
96+
- **Comprehensive business rule validation** (7-day/90-day boundaries)
97+
- **Self-documenting test cases** with clear descriptions
98+
- **Time-independent testing** that works regardless of execution date
99+
91100
**Test Data Files:**
92101
- `01_sample-input.json` - Basic filtering and deduplication
93102
- `02_priority-input.json` - Priority sorting validation
94103
- `03_bad-input.json` - Error handling (invalid priority variant)
95-
- `04_edge-cases.json` - Boundary conditions and complex scenarios
104+
105+
### Running Tests
106+
107+
```bash
108+
# Run all tests
109+
cargo test
110+
111+
# Run specific test suites
112+
cargo test --test basic_filter_tests # Basic integration tests
113+
cargo test --test edge_case_tests # Dynamic edge case tests
114+
115+
# Run unit tests only
116+
cargo test --lib
117+
```
96118

97119
## 🚀 Usage
98120

testdata/04_edge-cases.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/integration_tests.rs renamed to tests/basic_filter_tests.rs

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -177,100 +177,6 @@ fn test_bad_input_integration() -> Result<()> {
177177
Ok(())
178178
}
179179

180-
#[test]
181-
fn test_edge_case_filtering() -> Result<()> {
182-
// ---
183-
// Test edge cases around the 7-day and 90-day boundaries, plus deduplication
184-
let actions = run_lambda_invoke("testdata/04_edge-cases.json")?;
185-
186-
// Based on the test data (assuming current date around 2025-06-27):
187-
// - exactly_7_days: last_action 2025-06-20 (exactly 7 days ago) -> SHOULD PASS
188-
// - exactly_90_days: next_action 2025-09-25 (exactly 90 days away) -> SHOULD PASS
189-
// - just_over_7_days: last_action 2025-06-19 (8 days ago) -> SHOULD PASS
190-
// - just_under_90_days: next_action 2025-09-24 (89 days away) -> SHOULD PASS
191-
// - duplicate_entity (urgent): first occurrence -> SHOULD BE DEDUPLICATED OUT
192-
// - duplicate_entity (normal): second occurrence -> SHOULD PASS (last one wins)
193-
// - too_recent: last_action 2025-06-21 (6 days ago) -> SHOULD BE FILTERED OUT
194-
// - too_far_future: next_action 2025-09-26 (exactly 90 days away) -> SHOULD PASS
195-
196-
// We expect 6 actions after filtering and deduplication:
197-
// 8 input - 1 too_recent (filtered) - 1 duplicate removed = 6
198-
ensure!(
199-
actions.len() == 6,
200-
"Expected 6 actions to pass edge case filters, got {}",
201-
actions.len()
202-
);
203-
204-
// Verify the specific actions that should pass
205-
let entity_ids: Vec<&String> = actions.iter().map(|a| &a.entity_id).collect();
206-
let expected_ids = vec![
207-
"exactly_7_days",
208-
"exactly_90_days",
209-
"just_over_7_days",
210-
"just_under_90_days",
211-
"duplicate_entity",
212-
"too_far_future", // <-- included because it's exactly 90 days and code uses `<=`
213-
];
214-
215-
for expected_id in &expected_ids {
216-
ensure!(
217-
entity_ids.iter().any(|id| id == expected_id),
218-
"Expected to find entity_id '{}' in results, but didn't",
219-
expected_id
220-
);
221-
}
222-
223-
// Verify the filtered out actions are not present
224-
let filtered_ids = vec!["too_recent"];
225-
for filtered_id in &filtered_ids {
226-
ensure!(
227-
!entity_ids.iter().any(|id| id == filtered_id),
228-
"Expected entity_id '{}' to be filtered out, but found it in results",
229-
filtered_id
230-
);
231-
}
232-
233-
// Verify deduplication: duplicate_entity should appear exactly once
234-
let duplicate_count = entity_ids.iter().filter(|&id| *id == "duplicate_entity").count();
235-
ensure!(
236-
duplicate_count == 1,
237-
"Expected exactly 1 occurrence of 'duplicate_entity', found {}",
238-
duplicate_count
239-
);
240-
241-
// Verify that the duplicate_entity kept the LAST occurrence (normal priority)
242-
let duplicate_action = actions.iter().find(|a| a.entity_id == "duplicate_entity").unwrap();
243-
ensure!(
244-
duplicate_action.priority == Priority::Normal,
245-
"Expected duplicate_entity to keep the last occurrence (normal), but got {:?}",
246-
duplicate_action.priority
247-
);
248-
249-
// Verify priority sorting (urgent before normal)
250-
let mut seen_normal = false;
251-
for action in &actions {
252-
if action.priority == Priority::Normal {
253-
seen_normal = true;
254-
} else if action.priority == Priority::Urgent && seen_normal {
255-
panic!("Found urgent priority after normal priority - sorting is incorrect");
256-
}
257-
}
258-
259-
println!("Edge case filtering test passed:");
260-
println!(" {} actions passed the time filters", actions.len());
261-
println!(" Deduplication verified: duplicate_entity kept last occurrence (normal)");
262-
for (i, action) in actions.iter().enumerate() {
263-
println!(
264-
" {}. {} ({})",
265-
i + 1,
266-
action.entity_id,
267-
if action.priority == Priority::Urgent { "urgent" } else { "normal" }
268-
);
269-
}
270-
271-
Ok(())
272-
}
273-
274180
#[test]
275181
fn test_empty_input_array() -> Result<()> {
276182
// ---

0 commit comments

Comments
 (0)