/** * @param bool $flyValue * @param string $sizeValue * @param int $legsValue * @param string $expectedAnimal * @param string $expectedSound * @param array $expectedRules * * @dataProvider soundsDataProvider */ public function testSounds($flyValue, $sizeValue, $legsValue, $expectedAnimal, $expectedSound, array $expectedRules) { $this->knowledgeBase->addFact('fly', $flyValue); $this->knowledgeBase->addFact('size', $sizeValue); $this->knowledgeBase->addFact('legs', $legsValue); $workingMemory = $this->engine->run($this->knowledgeBase); $facts = $this->knowledgeBase->getFacts(); $this->assertSimpleFact('fly', $flyValue, $facts); $this->assertSimpleFact('size', $sizeValue, $facts); $this->assertSimpleFact('legs', $legsValue, $facts); $this->assertSimpleFact('animal', $expectedAnimal, $facts); $this->assertSimpleFact('sound', $expectedSound, $facts); $expectedRulesObjects = []; foreach ($expectedRules as $expectedRuleKey) { $expectedRulesObjects[] = $this->rules[$expectedRuleKey]; } $this->assertExplanation($expectedRulesObjects, $workingMemory); }
/** * Test Parent and children */ public function testParentAndChildren() { $joe = new \stdClass(); $joe->name = 'Joe'; $joe->dad = null; $joe->siblings = []; $joe->grandpas = []; $john = new \stdClass(); $joe->children = [$john]; $john->name = 'John'; $john->dad = $joe; $john->children = []; $john->siblings = []; $john->grandpas = []; $peter = new \stdClass(); $peter->name = 'Peter'; $peter->dad = $john; $peter->children = []; $peter->siblings = []; $peter->grandpas = []; $mery = new \stdClass(); $mery->name = 'Mery'; $mery->dad = $john; $mery->children = []; $mery->siblings = []; $mery->grandpas = []; $this->knowledgeBase->addFact('joe', $joe); $this->knowledgeBase->addFact('john', $john); $this->knowledgeBase->addFact('peter', $peter); $this->knowledgeBase->addFact('mery', $mery); $workingMemory = $this->engine->run($this->knowledgeBase); $facts = $this->knowledgeBase->getFacts(); $this->assertTrue(in_array($mery, $peter->siblings)); $this->assertTrue(in_array($peter, $mery->siblings)); $this->assertTrue(in_array($joe, $mery->grandpas)); $this->assertTrue(in_array($joe, $peter->grandpas)); }