-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Validating issue #108, and a little patch on array.Append() bug and fixing Makefile missing goornogo install * Making sure golint installed in makefile * Update go.mod
- Loading branch information
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package examples | ||
|
||
import ( | ||
"github.com/hyperjumptech/grule-rule-engine/ast" | ||
"github.com/hyperjumptech/grule-rule-engine/builder" | ||
"github.com/hyperjumptech/grule-rule-engine/engine" | ||
"github.com/hyperjumptech/grule-rule-engine/pkg" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
type Struct108 struct { | ||
Rule1Done bool | ||
Rule2Done bool | ||
Rule3Done bool | ||
Sequence []string | ||
} | ||
|
||
var Rule108 = ` | ||
rule Conflicting1 "First conflicting rule" salience 1 { | ||
when | ||
F.Rule1Done == false | ||
then | ||
F.Rule1Done = true; | ||
F.Sequence.Append("1"); | ||
} | ||
rule Conflicting2 "Second conflicting rule" salience 3 { | ||
when | ||
F.Rule2Done == false | ||
then | ||
F.Rule2Done = true; | ||
F.Sequence.Append("2"); | ||
} | ||
rule Conflicting3 "Third conflicting rule" salience 2 { | ||
when | ||
F.Rule3Done == false | ||
then | ||
F.Rule3Done = true; | ||
F.Sequence.Append("3"); | ||
} | ||
` | ||
|
||
func TestIssue108(t *testing.T) { | ||
Obj := &Struct108{ | ||
Rule1Done: false, | ||
Rule2Done: false, | ||
Rule3Done: false, | ||
Sequence: make([]string, 0), | ||
} | ||
|
||
dataContext := ast.NewDataContext() | ||
err := dataContext.Add("F", Obj) | ||
assert.NoError(t, err) | ||
|
||
// Prepare knowledgebase library and load it with our rule. | ||
lib := ast.NewKnowledgeLibrary() | ||
rb := builder.NewRuleBuilder(lib) | ||
err = rb.BuildRuleFromResource("Test108", "0.0.1", pkg.NewBytesResource([]byte(Rule108))) | ||
assert.NoError(t, err) | ||
eng1 := &engine.GruleEngine{MaxCycle: 5} | ||
kb := lib.NewKnowledgeBaseInstance("Test108", "0.0.1") | ||
err = eng1.Execute(dataContext, kb) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 3, len(Obj.Sequence)) | ||
assert.Equal(t, "2", Obj.Sequence[0]) | ||
assert.Equal(t, "3", Obj.Sequence[1]) | ||
assert.Equal(t, "1", Obj.Sequence[2]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters