import { SongMatchingService } from './src/services/songMatchingService.js'; async function testMatchingAlgorithm() { console.log('๐Ÿงช Testing improved matching algorithm...'); const matchingService = new SongMatchingService(); // Test cases for filename matching const testCases = [ { musicFile: { originalName: 'Artist Name - Song Title.mp3', title: 'Song Title', artist: 'Artist Name' }, song: { title: 'Song Title', artist: 'Artist Name', location: '/path/to/Artist Name - Song Title.mp3' }, expectedScore: 1.0, description: 'Exact Artist-Title pattern match' }, { musicFile: { originalName: 'Song Title (Remix).mp3', title: 'Song Title', artist: 'Artist Name' }, song: { title: 'Song Title', artist: 'Artist Name', location: '/path/to/Song Title.mp3' }, expectedScore: 0.95, description: 'Filename variation match' }, { musicFile: { originalName: 'Artist Name feat. Other Artist - Song Title.mp3', title: 'Song Title', artist: 'Artist Name' }, song: { title: 'Song Title', artist: 'Artist Name', location: '/path/to/Artist Name - Song Title.mp3' }, expectedScore: 0.95, description: 'Partial Artist-Title pattern match' }, { musicFile: { originalName: 'Song Title.mp3', title: 'Song Title', artist: 'Artist Name' }, song: { title: 'Song Title', artist: 'Artist Name', location: '/path/to/Song Title.mp3' }, expectedScore: 1.0, description: 'Exact filename match' }, { musicFile: { originalName: 'Different Name.mp3', title: 'Song Title', artist: 'Artist Name' }, song: { title: 'Song Title', artist: 'Artist Name', location: '/path/to/Song Title.mp3' }, expectedScore: 0.9, description: 'Title match when filename differs' } ]; console.log('\n๐Ÿ“Š Testing filename matching scenarios...'); for (const testCase of testCases) { console.log(`\n๐Ÿ” Testing: ${testCase.description}`); console.log(` Music File: ${testCase.musicFile.originalName}`); console.log(` Song: ${testCase.song.title} by ${testCase.song.artist}`); // Test the calculateMatch method directly const matchResult = matchingService['calculateMatch'](testCase.musicFile, testCase.song, { enableFuzzyMatching: true, enablePartialMatching: true }); const status = matchResult.confidence >= testCase.expectedScore * 0.9 ? 'โœ…' : 'โŒ'; console.log(` ${status} Confidence: ${(matchResult.confidence * 100).toFixed(1)}% (expected: ${(testCase.expectedScore * 100).toFixed(1)}%)`); console.log(` Match Type: ${matchResult.matchType}`); console.log(` Reason: ${matchResult.matchReason}`); } // Test filename matching function directly console.log('\n๐Ÿ” Testing filename matching function...'); const filenameTests = [ { filename: 'Artist - Song.mp3', song: { title: 'Song', artist: 'Artist' }, expected: 'Exact Artist-Title pattern match' }, { filename: 'Song (Remix).mp3', song: { title: 'Song', artist: 'Artist' }, expected: 'Filename variation matches title' }, { filename: 'Artist feat. Other - Song.mp3', song: { title: 'Song', artist: 'Artist' }, expected: 'Exact Artist-Title pattern match' } ]; for (const test of filenameTests) { const result = matchingService['matchFilename'](test.filename, test.song); const status = result.reason.includes(test.expected) ? 'โœ…' : 'โŒ'; console.log(`${status} "${test.filename}" -> "${test.expected}" (${(result.score * 100).toFixed(1)}%)`); } // Test location matching function console.log('\n๐Ÿ” Testing location matching function...'); const locationTests = [ { filename: 'Song.mp3', location: '/path/to/Song.mp3', expected: 'Exact location filename match' }, { filename: 'Song (Remix).mp3', location: '/path/to/Song.mp3', expected: 'Filename matches location variation' }, { filename: 'Artist - Song.mp3', location: '/path/to/Song.mp3', expected: 'Location filename contains match' } ]; for (const test of locationTests) { const result = matchingService['matchLocation'](test.filename, test.location); const status = result.reason.includes(test.expected) ? 'โœ…' : 'โŒ'; console.log(`${status} "${test.filename}" in "${test.location}" -> "${test.expected}" (${(result.score * 100).toFixed(1)}%)`); } console.log('\n๐ŸŽ‰ Matching algorithm tests completed!'); console.log('\n๐Ÿ“‹ Key improvements:'); console.log(' โœ… Filename matching is now the highest priority'); console.log(' โœ… Early termination for exact matches (95%+ confidence)'); console.log(' โœ… Comprehensive pattern matching for Artist-Title combinations'); console.log(' โœ… Better handling of filename variations (remix, edit, etc.)'); console.log(' โœ… Improved location matching for Rekordbox file paths'); console.log(' โœ… Weighted scoring system with filename bias'); } testMatchingAlgorithm().catch(console.error);