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