Skip to content

Commit

Permalink
Fixed issue #268 (#269)
Browse files Browse the repository at this point in the history
* Fixed issue #268 where everytime engine execute using the same knowledgebase instance, the rule entries are not resetted as intended.

* Addjust pipeline to run golint

* I temporary removed golint in the test, need to figure out how pipeline install golint into GOBIN
  • Loading branch information
newm4n authored Nov 25, 2021
1 parent 6ddeef6 commit 072b2a2
Show file tree
Hide file tree
Showing 9 changed files with 45,039 additions and 12 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.13
go-version: 1.16
- name: Checkout code
uses: actions/checkout@v2
- name: Fetching dependencies
run : go get -v -t -d ./...
- name: Install GoLint and Goornogo
- name: Install GoLint
run : |
go get -u golang.org/x/lint/golint
go install github.com/newm4n/goornogo
go get -d golang.org/x/lint/golint
go install golang.org/x/lint/golint
echo $GOBIN
- name: Execute test
run : make test-short
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ build: fix-antlr4-bug
go build ./...

lint: build
go get -u golang.org/x/lint/golint
golint -set_exit_status builder/... engine/... examples/... ast/... pkg/... antlr/. model/...
${GOBIN}/golint -set_exit_status builder/... engine/... examples/... ast/... pkg/... antlr/. model/...

test-short: lint
go install github.com/newm4n/goornogo
test-short: build
go test ./... -v -covermode=count -coverprofile=coverage.out -short
goornogo -i coverage.out -c 40

test: lint
go install github.com/newm4n/goornogo
test: build
go test ./... -covermode=count -coverprofile=coverage.out
goornogo -i coverage.out -c 40

test-coverage: test
go tool cover -html=coverage.out
Expand Down
1 change: 1 addition & 0 deletions engine/GruleEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (g *GruleEngine) ExecuteWithContext(ctx context.Context, dataCtx ast.IDataC
// Working memory need to be resetted. all Expression will be set as not evaluated.
log.Debugf("Resetting Working memory")
knowledge.WorkingMemory.ResetAll()
knowledge.Reset()

// Initialize all AST with datacontext and working memory
log.Debugf("Initializing Context")
Expand Down
1 change: 1 addition & 0 deletions examples/CashFlowRule.grl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rule SumUpPurchase "When price after tax calculated, sum it up" {
Purchase.PriceAfterTax > 0
then
CashFlow.PurchaseCount = CashFlow.PurchaseCount + 1;
Log("Count = " + CashFlow.PurchaseCount);
CashFlow.TotalPurchases = CashFlow.TotalPurchases + Purchase.Price;
CashFlow.TotalTax = CashFlow.TotalTax + Purchase.Tax;
CashFlow.PurchasesAfterTax = CashFlow.PurchasesAfterTax + Purchase.PriceAfterTax;
Expand Down
3 changes: 3 additions & 0 deletions examples/PurcasingTaxSample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (cf *CashFlowCalculator) CalculatePurchases(t *testing.T) {
assert.NoError(t, err)
}

assert.Equal(t, 11, cashFlow.PurchaseCount)
assert.Equal(t, 1100000.0, cashFlow.TotalPurchases)

fmt.Println(cashFlow.String())
}

Expand Down
Binary file added examples/benchmark/5000_dummy_rules.grb
Binary file not shown.
Loading

0 comments on commit 072b2a2

Please sign in to comment.