🐛 Bug fixes
This commit is contained in:
		@@ -91,7 +91,7 @@ class SolverService {
 | 
			
		||||
 | 
			
		||||
  /// 检测方程中的变量
 | 
			
		||||
  Set<String> _detectVariables(String input) {
 | 
			
		||||
    final variablePattern = RegExp(r'\b([a-zA-Z])\b');
 | 
			
		||||
    final variablePattern = RegExp(r'([a-zA-Z])');
 | 
			
		||||
    final matches = variablePattern.allMatches(input);
 | 
			
		||||
    return matches.map((match) => match.group(1)!).toSet();
 | 
			
		||||
  }
 | 
			
		||||
@@ -103,8 +103,8 @@ class SolverService {
 | 
			
		||||
 | 
			
		||||
    // 检测方程中的变量
 | 
			
		||||
    final variables = _detectVariables(cleanInput);
 | 
			
		||||
    if (variables.isEmpty) {
 | 
			
		||||
      // 如果没有变量,当作简单表达式处理
 | 
			
		||||
    if (!cleanInput.contains('=') || variables.isEmpty) {
 | 
			
		||||
      // 如果没有等号或没有变量,当作简单表达式处理
 | 
			
		||||
      try {
 | 
			
		||||
        return _solveSimpleExpression(input);
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
 
 | 
			
		||||
@@ -60,10 +60,9 @@ void main() {
 | 
			
		||||
      // 这个方程的根应该是 x = (4 ± √36)/2 = (4 ± 6)/2
 | 
			
		||||
      // 所以 x1 = 5, x2 = -1
 | 
			
		||||
      expect(
 | 
			
		||||
        result.finalAnswer.contains('2 + 3') &&
 | 
			
		||||
            result.finalAnswer.contains('2 - 3'),
 | 
			
		||||
        result.finalAnswer.contains('5') && result.finalAnswer.contains('-1'),
 | 
			
		||||
        true,
 | 
			
		||||
        reason: '方程 x^2 - 4x - 5 = 0 的根应该被表示为 2 ± 3',
 | 
			
		||||
        reason: '方程 x^2 - 4x - 5 = 0 的根为 2 ± 3',
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user