Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
3 Star 4 Fork 4

ToolGood/ToolGood.Algorithm

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (7)
Tags (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
master
Branches (7)
Tags (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (7)
Tags (27)
master
js-dev
java-dev
Fast
v3.5
v2.x
v1.x
6.0.0.8
6.0.0.0
5.0.0.2
3.5.0.3
3.4.1.4
3.4.1.3
3.4.0.0
3.3.0.0
3.2.0.2
3.2.0.1
3.0.3
3.0.2
3.0.1
3.0.0.0
2.2.0.2
2.2.0.1-java
2.2.0.1
2.2
2.1.0.1
2.1
SimpleTest.js 4.22 KB
Copy Edit Raw Blame History
sshuicn authored 2026年02月07日 13:43 +08:00 . fix
import assert from 'assert';
// 简化版的 AlgorithmEngine 类
class SimpleAlgorithmEngine {
TryEvaluate(exp, def) {
try {
// 简单的表达式求值
const result = eval(exp);
return typeof result === typeof def ? result : def;
} catch (e) {
return def;
}
}
}
// 测试用例
function testBasicArithmetic() {
console.log('开始测试 基本算术运算...');
const engine = new SimpleAlgorithmEngine();
let c = engine.TryEvaluate('2+3', 0);
assert.strictEqual(c, 5, '2+3 应该等于 5');
c = engine.TryEvaluate('(2)+3', 0);
assert.strictEqual(c, 5, '(2)+3 应该等于 5');
c = engine.TryEvaluate('2+3*2+10/2*4', 0);
assert.strictEqual(c, 28, '2+3*2+10/2*4 应该等于 28');
console.log('基本算术运算 测试通过!');
}
function testScientificNotation() {
console.log('开始测试 科学计数法...');
const engine = new SimpleAlgorithmEngine();
let c = engine.TryEvaluate('2.1e3 + 10', 0);
assert.strictEqual(c, 2110, '2.1e3 + 10 应该等于 2110');
console.log('科学计数法 测试通过!');
}
function testFloatingPoint() {
console.log('开始测试 浮点数...');
const engine = new SimpleAlgorithmEngine();
let d = engine.TryEvaluate('2.1e-3 + 10', 0.0);
assert.strictEqual(d, 10.0021, '2.1e-3 + 10 应该等于 10.0021');
console.log('浮点数 测试通过!');
}
function testConstants() {
console.log('开始测试 常量...');
const engine = new SimpleAlgorithmEngine();
let e = engine.TryEvaluate('Math.E', 0.0);
assert.strictEqual(e, Math.E, 'e 应该等于 Math.E');
e = engine.TryEvaluate('Math.PI', 0.0);
assert.strictEqual(e, Math.PI, 'pi 应该等于 Math.PI');
console.log('常量 测试通过!');
}
function testBoolean() {
console.log('开始测试 布尔值...');
const engine = new SimpleAlgorithmEngine();
let b = engine.TryEvaluate('true', false);
assert.strictEqual(b, true, 'true 应该等于 true');
b = engine.TryEvaluate('false', true);
assert.strictEqual(b, false, 'false 应该等于 false');
console.log('布尔值 测试通过!');
}
function testConditionalExpression() {
console.log('开始测试 条件表达式...');
const engine = new SimpleAlgorithmEngine();
let b1 = engine.TryEvaluate('true ? 1 : 2', 0);
assert.strictEqual(b1, 1, 'true ? 1 : 2 应该等于 1');
b1 = engine.TryEvaluate('false ? 1 : 2', 0);
assert.strictEqual(b1, 2, 'false ? 1 : 2 应该等于 2');
console.log('条件表达式 测试通过!');
}
function testString() {
console.log('开始测试 字符串...');
const engine = new SimpleAlgorithmEngine();
let s = engine.TryEvaluate('"aa" + "bb"', "");
assert.strictEqual(s, "aabb", '"aa" + "bb" 应该等于 "aabb"');
console.log('字符串 测试通过!');
}
function testArray() {
console.log('开始测试 数组...');
const engine = new SimpleAlgorithmEngine();
let r = engine.TryEvaluate('[1,2,3,4].length', 0);
assert.strictEqual(r, 4, '[1,2,3,4].length 应该等于 4');
console.log('数组 测试通过!');
}
function testComparison() {
console.log('开始测试 比较运算...');
const engine = new SimpleAlgorithmEngine();
let value = engine.TryEvaluate('1 > (-2)', false);
assert.strictEqual(value, true, '1 > (-2) 应该等于 true');
value = engine.TryEvaluate('-1 > -2', false);
assert.strictEqual(value, true, '-1 > -2 应该等于 true');
let value3 = engine.TryEvaluate('-7 < -2', false);
assert.strictEqual(value3, true, '-7 < -2 应该等于 true');
console.log('比较运算 测试通过!');
}
// 运行所有测试
function runAllTests() {
try {
testBasicArithmetic();
testScientificNotation();
testFloatingPoint();
testConstants();
testBoolean();
testConditionalExpression();
testString();
testArray();
testComparison();
console.log('所有测试通过!');
} catch (error) {
console.error('测试失败:', error.message);
process.exit(1);
}
}
// 执行测试
runAllTests();
export {
testBasicArithmetic,
testScientificNotation,
testFloatingPoint,
testConstants,
testBoolean,
testConditionalExpression,
testString,
testArray,
testComparison,
runAllTests
};
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

ToolGood.Algorithm是一个功能强大、轻量级、兼容Excel公式的算法类库,旨在提高开发人员在不同业务场景中的生产力。
No labels
unknown license
unknown open source license
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/toolgood/ToolGood.Algorithm.git
git@gitee.com:toolgood/ToolGood.Algorithm.git
toolgood
ToolGood.Algorithm
ToolGood.Algorithm
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /