Skip to content

Conversation

@cardmagic
Copy link
Owner

Summary

Add comprehensive test coverage for the Bayes#untrain method, which previously had zero coverage.

Tests Added (11 total)

  • Basic untrain functionality
  • Dynamic untrain_* method calls
  • Effect on classification results
  • Category count decrements
  • Word removal when count reaches zero
  • Partial word removal (multiple occurrences)
  • Edge case: untraining more than trained
  • Edge case: untraining non-existent words
  • Invalid category handling
  • Category word count updates

Coverage Improvement

Metric Before After Change
Line 88.06% 91.39% +3.33%
Branch 67.92% 72.64% +4.72%

Fixes #50

The untrain method had zero test coverage, which was identified
in the coverage audit (#48). This adds 11 tests covering:

- Basic untrain functionality
- Dynamic untrain_* method calls
- Effect on classification results
- Category count decrements
- Word removal when count reaches zero
- Partial word removal (multiple occurrences)
- Edge case: untraining more than trained
- Edge case: untraining non-existent words
- Invalid category handling
- Category word count updates

Coverage improved from 88% to 91% line, 68% to 73% branch.

Fixes #50
@cardmagic cardmagic requested a review from Copilot December 27, 2025 06:27
@cardmagic cardmagic self-assigned this Dec 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for the previously untested Bayes#untrain method, improving line coverage by 3.33% and branch coverage by 4.72%.

Key Changes:

  • Added 11 new test cases covering basic functionality, edge cases, and error handling
  • Tests verify word count decrements, category updates, and classification impact
  • Includes edge case handling for over-untraining and non-existent words

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cardmagic
Copy link
Owner Author

Re: Copilot's suggestion to change :word to :wor

This is incorrect. The Porter stemmer keeps word unchanged:

require 'fast-stemmer'
'word'.stem   # => "word"
'unique'.stem # => "uniqu"  
'apple'.stem  # => "appl"

The test is correct as written.

@cardmagic cardmagic merged commit 603f10d into master Dec 27, 2025
4 checks passed
@cardmagic cardmagic deleted the test/bayes-untrain branch December 27, 2025 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for Bayes#untrain method

2 participants