Commit 35a9809
[WIP] Fix train position calculation: Replace position-based with identity-based separator matching (#349)
* Migrate MockTrainOccupant and MockTrackBlock to MockK (Phase 1)
Replace inline mock classes with MockK-based implementations to improve
test maintainability and leverage Kotlin-native mocking capabilities.
Changes:
- PathTrackIntegrationTest.kt:
* Remove MockTrainOccupant class (9 lines)
* Replace 7 usages with mockk<TrackOccupant>(relaxed=true)
* Clean up unused OrientedPathSeparator import
- DefaultRailWayNetGridTest.kt:
* Convert MockTrackBlock class to createMockTrackBlock() factory
* Reduce from 43 lines to ~20 with relaxed mocks
* Clean up unused imports (DynamicPathSeparator, PathElement, etc.)
Test results: 1845/1849 passing (0 failures, 4 skipped)
All integration tests passing (PathTrackIntegrationTest: 10/10)
All unit tests passing (DefaultRailWayNetGridTest)
Part of MockK migration plan (Issue #332, Phase 1 of 3)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Complete MockK migration Phase 2: remove Mockito dependency and migrate MockNodeCell
This completes the MockK migration by removing the Mockito framework dependency
and migrating all MockNodeCell usages to the createMockNodeCell() factory pattern.
Changes:
- Remove Mockito dependency from gradle.properties and build.gradle.kts
- Add createMockNodeCell() factory function in TrackTestMocks.kt
- Migrate 12 test files to use factory pattern (68+ usages total)
- Update MockNodeCell class to accept spatialType parameter
- Fix code style issues (long lines, unused imports)
All 1849 unit tests and 325 integration tests passing with zero regressions.
Follows Phase 1 pattern (createMockTrackBlock) for consistency. Issue #332.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Complete MockK migration Phase 3: migrate MockTrackOccupant to factory pattern
Phase 3 completes the MockK migration by converting MockTrackOccupant from a manual
mock class to a pure MockK factory function, following the pattern established in
Phases 1 and 2.
Changes:
- Add createMockTrackOccupant() factory in TrackTestMocks.kt
- Pure MockK implementation (TrackOccupant is interface)
- Provides defaults: name="MockTrain", distanceToSemaphore=100.0
- Uses mockk(relaxed=true) with this@mockk qualifiers
- Migrate 4 test files (15 usages total):
- SimpleTrackEnterLeaveTest.kt (2 usages)
- SimpleTrackStateTest.kt (2 usages)
- RaceConditionTest.kt (4 usages, integration tests)
- Remove MockTrackOccupant class (no longer needed)
- Update TrackTestMocks.kt documentation with Phase 3 entry
Final state after Phase 3:
- 3 factory functions: createMockTrackBlock, createMockNodeCell, createMockTrackOccupant
- 2 preserved classes: MockNodeCell (abstract base), MockSimulationContext (delegation)
- 0 Mockito dependencies
- Consistent factory pattern across all test mocks
Test results: 1845 unit tests passing, 307 integration tests passing, 0 failures.
Related: Issue #332 (MockK migration Phases 1-3 complete)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Complete MockK migration Phase 4: consolidate 17 inline mock factories
Consolidates all inline MockK factory functions from 4 test files into the
central TrackTestMocks.kt repository, completing the Phase 4 factory
consolidation plan.
Changes:
- Added 13 new factory functions to TrackTestMocks.kt
- Resolved 3 duplicate factories (2 merged, 1 split):
* createMockTrack() - merged with optional maxSpeed parameter
* createMockPath() - merged returning ArrayPath
* createMockSemaphore() - split into createMockSemaphoreReal() and
createMockSemaphoreMock() (incompatible implementations)
- Removed 157 lines of duplicated code from 4 test files:
* DeadlockDetectionTest.kt - removed 7 factories
* TrainPathInteractionTest.kt - removed 4 factories
* DefaultRailWayNetGridTest.kt - removed 1 factory
* AnimatedSimulationCellRendererTest.kt - removed 3 factories
- Organized into 5 categories:
* Track Facilities (6 factories)
* Semaphores (4 factories)
* Path & Network Elements (3 factories)
* Occupants & Nodes (2 factories)
* Mock Implementations (1 class)
Test results: ✅ All 1845 unit tests passing, 307 integration tests passing
Code quality: ✅ detekt and ktlintCheck passing
Outcome: Single centralized mock factory repository with consistent
organization. Zero test regressions. Issue #332 (Phases 1-4) complete.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* backup
* Fix Detekt failures: remove unused imports and migrate to PhysicsConstants (#360)
* Initial plan
* Fix Detekt issues: remove unused imports and update deprecated constants
- Remove unused imports from test files (AnimationIntegrationTest, StatusBarTest, etc.)
- Update deprecated constants to use domain.PhysicsConstants:
* COMMON_MAX_SPEED in BaseContext.kt
* MINIMAL_MAX_SPEED in AbstractPath.kt and SimpleTrack.kt
* MIN_TRACK_LENGTH in SimpleTrack.kt
- All Detekt checks now pass
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* Initial plan
* Fix train position calculation with identity-based separator matching and add lerp() to PointF
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* Add comprehensive tests for identity-based separator matching (Issue #324)
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* Fix type mismatch in TrainPositionCalculatorTest: Cast PathSeparator to DynamicPathSeparator
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* Fix type inference error: Add non-null assertion for differentSeparator in test
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* Fix compilation error: Replace getAllCells() with iterator-based cell collection
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
* fix detekt
* fix compile
* fix: resolve build failures in PR #349 test files
- TrackTestMocks.kt: remove duplicate function definitions (entire factory
function set was accidentally duplicated, causing overload ambiguity)
- MenuBarTest.kt: add missing isNotNull import from assertk.assertions
- AbstractPathTest.kt, ArrayPathTest.kt: remove duplicate createMockNodeCell
import (caused detekt NoUnusedImports violation)
All 1999 tests pass, detekt and ktlint clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test: add lerp() unit tests for PointF to meet SonarCloud coverage gate
Add 5 parameterized-style tests covering t=0 (returns start), t=1 (returns
end), t=0.5 (midpoint), t=0.25 (quarter point), and equal-points identity.
Brings PointF line coverage to 100% (was 66.7%), satisfying the ≥80%
SonarCloud quality gate requirement for PR #349.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: remove dead positionsMatch() method and unused abs import
The identity-based comparison (===) introduced in the previous commit
made positionsMatch() unreachable. Remove the dead method, its
POSITION_MATCH_EPSILON constant, the empty companion object, and the
now-unused 'import kotlin.math.abs'.
This fixes the SonarCloud C Reliability Rating on new code caused by
the dead private method.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: address Copilot review comments on PR #349
- Fix import ordering in AbstractPathTest.kt and ArrayPathTest.kt:
MockSimulationContext now appears before createMockNodeCell (alphabetical)
- Strengthen consistentOrderWithEntrySeparator test: use 25% asymmetric
position instead of 50% midpoint, then assert the two trains' positions
differ by > 0.1 grid cells — verifies direction selection actually matters
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: address remaining code review issues on PR #349
- Use PointF.lerp() in TrainPositionCalculator instead of inline arithmetic
(the method was added by this PR but not yet called in production code)
- Update stale comment: "Try both orderings" → explain identity comparison
- Assert as? DynamicPathSeparator casts succeed in tests before use
(prevents silent null from masking a wrong code path being exercised)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: address remaining code review issues on PR #349
- Replace lerp() call with direct arithmetic to avoid 2 extra PointF
allocations in the 30fps hot path
- Strengthen identity-separator tests: use ratio=0.25 (asymmetric) and
assert directional closeness instead of trivial x/y >= 0 checks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Bedrich Hovorka <bedrich.hovorka@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>1 parent 20d600f commit 35a9809
5 files changed
Lines changed: 296 additions & 59 deletions
File tree
- src
- main/kotlin/cz/vutbr/fit/interlockSim
- gui/animation
- util
- test/kotlin/cz/vutbr/fit/interlockSim
- gui/animation
- testutil
- util
Lines changed: 19 additions & 52 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | 82 | | |
99 | 83 | | |
100 | 84 | | |
| |||
176 | 160 | | |
177 | 161 | | |
178 | 162 | | |
179 | | - | |
180 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
181 | 166 | | |
182 | 167 | | |
183 | | - | |
184 | | - | |
185 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
186 | 174 | | |
187 | 175 | | |
188 | 176 | | |
189 | 177 | | |
190 | | - | |
| 178 | + | |
191 | 179 | | |
192 | | - | |
| 180 | + | |
193 | 181 | | |
194 | | - | |
| 182 | + | |
195 | 183 | | |
196 | | - | |
| 184 | + | |
197 | 185 | | |
198 | 186 | | |
199 | | - | |
| 187 | + | |
200 | 188 | | |
201 | 189 | | |
202 | 190 | | |
| |||
215 | 203 | | |
216 | 204 | | |
217 | 205 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
244 | 211 | | |
245 | 212 | | |
246 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
43 | 55 | | |
0 commit comments