Skip to content

Commit

Permalink
修正单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Feb 4, 2025
1 parent 9ff1e45 commit bb2bf48
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 277 deletions.
128 changes: 85 additions & 43 deletions docs/compare/nop-vs-mps.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ public ISchema buildRuleInputSchema(NopRuleDefinition entity) {
return null;

XNode node = XNodeParser.instance().parseFromText(null, entity.getModelText());
XNode inputsNode = node.childByTag("inputs");
if (inputsNode == null || !inputsNode.hasChild()) {
List<XNode> inputsNode = node.childrenByTag("input");
if (inputsNode.isEmpty()) {
return null;
}

XNode schemaNode = XNode.make("schema");
XNode propsNode = schemaNode.makeChild("props");
for (XNode inputNode : inputsNode.getChildren()) {
for (XNode inputNode : inputsNode) {
XNode propNode = XNode.make("prop");
propNode.setLocation(inputNode.getLocation());
propNode.setAttr("name", inputNode.getAttr("name"));
Expand Down Expand Up @@ -188,7 +188,6 @@ private void buildRuleTree(XNode children, List<NopRuleNode> nodes, TreeIndex<No

Map<String, Object> outputs = (Map<String, Object>) JsonTool.parseNonStrict(node.getOutputs());
if (outputs != null) {
XNode outputsNode = child.makeChild("outputs");
for (Map.Entry<String, Object> entry : outputs.entrySet()) {
String name = entry.getKey();
XNode exprNode = toExprNode(entry.getValue());
Expand All @@ -198,7 +197,7 @@ private void buildRuleTree(XNode children, List<NopRuleNode> nodes, TreeIndex<No
exprNode.setTagName("valueExpr");
outputNode.appendChild(exprNode);
}
outputsNode.appendChild(outputNode);
child.appendChild(outputNode);
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,61 +1,6 @@
{
"data": {
"logMessages": [
{
"logTime": "@var:rule-log-time",
"message": "MISMATCH",
"ruleNodeId": "A3",
"ruleNodeLabel": "<20"
},
{
"logTime": "@var:rule-log-time_1",
"message": "MISMATCH",
"ruleNodeId": "A5",
"ruleNodeLabel": "<30"
},
{
"logTime": "@var:rule-log-time_2",
"message": "MATCH",
"ruleNodeId": "A6",
"ruleNodeLabel": ">=30"
},
{
"logTime": "@var:rule-log-time_3",
"message": "MATCH",
"ruleNodeId": "B6",
"ruleNodeLabel": "-"
},
{
"logTime": "@var:rule-log-time_4",
"message": "MISMATCH",
"ruleNodeId": "C1",
"ruleNodeLabel": "有房"
},
{
"logTime": "@var:rule-log-time_5",
"message": "MATCH",
"ruleNodeId": "F1",
"ruleNodeLabel": "无房"
},
{
"logTime": "@var:rule-log-time_6",
"message": "MISMATCH",
"ruleNodeId": "F2",
"ruleNodeLabel": "已婚"
},
{
"logTime": "@var:rule-log-time_7",
"message": "MATCH",
"ruleNodeId": "G2",
"ruleNodeLabel": "未婚"
}
],
"outputs": {
"result": 16
},
"ruleMatch": true,
"ruleName": "testMatrix",
"ruleVersion": 1
},
"status": 0
"bizFatal": false,
"code": "nop.err.rule.output-var-not-allow-empty",
"msg": "输出变量不允许为空:name=type,displayName=类型",
"status": -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,87 @@ A,@var:NopRuleDefinition@ruleId,testMatrix,1,Test Matrix,default,MATX,,"<rule di
<decisionMatrix>
<cells>
<cell pos=""A1"">
<outputs>
<output name=""result"">
<valueExpr>1</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>1</valueExpr>
</output>
</cell>
<cell pos=""B1"">
<outputs>
<output name=""result"">
<valueExpr>2</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>2</valueExpr>
</output>
</cell>
<cell pos=""C1"">
<outputs>
<output name=""result"">
<valueExpr>3</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>3</valueExpr>
</output>
</cell>
<cell pos=""D1"">
<outputs>
<output name=""result"">
<valueExpr>4</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>4</valueExpr>
</output>
</cell>
<cell pos=""A2"">
<outputs>
<output name=""result"">
<valueExpr>5</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>5</valueExpr>
</output>
</cell>
<cell pos=""B2"">
<outputs>
<output name=""result"">
<valueExpr>6</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>6</valueExpr>
</output>
</cell>
<cell pos=""C2"">
<outputs>
<output name=""result"">
<valueExpr>7</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>7</valueExpr>
</output>
</cell>
<cell pos=""D2"">
<outputs>
<output name=""result"">
<valueExpr>8</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>8</valueExpr>
</output>
</cell>
<cell pos=""A3"">
<outputs>
<output name=""result"">
<valueExpr>9</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>9</valueExpr>
</output>
</cell>
<cell pos=""B3"">
<outputs>
<output name=""result"">
<valueExpr>10</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>10</valueExpr>
</output>
</cell>
<cell pos=""C3"">
<outputs>
<output name=""result"">
<valueExpr>11</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>11</valueExpr>
</output>
</cell>
<cell pos=""D3"">
<outputs>
<output name=""result"">
<valueExpr>12</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>12</valueExpr>
</output>
</cell>
<cell pos=""A4"">
<outputs>
<output name=""result"">
<valueExpr>13</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>13</valueExpr>
</output>
</cell>
<cell pos=""B4"">
<outputs>
<output name=""result"">
<valueExpr>14</valueExpr>
</output>
<output name=""type"">
<valueExpr> 'A'</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>14</valueExpr>
</output>
<output name=""type"">
<valueExpr> 'A'</valueExpr>
</output>
</cell>
<cell pos=""C4"">
<outputs>
<output name=""result"">
<valueExpr>15</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>15</valueExpr>
</output>
</cell>
<cell pos=""D4"">
<outputs>
<output name=""result"">
<valueExpr>16</valueExpr>
</output>
</outputs>
<output name=""result"">
<valueExpr>16</valueExpr>
</output>
</cell>
</cells>
<colDecider>
Expand Down Expand Up @@ -202,37 +170,33 @@ A,@var:NopRuleDefinition@ruleId,testMatrix,1,Test Matrix,default,MATX,,"<rule di
</children>
</rowDecider>
</decisionMatrix>
<inputs>
<input displayName=""是否有房"" mandatory=""true"" name=""是否有房"" type=""Boolean"" ext:level=""0"">
<schema/>
</input>
<input displayName=""是否已婚"" mandatory=""true"" name=""是否已婚"" type=""String"" ext:level=""0"">
<schema/>
</input>
<input displayName=""基础信息"" mandatory=""true"" name=""baseInfo"" type=""Object"" ext:level=""0"">
<schema implementsTypes="""">
<props>
<prop displayName=""年龄"" mandatory=""true"" name=""age"" type=""Integer"" ext:level=""1""
i18n-en:displayName=""Age"">
<schema type=""Integer""/>
</prop>
<prop displayName=""性别"" mandatory=""true"" name=""gender"" type=""Integer"" ext:level=""1"">
<schema type=""Integer""/>
</prop>
</props>
</schema>
</input>
<input computed=""true"" displayName=""性别"" mandatory=""true"" name=""gender"" type=""Integer"" ext:level=""0"">
<defaultExpr>baseInfo.gender</defaultExpr>
<schema dict=""auth/gender""/>
</input>
</inputs>
<outputs>
<output displayName=""分数"" mandatory=""true"" name=""result"" type=""Double"" ext:level=""0"">
<schema/>
</output>
<output displayName=""类型"" mandatory=""true"" name=""type"" type=""String"" ext:level=""0"">
<schema/>
</output>
</outputs>
<input displayName=""是否有房"" mandatory=""true"" name=""是否有房"" type=""Boolean"" ext:level=""0"">
<schema/>
</input>
<input displayName=""是否已婚"" mandatory=""true"" name=""是否已婚"" type=""String"" ext:level=""0"">
<schema/>
</input>
<input displayName=""基础信息"" mandatory=""true"" name=""baseInfo"" type=""Object"" ext:level=""0"">
<schema implementsTypes="""">
<props>
<prop displayName=""年龄"" mandatory=""true"" name=""age"" type=""Integer"" ext:level=""1""
i18n-en:displayName=""Age"">
<schema type=""Integer""/>
</prop>
<prop displayName=""性别"" mandatory=""true"" name=""gender"" type=""Integer"" ext:level=""1"">
<schema type=""Integer""/>
</prop>
</props>
</schema>
</input>
<input computed=""true"" displayName=""性别"" mandatory=""true"" name=""gender"" type=""Integer"" ext:level=""0"">
<defaultExpr>baseInfo.gender</defaultExpr>
<schema dict=""auth/gender""/>
</input>
<output displayName=""分数"" mandatory=""true"" name=""result"" type=""Double"" ext:level=""0"">
<schema/>
</output>
<output displayName=""类型"" mandatory=""true"" name=""type"" type=""String"" ext:level=""0"">
<schema/>
</output>
</rule>",1,0,autotest-ref,*,autotest-ref,*,
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ruleGroup": "default",
"ruleType": "TREE",
"ruleType_label": "TREE-决策树",
"modelText": "<rule displayName=\"测试规则\" x:schema=\"/nop/schema/rule.xdef\" xmlns:x=\"/nop/schema/xdsl.xdef\">\n <inputs>\n <input displayName=\"季度\" mandatory=\"true\" name=\"season\" type=\"String\" ext:level=\"0\">\n <schema/>\n </input>\n <input displayName=\"客人数\" mandatory=\"true\" name=\"guestCount\" type=\"Integer\" ext:level=\"0\">\n <schema/>\n </input>\n </inputs>\n <outputs>\n <output displayName=\"食物\" mandatory=\"true\" name=\"dish\" type=\"String\" ext:level=\"0\">\n <schema/>\n </output>\n </outputs>\n</rule>",
"modelText": "<rule displayName=\"测试规则\" x:schema=\"/nop/schema/rule.xdef\" xmlns:x=\"/nop/schema/xdsl.xdef\">\n <decisionMatrix>\n <colDecider/>\n <rowDecider/>\n </decisionMatrix>\n <input displayName=\"季度\" mandatory=\"true\" name=\"season\" type=\"String\" ext:level=\"0\">\n <schema/>\n </input>\n <input displayName=\"客人数\" mandatory=\"true\" name=\"guestCount\" type=\"Integer\" ext:level=\"0\">\n <schema/>\n </input>\n <output displayName=\"食物\" mandatory=\"true\" name=\"dish\" type=\"String\" ext:level=\"0\">\n <schema/>\n </output>\n</rule>",
"status": 1,
"status_label": "1-启用",
"version": 0,
Expand Down Expand Up @@ -49,7 +49,7 @@
}
],
"beforeExecute": null,
"decisionMatrix": null,
"decisionMatrix": "<_>\n <colDecider/>\n <rowDecider/>\n</_>",
"description": null,
"remark": null
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
_chgType,RULE_ID,RULE_NAME,RULE_VERSION,DISPLAY_NAME,RULE_GROUP,RULE_TYPE,DESCRIPTION,MODEL_TEXT,STATUS,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
A,@var:NopRuleDefinition@ruleId,test,1,Test Tree,default,TREE,,"<rule displayName=""测试规则"" x:schema=""/nop/schema/rule.xdef"" xmlns:x=""/nop/schema/xdsl.xdef"">
<inputs>
<input displayName=""季度"" mandatory=""true"" name=""season"" type=""String"" ext:level=""0"">
<schema/>
</input>
<input displayName=""客人数"" mandatory=""true"" name=""guestCount"" type=""Integer"" ext:level=""0"">
<schema/>
</input>
</inputs>
<outputs>
<output displayName=""食物"" mandatory=""true"" name=""dish"" type=""String"" ext:level=""0"">
<schema/>
</output>
</outputs>
<decisionMatrix>
<colDecider/>
<rowDecider/>
</decisionMatrix>
<input displayName=""季度"" mandatory=""true"" name=""season"" type=""String"" ext:level=""0"">
<schema/>
</input>
<input displayName=""客人数"" mandatory=""true"" name=""guestCount"" type=""Integer"" ext:level=""0"">
<schema/>
</input>
<output displayName=""食物"" mandatory=""true"" name=""dish"" type=""String"" ext:level=""0"">
<schema/>
</output>
</rule>",1,0,autotest-ref,*,autotest-ref,*,
Loading

0 comments on commit bb2bf48

Please sign in to comment.