|
| 1 | +/* eslint-disable antfu/no-import-dist */ |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { QuantumMatcher } from '../../dist' |
| 4 | +import { scientificData } from '../const' |
| 5 | + |
| 6 | +describe('quantumMatcher Depth Search with Scientific Data', () => { |
| 7 | + const matcher = new QuantumMatcher(scientificData, { |
| 8 | + keys: [ |
| 9 | + 'id', |
| 10 | + 'title', |
| 11 | + 'content.basics.description', |
| 12 | + 'content.basics.examples', |
| 13 | + 'content.advanced.applications.realWorld', |
| 14 | + 'content.advanced.applications.economics', |
| 15 | + 'content.metadata.category.main', |
| 16 | + 'content.metadata.category.sub', |
| 17 | + 'content.metadata.tags', |
| 18 | + 'content.basics.formula.standard', |
| 19 | + 'content.basics.formula.vertex', |
| 20 | + 'content.solutions.methods.factoring.steps', |
| 21 | + 'content.solutions.methods.factoring.example', |
| 22 | + 'content.solutions.methods.quadraticFormula.expression', |
| 23 | + 'content.solutions.methods.quadraticFormula.usage', |
| 24 | + 'content.fundamentals.laws.first.statement', |
| 25 | + 'content.fundamentals.laws.first.applications.space', |
| 26 | + 'content.fundamentals.laws.first.applications.earth', |
| 27 | + 'content.fundamentals.laws.second.statement', |
| 28 | + 'content.fundamentals.laws.second.components.force', |
| 29 | + 'content.fundamentals.laws.second.components.mass', |
| 30 | + 'content.fundamentals.laws.second.components.acceleration', |
| 31 | + 'content.fundamentals.laws.third.statement', |
| 32 | + 'content.fundamentals.laws.third.examples.rocket', |
| 33 | + 'content.fundamentals.laws.third.examples.walking', |
| 34 | + 'content.principles.uncertainty.definition.basic', |
| 35 | + 'content.principles.uncertainty.definition.mathematical', |
| 36 | + 'content.principles.uncertainty.implications.measurement.effects', |
| 37 | + 'content.principles.uncertainty.implications.measurement.limitations', |
| 38 | + 'content.principles.waveFunctions.properties.superposition.description', |
| 39 | + 'content.principles.waveFunctions.properties.superposition.examples.cat', |
| 40 | + 'content.principles.waveFunctions.properties.superposition.examples.electron', |
| 41 | + 'content.metadata.category.level', |
| 42 | + 'content.metadata.tags', |
| 43 | + ], |
| 44 | + }) |
| 45 | + |
| 46 | + // Existing tests |
| 47 | + it('should find exact matches', () => { |
| 48 | + const results = matcher.findMatches('Linear Equations') |
| 49 | + expect(results.length).toBe(1) |
| 50 | + expect(results[0].item.title).toBe('Linear Equations') |
| 51 | + }) |
| 52 | + |
| 53 | + it('should handle case insensitivity', () => { |
| 54 | + const results = matcher.findMatches('linear equations') |
| 55 | + expect(results.length).toBe(1) |
| 56 | + expect(results[0].item.title).toBe('Linear Equations') |
| 57 | + }) |
| 58 | + |
| 59 | + it('should find partial matches', () => { |
| 60 | + const results = matcher.findMatches('equations') |
| 61 | + expect(results.length).toBeGreaterThan(0) |
| 62 | + expect(results.some(result => result.item.title.includes('Equations'))).toBe(true) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should handle special characters', () => { |
| 66 | + const results = matcher.findMatches('F = ma') |
| 67 | + expect(results.length).toBeGreaterThan(0) |
| 68 | + expect(results.some(result => result.item.title === 'Newton\'s Laws')).toBe(true) |
| 69 | + }) |
| 70 | + |
| 71 | + it('should return empty for non-existent patterns', () => { |
| 72 | + const results = matcher.findMatches('xyz') |
| 73 | + expect(results.length).toBe(0) |
| 74 | + }) |
| 75 | + |
| 76 | + it('should handle empty query', () => { |
| 77 | + const results = matcher.findMatches('') |
| 78 | + expect(results.length).toBe(0) |
| 79 | + }) |
| 80 | + |
| 81 | + it('should handle long queries', () => { |
| 82 | + const longQuery = 'a'.repeat(1000) |
| 83 | + const results = matcher.findMatches(longQuery) |
| 84 | + expect(results.length).toBe(0) |
| 85 | + }) |
| 86 | + |
| 87 | + it('should handle queries with spaces', () => { |
| 88 | + const results = matcher.findMatches('Cannot simultaneously know position') |
| 89 | + expect(results.length).toBe(1) |
| 90 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 91 | + }) |
| 92 | + |
| 93 | + it('should find matches by tags', () => { |
| 94 | + const results = matcher.findMatches('algebra') |
| 95 | + expect(results.length).toBeGreaterThan(0) |
| 96 | + expect(results.some(result => result.item.content.metadata.tags.includes('algebra'))).toBe(true) |
| 97 | + }) |
| 98 | + |
| 99 | + it('should handle multiple keywords', () => { |
| 100 | + const results = matcher.findMatches('Quantum Uncertainty') |
| 101 | + expect(results.length).toBe(1) |
| 102 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 103 | + }) |
| 104 | + |
| 105 | + it('should handle numeric searches', () => { |
| 106 | + const results = matcher.findMatches('ΔxΔp ≥ ħ/2') |
| 107 | + expect(results.length).toBe(1) |
| 108 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 109 | + }) |
| 110 | + |
| 111 | + it('should find matches in basics.description', () => { |
| 112 | + const results = matcher.findMatches('Equations where variables are raised to the first power') |
| 113 | + expect(results.length).toBe(1) |
| 114 | + expect(results[0].item.title).toBe('Linear Equations') |
| 115 | + }) |
| 116 | + |
| 117 | + it('should find matches in basics.examples', () => { |
| 118 | + const results = matcher.findMatches('y = mx + b') |
| 119 | + expect(results.length).toBe(1) |
| 120 | + expect(results[0].item.title).toBe('Linear Equations') |
| 121 | + }) |
| 122 | + |
| 123 | + it('should find matches in advanced.applications.realWorld', () => { |
| 124 | + const results = matcher.findMatches('Used in calculating slopes and linear relationships') |
| 125 | + expect(results.length).toBe(1) |
| 126 | + expect(results[0].item.title).toBe('Linear Equations') |
| 127 | + }) |
| 128 | + |
| 129 | + it('should find matches in advanced.applications.economics', () => { |
| 130 | + const results = matcher.findMatches('Supply and demand curves') |
| 131 | + expect(results.length).toBe(1) |
| 132 | + expect(results[0].item.title).toBe('Linear Equations') |
| 133 | + }) |
| 134 | + |
| 135 | + it('should find matches in metadata.category.main', () => { |
| 136 | + const results = matcher.findMatches('mathematics') |
| 137 | + expect(results.length).toBeGreaterThan(0) |
| 138 | + expect(results.some(result => result.item.content.metadata.category.main === 'mathematics')).toBe(true) |
| 139 | + }) |
| 140 | + |
| 141 | + it('should find matches in metadata.category.sub', () => { |
| 142 | + const results = matcher.findMatches('algebra') |
| 143 | + expect(results.length).toBeGreaterThan(0) |
| 144 | + expect(results.some(result => result.item.content.metadata.category.sub === 'algebra')).toBe(true) |
| 145 | + }) |
| 146 | + |
| 147 | + // New tests for missing keys |
| 148 | + it('should find matches in basics.formula.standard', () => { |
| 149 | + const results = matcher.findMatches('ax² + bx + c = 0') |
| 150 | + expect(results.length).toBe(1) |
| 151 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 152 | + }) |
| 153 | + |
| 154 | + it('should find matches in basics.formula.vertex', () => { |
| 155 | + const results = matcher.findMatches('y = a(x - h)² + k') |
| 156 | + expect(results.length).toBe(1) |
| 157 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 158 | + }) |
| 159 | + |
| 160 | + it('should find matches in solutions.methods.factoring.steps', () => { |
| 161 | + const results = matcher.findMatches('Find factors') |
| 162 | + expect(results.length).toBe(1) |
| 163 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 164 | + }) |
| 165 | + |
| 166 | + it('should find matches in solutions.methods.factoring.example', () => { |
| 167 | + const results = matcher.findMatches('x² + 5x + 6 = (x + 2)(x + 3)') |
| 168 | + expect(results.length).toBe(1) |
| 169 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 170 | + }) |
| 171 | + |
| 172 | + it('should find matches in solutions.methods.quadraticFormula.expression', () => { |
| 173 | + const results = matcher.findMatches('x = (-b ± √(b² - 4ac)) / 2a') |
| 174 | + expect(results.length).toBe(1) |
| 175 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 176 | + }) |
| 177 | + |
| 178 | + it('should find matches in solutions.methods.quadraticFormula.usage', () => { |
| 179 | + const results = matcher.findMatches('When factoring is not possible') |
| 180 | + expect(results.length).toBe(1) |
| 181 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 182 | + }) |
| 183 | + |
| 184 | + it('should find matches in fundamentals.laws.first.statement', () => { |
| 185 | + const results = matcher.findMatches('An object remains at rest or in motion unless acted upon by a force') |
| 186 | + expect(results.length).toBe(1) |
| 187 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 188 | + }) |
| 189 | + |
| 190 | + it('should find matches in fundamentals.laws.first.applications.space', () => { |
| 191 | + const results = matcher.findMatches('Objects in space continue moving without propulsion') |
| 192 | + expect(results.length).toBe(1) |
| 193 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 194 | + }) |
| 195 | + |
| 196 | + it('should find matches in fundamentals.laws.first.applications.earth', () => { |
| 197 | + const results = matcher.findMatches('Friction affects motion on Earth') |
| 198 | + expect(results.length).toBe(1) |
| 199 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 200 | + }) |
| 201 | + |
| 202 | + it('should find matches in fundamentals.laws.second.statement', () => { |
| 203 | + const results = matcher.findMatches('F = ma') |
| 204 | + expect(results.length).toBeGreaterThan(0) |
| 205 | + }) |
| 206 | + |
| 207 | + it('should find matches when searching by multiple properties "Newton\'s Laws F = ma"', () => { |
| 208 | + const results = matcher.findMatches('Newton\'s Laws F = ma') |
| 209 | + expect(results.length).toBe(1) |
| 210 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 211 | + }) |
| 212 | + |
| 213 | + it('should find matches in fundamentals.laws.second.components.force', () => { |
| 214 | + const results = matcher.findMatches('Measured in Newtons') |
| 215 | + expect(results.length).toBe(1) |
| 216 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 217 | + }) |
| 218 | + |
| 219 | + it('should find matches in fundamentals.laws.second.components.mass', () => { |
| 220 | + const results = matcher.findMatches('Measured in kilograms') |
| 221 | + expect(results.length).toBe(1) |
| 222 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 223 | + }) |
| 224 | + |
| 225 | + it('should find matches in fundamentals.laws.second.components.acceleration', () => { |
| 226 | + const results = matcher.findMatches('Measured in meters per second squared') |
| 227 | + expect(results.length).toBe(1) |
| 228 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 229 | + }) |
| 230 | + |
| 231 | + it('should find matches in fundamentals.laws.third.statement', () => { |
| 232 | + const results = matcher.findMatches('For every action, there is an equal and opposite reaction') |
| 233 | + expect(results.length).toBe(1) |
| 234 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 235 | + }) |
| 236 | + |
| 237 | + it('should find matches in fundamentals.laws.third.examples.rocket', () => { |
| 238 | + const results = matcher.findMatches('Propulsion in space') |
| 239 | + expect(results.length).toBe(1) |
| 240 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 241 | + }) |
| 242 | + |
| 243 | + it('should find matches in fundamentals.laws.third.examples.walking', () => { |
| 244 | + const results = matcher.findMatches('Push against ground') |
| 245 | + expect(results.length).toBe(1) |
| 246 | + expect(results[0].item.title).toBe('Newton\'s Laws') |
| 247 | + }) |
| 248 | + |
| 249 | + it('should find matches in principles.uncertainty.definition.basic', () => { |
| 250 | + const results = matcher.findMatches('Cannot simultaneously know position and momentum precisely') |
| 251 | + expect(results.length).toBe(1) |
| 252 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 253 | + }) |
| 254 | + |
| 255 | + it('should find matches in principles.uncertainty.definition.mathematical', () => { |
| 256 | + const results = matcher.findMatches('ΔxΔp ≥ ħ/2') |
| 257 | + expect(results.length).toBe(1) |
| 258 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 259 | + }) |
| 260 | + |
| 261 | + it('should find matches in principles.uncertainty.implications.measurement.effects', () => { |
| 262 | + const results = matcher.findMatches('Act of measurement affects the system') |
| 263 | + expect(results.length).toBe(1) |
| 264 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 265 | + }) |
| 266 | + |
| 267 | + it('should find matches in principles.uncertainty.implications.measurement.limitations', () => { |
| 268 | + const results = matcher.findMatches('Fundamental limits to precision') |
| 269 | + expect(results.length).toBe(1) |
| 270 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 271 | + }) |
| 272 | + |
| 273 | + it('should find matches in principles.waveFunctions.properties.superposition.description', () => { |
| 274 | + const results = matcher.findMatches('System can exist in multiple states simultaneously') |
| 275 | + expect(results.length).toBe(1) |
| 276 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 277 | + }) |
| 278 | + |
| 279 | + it('should find matches in principles.waveFunctions.properties.superposition.examples.cat', () => { |
| 280 | + const results = matcher.findMatches('Schrödinger\'s cat thought experiment') |
| 281 | + expect(results.length).toBe(1) |
| 282 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 283 | + }) |
| 284 | + |
| 285 | + it('should find matches in principles.waveFunctions.properties.superposition.examples.electron', () => { |
| 286 | + const results = matcher.findMatches('Electron passing through double slit') |
| 287 | + expect(results.length).toBe(1) |
| 288 | + expect(results[0].item.title).toBe('Quantum Mechanics') |
| 289 | + }) |
| 290 | + |
| 291 | + it('should find matches in metadata.category.level', () => { |
| 292 | + const results = matcher.findMatches('intermediate') |
| 293 | + expect(results.length).toBe(1) |
| 294 | + expect(results[0].item.title).toBe('Quadratic Equations') |
| 295 | + }) |
| 296 | +}) |
0 commit comments