GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 增加 GetValue 方法 · toolgood/ToolGood.Algorithm@7fb45b0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • JavaScript
    • dist
      • toolgood.algorithm.js
    • package-lock.json
    • package.json
    • src/CalculationLogic
      • CalculationLogicEngine.js
    • tests
      • CalculationLogicTest.js
  • csharp
    • ToolGood.Algorithm.Fast
      • ToolGood.Algorithm.Fast.csproj
    • ToolGood.Algorithm
      • ToolGood.Algorithm.csproj
  • java/toolgood.algorithm
    • pom.xml
    • src
      • main/java/toolgood/algorithm/calculationlogic
        • CalculationLogicEngine.java
      • test/java/toolgood/algorithm/calculationlogic
        • CalculationLogicTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎JavaScript/dist/toolgood.algorithm.js‎

Copy file name to clipboardExpand all lines: JavaScript/dist/toolgood.algorithm.js
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎JavaScript/package-lock.json‎

Copy file name to clipboardExpand all lines: JavaScript/package-lock.json
+2-2Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎JavaScript/package.json‎

Copy file name to clipboardExpand all lines: JavaScript/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "toolgood.algorithm",
3-
"version": "6.3",
3+
"version": "6.3.0.2",
44
"description": "ToolGood Algorithm Engine for JavaScript",
55
"type": "module",
66
"main": "dist/toolgood.algorithm.js",
Collapse file

‎JavaScript/src/CalculationLogic/CalculationLogicEngine.js‎

Copy file name to clipboardExpand all lines: JavaScript/src/CalculationLogic/CalculationLogicEngine.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ export class CalculationLogicEngine {
220220

221221
// #endregion
222222

223+
// #region GetValue
224+
225+
/**
226+
* 获取值
227+
* @param {string} key
228+
* @returns {Operand}
229+
*/
230+
GetValue(key) {
231+
return this._engine.GetParameter(key);
232+
}
233+
234+
// #endregion
235+
223236
// #region BlankLine
224237

225238
/**
Collapse file

‎JavaScript/tests/CalculationLogicTest.js‎

Copy file name to clipboardExpand all lines: JavaScript/tests/CalculationLogicTest.js
+110Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'assert';
22
import { CalculationLogicEngine } from '../src/CalculationLogic/CalculationLogicEngine.js';
3+
import { OperandType } from '../src/Enums/OperandType.js';
34

45
function createEngine(useCalculationLogicInfo = true) {
56
return new CalculationLogicEngine(useCalculationLogicInfo);
@@ -220,6 +221,95 @@ function testSetValue_LayerRemark() {
220221

221222
// #endregion
222223

224+
// #region GetValue 测试
225+
226+
function testGetValue_InitValue_Int() {
227+
const logic = createEngine();
228+
logic.InitValue('a', 1);
229+
const operand = logic.GetValue('a');
230+
assert.strictEqual(operand.IsNumber, true);
231+
assert.strictEqual(operand.Type, OperandType.NUMBER);
232+
assert.strictEqual(operand.NumberValue, 1);
233+
}
234+
235+
function testGetValue_InitValue_String() {
236+
const logic = createEngine();
237+
logic.InitValue('s', 'hello');
238+
const operand = logic.GetValue('s');
239+
assert.strictEqual(operand.IsText, true);
240+
assert.strictEqual(operand.Type, OperandType.TEXT);
241+
assert.strictEqual(operand.TextValue, 'hello');
242+
}
243+
244+
function testGetValue_InitValue_Decimal() {
245+
// JS 无 decimal 类型,使用 number 表示
246+
const logic = createEngine();
247+
logic.InitValue('d', 1.5);
248+
const operand = logic.GetValue('d');
249+
assert.strictEqual(operand.IsNumber, true);
250+
assert.strictEqual(operand.NumberValue, 1.5);
251+
}
252+
253+
function testGetValue_InitValue_Double() {
254+
const logic = createEngine();
255+
logic.InitValue('dd', 1.5);
256+
const operand = logic.GetValue('dd');
257+
assert.strictEqual(operand.IsNumber, true);
258+
assert.strictEqual(operand.NumberValue, 1.5);
259+
}
260+
261+
function testGetValue_InitValue_Bool() {
262+
const logic = createEngine();
263+
logic.InitValue('flag', true);
264+
const operand = logic.GetValue('flag');
265+
assert.strictEqual(operand.IsBoolean, true);
266+
assert.strictEqual(operand.Type, OperandType.BOOLEAN);
267+
assert.strictEqual(operand.BooleanValue, true);
268+
}
269+
270+
function testGetValue_SetValue() {
271+
const logic = createEngine();
272+
logic.SetValue('v', 'text');
273+
const operand = logic.GetValue('v');
274+
assert.strictEqual(operand.IsText, true);
275+
assert.strictEqual(operand.TextValue, 'text');
276+
}
277+
278+
function testGetValue_SetFormula() {
279+
const logic = createEngine();
280+
logic.InitValue('a', 1);
281+
logic.InitValue('b', 2);
282+
logic.SetFormula('x', 'a*3+b');
283+
const operand = logic.GetValue('x');
284+
assert.strictEqual(operand.IsNumber, true);
285+
assert.strictEqual(operand.NumberValue, 5);
286+
}
287+
288+
function testGetValue_AfterSetFormulaOverwrite() {
289+
const logic = createEngine();
290+
logic.InitValue('a', 1);
291+
logic.SetFormula('a', 'a+10');
292+
const operand = logic.GetValue('a');
293+
assert.strictEqual(operand.IsNumber, true);
294+
assert.strictEqual(operand.NumberValue, 11);
295+
}
296+
297+
function testGetValue_NotFound_ReturnsError() {
298+
const logic = createEngine();
299+
const operand = logic.GetValue('missing');
300+
assert.strictEqual(operand.IsError, true);
301+
assert.strictEqual(operand.ErrorMsg, 'Parameter [missing] is missing.');
302+
}
303+
304+
function testGetValue_NoInfo() {
305+
// 关闭信息记录不影响取值
306+
const logic = createEngine(false);
307+
logic.InitValue('a', 1);
308+
assert.strictEqual(logic.GetValue('a').NumberValue, 1);
309+
}
310+
311+
// #endregion
312+
223313
// #region BlankLine 测试
224314

225315
function testBlankLine() {
@@ -309,6 +399,16 @@ function runAllTests() {
309399
testSetValue_Double();
310400
testSetValue_Bool();
311401
testSetValue_LayerRemark();
402+
testGetValue_InitValue_Int();
403+
testGetValue_InitValue_String();
404+
testGetValue_InitValue_Decimal();
405+
testGetValue_InitValue_Double();
406+
testGetValue_InitValue_Bool();
407+
testGetValue_SetValue();
408+
testGetValue_SetFormula();
409+
testGetValue_AfterSetFormulaOverwrite();
410+
testGetValue_NotFound_ReturnsError();
411+
testGetValue_NoInfo();
312412
testBlankLine();
313413
testToInfoString_Empty();
314414
testToInfoString_Disabled();
@@ -349,6 +449,16 @@ export {
349449
testSetValue_Double,
350450
testSetValue_Bool,
351451
testSetValue_LayerRemark,
452+
testGetValue_InitValue_Int,
453+
testGetValue_InitValue_String,
454+
testGetValue_InitValue_Decimal,
455+
testGetValue_InitValue_Double,
456+
testGetValue_InitValue_Bool,
457+
testGetValue_SetValue,
458+
testGetValue_SetFormula,
459+
testGetValue_AfterSetFormulaOverwrite,
460+
testGetValue_NotFound_ReturnsError,
461+
testGetValue_NoInfo,
352462
testBlankLine,
353463
testToInfoString_Empty,
354464
testToInfoString_Disabled,
Collapse file

‎csharp/ToolGood.Algorithm.Fast/ToolGood.Algorithm.Fast.csproj‎

Copy file name to clipboardExpand all lines: csharp/ToolGood.Algorithm.Fast/ToolGood.Algorithm.Fast.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Product>ToolGood.Algorithm.Fast</Product>
2020
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2121
<SignAssembly>true</SignAssembly>
22-
<Version>6.3.0.1</Version>
22+
<Version>6.3.0.2</Version>
2323
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
2424
<DelaySign>false</DelaySign>
2525
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>
Collapse file

‎csharp/ToolGood.Algorithm/ToolGood.Algorithm.csproj‎

Copy file name to clipboardExpand all lines: csharp/ToolGood.Algorithm/ToolGood.Algorithm.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Product>ToolGood.Algorithm</Product>
2020
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2121
<SignAssembly>true</SignAssembly>
22-
<Version>6.3.0.1</Version>
22+
<Version>6.3.0.2</Version>
2323
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
2424
<DelaySign>false</DelaySign>
2525
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>
Collapse file

‎java/toolgood.algorithm/pom.xml‎

Copy file name to clipboardExpand all lines: java/toolgood.algorithm/pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.toolgood</groupId>
88
<artifactId>toolgood-algorithm</artifactId>
9-
<version>6.3.0.0</version>
9+
<version>6.3.0.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>toolgood.algorithm</name>
Collapse file

‎java/toolgood.algorithm/src/main/java/toolgood/algorithm/calculationlogic/CalculationLogicEngine.java‎

Copy file name to clipboardExpand all lines: java/toolgood.algorithm/src/main/java/toolgood/algorithm/calculationlogic/CalculationLogicEngine.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ private String GetOperand(AlgorithmEngineEx engine, String name) {
415415

416416
// #endregion
417417

418+
// #region GetValue
419+
420+
/**
421+
* 获取值
422+
*/
423+
public Operand GetValue(String key) {
424+
return _engine.GetParameter(key);
425+
}
426+
427+
// #endregion
428+
418429
// #region BlankLine
419430

420431
/**
Collapse file

‎java/toolgood.algorithm/src/test/java/toolgood/algorithm/calculationlogic/CalculationLogicTest.java‎

Copy file name to clipboardExpand all lines: java/toolgood.algorithm/src/test/java/toolgood/algorithm/calculationlogic/CalculationLogicTest.java
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package toolgood.algorithm.calculationlogic;
22

33
import org.junit.Test;
4+
import toolgood.algorithm.Operand;
5+
import toolgood.algorithm.enums.OperandType;
46

57
import java.math.BigDecimal;
68

@@ -236,6 +238,104 @@ public void SetValue_LayerRemark_Test() {
236238

237239
// #endregion
238240

241+
// #region GetValue 测试
242+
243+
@Test
244+
public void GetValue_InitValue_Int_Test() {
245+
CalculationLogicEngine logic = CreateEngine();
246+
logic.InitValue("a", 1);
247+
Operand operand = logic.GetValue("a");
248+
assertTrue(operand.IsNumber());
249+
assertEquals(OperandType.NUMBER, operand.Type());
250+
assertEquals(0, operand.NumberValue().compareTo(BigDecimal.ONE));
251+
}
252+
253+
@Test
254+
public void GetValue_InitValue_String_Test() {
255+
CalculationLogicEngine logic = CreateEngine();
256+
logic.InitValue("s", "hello");
257+
Operand operand = logic.GetValue("s");
258+
assertTrue(operand.IsText());
259+
assertEquals(OperandType.TEXT, operand.Type());
260+
assertEquals("hello", operand.TextValue());
261+
}
262+
263+
@Test
264+
public void GetValue_InitValue_Decimal_Test() {
265+
CalculationLogicEngine logic = CreateEngine();
266+
logic.InitValue("d", new BigDecimal("1.5"));
267+
Operand operand = logic.GetValue("d");
268+
assertTrue(operand.IsNumber());
269+
assertEquals(0, operand.NumberValue().compareTo(new BigDecimal("1.5")));
270+
}
271+
272+
@Test
273+
public void GetValue_InitValue_Double_Test() {
274+
CalculationLogicEngine logic = CreateEngine();
275+
logic.InitValue("dd", 1.5);
276+
Operand operand = logic.GetValue("dd");
277+
assertTrue(operand.IsNumber());
278+
assertEquals(0, operand.NumberValue().compareTo(new BigDecimal("1.5")));
279+
}
280+
281+
@Test
282+
public void GetValue_InitValue_Bool_Test() {
283+
CalculationLogicEngine logic = CreateEngine();
284+
logic.InitValue("flag", true);
285+
Operand operand = logic.GetValue("flag");
286+
assertTrue(operand.IsBoolean());
287+
assertEquals(OperandType.BOOLEAN, operand.Type());
288+
assertTrue(operand.BooleanValue());
289+
}
290+
291+
@Test
292+
public void GetValue_SetValue_Test() {
293+
CalculationLogicEngine logic = CreateEngine();
294+
logic.SetValue("v", "text");
295+
Operand operand = logic.GetValue("v");
296+
assertTrue(operand.IsText());
297+
assertEquals("text", operand.TextValue());
298+
}
299+
300+
@Test
301+
public void GetValue_SetFormula_Test() {
302+
CalculationLogicEngine logic = CreateEngine();
303+
logic.InitValue("a", 1);
304+
logic.InitValue("b", 2);
305+
logic.SetFormula("x", "a*3+b");
306+
Operand operand = logic.GetValue("x");
307+
assertTrue(operand.IsNumber());
308+
assertEquals(0, operand.NumberValue().compareTo(new BigDecimal("5")));
309+
}
310+
311+
@Test
312+
public void GetValue_AfterSetFormulaOverwrite_Test() {
313+
CalculationLogicEngine logic = CreateEngine();
314+
logic.InitValue("a", 1);
315+
logic.SetFormula("a", "a+10");
316+
Operand operand = logic.GetValue("a");
317+
assertTrue(operand.IsNumber());
318+
assertEquals(0, operand.NumberValue().compareTo(new BigDecimal("11")));
319+
}
320+
321+
@Test
322+
public void GetValue_NotFound_ReturnsError_Test() {
323+
CalculationLogicEngine logic = CreateEngine();
324+
Operand operand = logic.GetValue("missing");
325+
assertTrue(operand.IsError());
326+
assertEquals("Parameter [missing] is missing.", operand.ErrorMsg());
327+
}
328+
329+
@Test
330+
public void GetValue_NoInfo_Test() {
331+
// 关闭信息记录不影响取值
332+
CalculationLogicEngine logic = CreateEngine(false);
333+
logic.InitValue("a", 1);
334+
assertEquals(0, logic.GetValue("a").NumberValue().compareTo(BigDecimal.ONE));
335+
}
336+
337+
// #endregion
338+
239339
// #region BlankLine 测试
240340

241341
@Test

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.