test(domain): write failing tests for RelayId newtype validation
Tests cover validation requirements for the RelayId newtype: - Valid relay IDs (1-8 for 8-channel controller) - Invalid IDs outside valid range - Smart constructor error handling - Type-safe ID representation TDD red phase: Tests fail until RelayId is implemented. Ref: T017 (specs/001-modbus-relay-control/tasks.md)
This commit is contained in:
@@ -12,3 +12,45 @@ impl std::fmt::Display for RelayId {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_relay_id_new_valid_lower_bound() {
|
||||
// Test: RelayId::new(1) → Ok(RelayId(1))
|
||||
let result = RelayId::new(1);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), RelayId(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relay_id_new_valid_upper_bound() {
|
||||
// Test: RelayId::new(8) → Ok(RelayId(8))
|
||||
let result = RelayId::new(8);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), RelayId(8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relay_id_new_invalid_zero() {
|
||||
// Test: RelayId::new(0) → Err(InvalidRelayId)
|
||||
let result = RelayId::new(0);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relay_id_new_invalid_nine() {
|
||||
// Test: RelayId::new(9) → Err(InvalidRelayId)
|
||||
let result = RelayId::new(9);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relay_id_as_u8_returns_inner_value() {
|
||||
// Test: RelayId::as_u8() returns inner value
|
||||
let relay_id = RelayId(5);
|
||||
assert_eq!(relay_id.as_u8(), 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
|
||||
**⚠️ TDD CRITICAL**: Write failing tests FIRST for every type, then implement
|
||||
|
||||
- [ ] **T017** [US1] [TDD] Write tests for RelayId newtype
|
||||
- [x] **T017** [US1] [TDD] Write tests for RelayId newtype
|
||||
- Test: RelayId::new(1) → Ok(RelayId(1))
|
||||
- Test: RelayId::new(8) → Ok(RelayId(8))
|
||||
- Test: RelayId::new(0) → Err(InvalidRelayId)
|
||||
|
||||
Reference in New Issue
Block a user