Skip to content

Commit

Permalink
DecisionTree#clone API
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzeroglu committed Sep 24, 2020
1 parent 369661e commit 32d3aa7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/decision-tree/DecisionTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ DecisionTree.prototype.makeDecision = function(knowledge){
return currentNode;
}

DecisionTree.prototype.clone = function(){
return new DecisionTree(this._rootNode.clone());
}

export { DecisionTree };
14 changes: 14 additions & 0 deletions test/decision-tree/DecisionTreeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ describe("DecisionTree", function(){
expect(catchedErr.message).to.eql("Root node must be an instance of Ego.Decision")
});

it("should clone", function(){

var rootDecision = new Ego.Decision("isStuffHappening", Ego.InformationTypes.TYPE_BOOLEAN, new Ego.IsTrue());

var decisionTree = new Ego.DecisionTree(rootDecision);

var cloned = decisionTree.clone();

expect(decisionTree).to.eql(cloned);
expect(decisionTree === cloned).to.eql(false);
expect(decisionTree._rootNode).to.eql(cloned._rootNode);
expect(decisionTree._rootNode === cloned._rootNode).to.eql(false);
});

describe("should make decision", function(){

it("root node only", function(){
Expand Down

0 comments on commit 32d3aa7

Please sign in to comment.