test: Improve test coverage for DijkstraSearch and KoshienMock#39
Conversation
- Add 20 test cases for lib/dijkstra_search.rb covering: - Node and Edge initialization - Graph construction - Shortest path finding with #route - Coordinate conversion with #get_route - Cost calculation with #cost - Edge cases (unreachable destinations, same start/goal) - Add 28 test cases for lib/smalruby3/koshien_mock.rb covering: - All public API methods - Position parsing and formatting - Object type mapping - Map data methods (map, map_all, map_from) - Player and goal position methods - Route calculation and object location Test coverage improved from 67.85% to 69.28% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Added RSpec tests for Koshien class to improve test coverage and verify correct implementation of core API methods: - calc_route: Tests route calculation with default and custom parameters, exception handling for blocked cells, and proper List format output - map: Tests map data retrieval for explored and unexplored positions - map_all: Tests complete map string representation - map_from: Tests map data extraction from map string These tests verify that calc_route already correctly uses DijkstraSearch::Graph for pathfinding (lines 519-525 in koshien.rb), confirming no refactoring is needed. Test results: - All 385 tests passing - Coverage increased to 71.26% - All 10 new Koshien tests passing Related to #24 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Added tests to achieve 100% coverage for calc_route and make_data methods: - Positive item cells (a-e): walkable items with standard cost - Negative item cells (A-D): walkable items with standard cost - Water cells (4): walkable with higher pathfinding cost (weight 2) - Uncleared cells (-1): unexplored cells with highest cost (weight 4) - Unknown cell types: cells with default pathfinding cost (weight 3) These tests ensure the pathfinding algorithm correctly handles all terrain types used in the Smalruby Koshien game, improving coverage from 71.6% to 72.15% overall and achieving 100% coverage for the make_data method used by calc_route. The tests verify that: - Different cell types are correctly processed by the Dijkstra algorithm - Routes are calculated avoiding high-cost cells when possible - All position strings follow the "x:y" format - The pathfinding integrates properly with lib/dijkstra_search.rb 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Consolidated duplicate DijkstraSearch module implementations: - Removed 104 lines of duplicate code from lib/smalruby3/koshien.rb (lines 5-109) - Added require_relative "../dijkstra_search" to use the existing implementation - The existing lib/dijkstra_search.rb has 100% test coverage and better error handling - All existing tests pass (dijkstra_search_spec.rb and koshien_spec.rb calc_route tests) - Reduces code duplication and maintenance burden Benefits: - Single source of truth for Dijkstra's algorithm implementation - Better tested code (100% coverage in dijkstra_search.rb) - Easier to maintain and update - Reduced file size for koshien.rb (650 lines vs 754 lines) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Added test coverage for all methods in Smalruby3::Koshien::Map: - #initialize with Array and String inputs - #data method with various position edge cases - #to_a method for array conversion - #to_s method for string conversion Coverage improved from 88.24% to 100% (17/17 lines) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Added 6 test cases covering all initialization paths and methods - Tests cover Position, String, Array, and x/y initialization - Tests cover to_s and to_a conversion methods - Achieved 100% coverage for lib/smalruby3/koshien/position.rb (15/15 lines) - All tests passing, lint clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Added 23 test cases covering all public and private methods - Tests cover initialize, push, delete_at, clear, []=, insert, [], index, length, include?, replace, map, each, to_s - Tests cover private methods to_array_index and to_list_index - Achieved 97.37% coverage for lib/smalruby3/list.rb (37/38 lines) - All tests passing, lint clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Add 8 test cases covering World singleton class functionality to achieve 100% coverage: - Initialization and reset behavior - Adding stage with duplicate prevention (ExistStage error) - Adding sprites to array with name tracking - Duplicate sprite prevention (ExistSprite error) - Singleton pattern verification Coverage improved from 48.15% to 100% (27/27 lines covered). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Add 4 test cases covering IgnoreMethodMissing functionality to achieve 100% coverage: - method_missing returns new instance - method_missing handles arguments - method_missing warns about missing method - respond_to_missing? delegates to super Coverage improved from 57.14% to 100% (7/7 lines covered). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
Add 5 test cases covering Stage class functionality to achieve 100% coverage: - stage? method returns true - Inheritance from Sprite class - define_variable private method creates global variables with $ prefix - define_variable sets values correctly - define_variable returns prefixed variable name Coverage improved from 60% to 100% (10/10 lines covered). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 20 comprehensive test cases covering all Sprite functionality - Test initialization with name, options, and block - Test variables and lists setters with defaults and values - Test stage? method returns false - Test list retrieval by name - Test koshien singleton access - Test method_missing and respond_to_missing? behavior - Test define_variable private method - Achieve 100% coverage for lib/smalruby3/sprite.rb (39/39 lines) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add test for List#index when element not found (returns nil) - Add nil check in to_list_index private method to handle nil array_index - Achieve 97.44% coverage for lib/smalruby3/list.rb (38/39 lines) - One remaining uncovered line is unreachable in practice 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 4 test cases covering position coordinate conversion - Tests handle positive, negative, zero, and mixed coordinates - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add 3 test cases for extracting x coordinate from position string - Tests handle positive, negative, and zero x coordinates - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add 3 test cases for extracting y coordinate from position string - Tests handle positive, negative, and zero y coordinates - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add tests for #goal, #goal_x, and #goal_y methods - Tests verify goal position retrieval and coordinate extraction - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add tests for #player, #player_x, and #player_y methods - Tests verify player position retrieval and coordinate extraction - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
📊 Code Coverage ReportCoverage threshold:
|
- Add 6 test cases for #other_player, #other_player_x, #other_player_y - Tests cover both when other player data is available and not available - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add 7 test cases for #enemy, #enemy_x, #enemy_y - Tests cover when enemy data is available, not available, and empty array - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 3 test cases for #set_message - Tests verify message delegation to send_debug_message - Tests cover string, numeric, and nil values - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 7 comprehensive test cases for #locate_objects - Tests cover object finding, filtering, sorting, and edge cases - Tests verify custom search area size and center position - Tests check behavior when visible map is not available - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
📊 Code Coverage ReportCoverage threshold:
|
- Add 5 test cases for #add_action, #clear_actions, #get_actions - Tests verify action array manipulation and copying - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add 12 test cases for private helper methods - Tests for current_player_position, other_players, enemies, visible_map, goal_position - Tests cover various data availability scenarios and fallback behaviors - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
📊 Code Coverage ReportCoverage threshold:
|
- Add 4 test cases for #map method covering all branches - Tests cover visible_map available/unavailable scenarios - Tests verify correct handling of valid, empty, and unexplored cells - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 2 additional test cases for #map_all method - Tests verify correct handling of mixed visible/unexplored cells - Tests verify behavior when visible_map is missing vs nil - All 4 tests pass and lint is clean - Indirectly covers build_map_string_from_visible_map private method 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add 6 test cases for #get_map_area method covering all branches - Tests verify valid position parsing and map area data return - Tests verify @last_map_area_response storage - Tests verify exploration action is added - Tests verify invalid position formats return nil - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage ReportCoverage threshold:
|
- Add 6 test cases for #move_to method covering all branches - Tests verify move action is added with correct coordinates - Tests verify @current_position tracking via track_movement_action - Tests verify invalid position formats don't add actions - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage Report✅ Coverage: 80.17% Coverage threshold:
|
- Add 6 test cases for #set_dynamite method covering all branches - Tests verify set_dynamite action is added with correct coordinates - Tests verify default behavior using player position when nil/no arg - Tests verify invalid position formats don't add actions - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage Report✅ Coverage: 80.56% Coverage threshold:
|
- Add 6 test cases for #set_bomb method covering all branches - Tests verify set_bomb action is added with correct coordinates - Tests verify default behavior using player position when nil/no arg - Tests verify invalid position formats don't add actions - All tests pass and lint is clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage Report✅ Coverage: 80.56% Coverage threshold:
|
📊 Code Coverage Report✅ Coverage: 80.56% Coverage threshold:
|
- Add 6 test cases for #turn_over method covering all branches - Tests verify turn_over message is sent with actions - Tests verify actions are cleared after sending - Tests verify turn_end_confirm and turn_start message handling - Tests verify timeout handling when no messages received - All tests pass and lint is clean - Indirectly covers send_turn_over and wait_for_turn_completion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
📊 Code Coverage Report✅ Coverage: 82.09% Coverage threshold:
|
Summary
This PR significantly improves test coverage by adding comprehensive tests for:
Test Coverage Improvements
Overall Coverage: 71.26% (target: 95%)
Total Tests: 385 examples, 0 failures
New Test Files
spec/lib/smalruby3/koshien_spec.rb (10 tests) ✅ NEW
spec/lib/dijkstra_search_spec.rb (existing)
spec/lib/smalruby3/koshien_mock_spec.rb (existing)
Implementation Notes
Koshien#calc_routealready correctly usesDijkstraSearch::Graph(lines 519-525 in koshien.rb)Test Examples
Koshien API Tests
DijkstraSearch Tests
Progress
Related Issue
Closes #24
🤖 Generated with Claude Code