/*public*/ void TestExecute_PriorityController() { PriorityController_PublicMethods controller = new PriorityController_PublicMethods(); IBlackboard blackboard = new Blackboard(); KS_Old_ReactiveIDSelector ks1 = new KS_Old_ReactiveIDSelector(blackboard); ks1.Properties[Priority] = 10; controller.AddKnowledgeSource(ks1); blackboard.AddUnit(new U_IDSelectRequest("foo")); List <ContentUnit> cuList = new List <ContentUnit> { new ContentUnit(), new ContentUnit(), new ContentUnit() }; cuList[0].Metadata[ContentUnitID] = "foo"; cuList[1].Metadata[ContentUnitID] = "bar"; cuList[2].Metadata[ContentUnitID] = "baz"; foreach (IUnit u in cuList) { blackboard.AddUnit(u); } controller.Execute(); // Four content units total (the original three plus a new selected one) ISet <ContentUnit> cuSet = blackboard.LookupUnits <ContentUnit>(); Assert.Equal(4, cuSet.Count); var selectedUnit = from unit in cuSet where unit.HasMetadataSlot(SelectedContentUnit) select unit; // Exactly 1 selected content unit int count = selectedUnit.Count(); Assert.Equal(1, count); // The selected content unit is "foo" (matches the query request) Assert.True(selectedUnit.ElementAt(0).Metadata[ContentUnitID].Equals("foo")); // Since we only added one KS to controller, and there was only one matching blackboard pattern, after execution the agenda should be empty Assert.Empty(controller.Agenda); }
/*public*/ void TestSelectKSForExecution_PriorityController() { PriorityController_PublicMethods controller = new PriorityController_PublicMethods(); IBlackboard blackboard = new Blackboard(); KS_Old_ReactiveIDSelector ks1 = new KS_Old_ReactiveIDSelector(blackboard); KS_Old_ReactiveIDSelector ks2 = new KS_Old_ReactiveIDSelector(blackboard); KS_Old_ReactiveIDSelector ks3 = new KS_Old_ReactiveIDSelector(blackboard); ks1.Properties[Priority] = 10; ks2.Properties[Priority] = 30; ks3.Properties[Priority] = 20; controller.AddKnowledgeSource(ks1); controller.AddKnowledgeSource(ks2); controller.AddKnowledgeSource(ks3); blackboard.AddUnit(new U_IDSelectRequest("foo")); controller.UpdateAgenda(); Assert.Equal(3, controller.Agenda.Count); IKnowledgeSourceActivation KSA = controller.SelectKSForExecution(); Assert.Equal(30, KSA.Properties[KSProps.Priority]); }