Initial commit
This commit is contained in:
173
srcs/RobotNet10/Tests/RobotNet10.NavigationTune.Test/README.md
Normal file
173
srcs/RobotNet10/Tests/RobotNet10.NavigationTune.Test/README.md
Normal file
@@ -0,0 +1,173 @@
|
||||
# Unit Tests - RobotNet10.NavigationTune
|
||||
|
||||
Thư mục này chứa các unit tests cho project `RobotNet10.NavigationTune`.
|
||||
|
||||
## 📁 Cấu trúc Tests
|
||||
|
||||
```
|
||||
RobotNet10.NavigationTune.Test/
|
||||
├── Helpers/
|
||||
│ └── TestHelpers.cs # Helper methods để tạo test data
|
||||
├── Navigation/
|
||||
│ └── Core/
|
||||
│ ├── PIDTests.cs # Tests cho PID controller
|
||||
│ ├── MotorDynamicsModelTests.cs # Tests cho Motor Dynamics Model
|
||||
│ └── PurePursuitSimplifiedTests.cs # Tests cho Pure Pursuit
|
||||
├── Services/
|
||||
│ ├── MetricsCalculatorTests.cs # Tests cho Metrics Calculator
|
||||
│ └── ParameterManagerTests.cs # Tests cho Parameter Manager
|
||||
├── Scenarios/
|
||||
│ ├── StraightLineScenarioTests.cs # Tests cho Straight Line Scenario
|
||||
│ └── CircleScenarioTests.cs # Tests cho Circle Scenario
|
||||
└── README.md # File này
|
||||
```
|
||||
|
||||
## 🧪 Test Coverage
|
||||
|
||||
### ✅ Đã được test
|
||||
|
||||
1. **PID Controller**
|
||||
- Constructor với config
|
||||
- PID_step với zero error
|
||||
- Proportional term
|
||||
- Integral term accumulation
|
||||
- Derivative term
|
||||
- Clamping to max/min
|
||||
- Reset functionality
|
||||
- WithKp, WithKi, WithKd methods
|
||||
|
||||
2. **Motor Dynamics Model**
|
||||
- Constructor với default và config values
|
||||
- PredictVelocity với time before/after delay
|
||||
- PredictVelocity với long time
|
||||
- GetSettlingTime calculation
|
||||
- GetRiseTime calculation
|
||||
- Decreasing command velocity
|
||||
- ToString method
|
||||
|
||||
3. **Pure Pursuit Simplified**
|
||||
- Constructor và SetPath
|
||||
- CalculateAngularVelocity với straight path
|
||||
- CalculateAngularVelocity với curved path
|
||||
- GetCurrentLookahead với low/high velocity
|
||||
- Low confidence handling
|
||||
|
||||
4. **Metrics Calculator**
|
||||
- CalculateMetrics với empty telemetry
|
||||
- Perfect tracking scenario
|
||||
- Tracking errors calculation
|
||||
- Smoothness metrics
|
||||
- Efficiency metrics
|
||||
- Overall score calculation
|
||||
- Goal errors calculation
|
||||
|
||||
5. **Parameter Manager**
|
||||
- Validate với valid parameters
|
||||
- Validate với negative Kp/Ki
|
||||
- Validate với invalid lookahead range
|
||||
- GetDefaultPreset
|
||||
- GetAggressivePreset
|
||||
- GetSmoothPreset
|
||||
- Validate với invalid blend ratio
|
||||
- Validate với invalid velocity limits
|
||||
|
||||
6. **Test Scenarios**
|
||||
- StraightLineScenario: GenerateReferencePath, IsGoalReached, GetGoalPose
|
||||
- CircleScenario: GenerateReferencePath, IsGoalReached, GetGoalPose, radius validation
|
||||
|
||||
## 🚀 Chạy Tests
|
||||
|
||||
### Sử dụng Visual Studio
|
||||
1. Mở Test Explorer (Test → Test Explorer)
|
||||
2. Build solution
|
||||
3. Chọn tests cần chạy và click "Run"
|
||||
|
||||
### Sử dụng dotnet CLI
|
||||
```bash
|
||||
cd srcs/RobotNet10/Tests/RobotNet10.NavigationTune.Test
|
||||
dotnet test
|
||||
```
|
||||
|
||||
### Chạy tests cụ thể
|
||||
```bash
|
||||
dotnet test --filter "FullyQualifiedName~PIDTests"
|
||||
dotnet test --filter "FullyQualifiedName~MetricsCalculatorTests"
|
||||
```
|
||||
|
||||
### Chạy với coverage
|
||||
```bash
|
||||
dotnet test --collect:"XPlat Code Coverage"
|
||||
```
|
||||
|
||||
## 📊 Test Statistics
|
||||
|
||||
- **Total Tests**: 40+ test cases
|
||||
- **Test Framework**: xUnit
|
||||
- **Assertion Library**: FluentAssertions
|
||||
- **Mocking Framework**: Moq (for future use)
|
||||
- **Coverage Areas**:
|
||||
- Core navigation controllers
|
||||
- Metrics calculation
|
||||
- Parameter validation
|
||||
- Test scenarios
|
||||
|
||||
## 🛠️ Test Helpers
|
||||
|
||||
`TestHelpers.cs` cung cấp các helper methods để tạo test data:
|
||||
|
||||
- `CreateDefaultParameterSet()` - Default parameter set
|
||||
- `CreateCustomParameterSet()` - Custom parameter set với specified values
|
||||
- `CreateStraightLineScenario()` - Straight line scenario
|
||||
- `CreateCircleScenario()` - Circle scenario
|
||||
- `CreateSimplePath()` - Simple reference path
|
||||
- `CreateTelemetryData()` - Single telemetry data point
|
||||
- `CreateTelemetryHistory()` - List of telemetry data points
|
||||
|
||||
## 📝 Best Practices
|
||||
|
||||
1. **AAA Pattern**: Arrange, Act, Assert
|
||||
2. **Test Isolation**: Mỗi test độc lập, không phụ thuộc vào test khác
|
||||
3. **Meaningful Names**: Tên test mô tả rõ behavior được test
|
||||
4. **Test Data**: Sử dụng TestHelpers để tạo consistent test data
|
||||
5. **Edge Cases**: Test cả success và failure scenarios
|
||||
6. **Floating Point**: Sử dụng `BeApproximately` cho floating point comparisons
|
||||
|
||||
## 🔍 Test Categories
|
||||
|
||||
### Unit Tests
|
||||
- Test từng component riêng biệt
|
||||
- Mock dependencies nếu cần
|
||||
- Fast execution
|
||||
|
||||
### Integration Tests (Future)
|
||||
- Test interaction giữa các components
|
||||
- Test với real data
|
||||
- Test end-to-end scenarios
|
||||
|
||||
## 📈 Coverage Goals
|
||||
|
||||
- [x] PID Controller: ~90%
|
||||
- [x] Motor Dynamics Model: ~90%
|
||||
- [x] Pure Pursuit Simplified: ~80%
|
||||
- [x] Metrics Calculator: ~85%
|
||||
- [x] Parameter Manager: ~90%
|
||||
- [x] Test Scenarios: ~90%
|
||||
- [ ] Velocity Estimator Simplified: Pending
|
||||
- [ ] Safety Monitor: Pending
|
||||
- [ ] Test Executor: Pending (requires mocking)
|
||||
- [ ] Tuning Navigation: Pending (requires mocking)
|
||||
|
||||
## 🐛 Known Issues
|
||||
|
||||
- Một số tests phụ thuộc vào floating point precision
|
||||
- Tests cho TestExecutor và TuningNavigation cần mocking của ILocalizationProvider và IVelocityProvider
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
Khi thêm tests mới:
|
||||
|
||||
1. Follow naming convention: `MethodName_Scenario_ExpectedBehavior`
|
||||
2. Sử dụng TestHelpers cho test data
|
||||
3. Sử dụng FluentAssertions cho assertions
|
||||
4. Test cả success và failure cases
|
||||
5. Document any special test setup requirements
|
||||
Reference in New Issue
Block a user