def testThatDependentsAreListedAfterDependencies(self): attrA = self.addAttributeToCharacter() attrB = self.addAttributeToCharacter([attrA]) attrC = self.addAttributeToCharacter([attrB]) expected = [attrB, attrC] graph = AttributeDependentGraph(attrA) actual = list(graph.items()) self.assertEqual(actual, expected)
def testThatDependentsOfManyAttributesAreListedAtTheirLatestPosition(self): attrA = self.addAttributeToCharacter() attrB = self.addAttributeToCharacter([attrA]) attrC = self.addAttributeToCharacter([attrA, attrB]) attrD = self.addAttributeToCharacter([attrC]) expected = [attrB, attrC, attrD] graph = AttributeDependentGraph(attrA) actual = list(graph.items()) self.assertEqual(actual, expected)
def setValue(self, instance, newValue): super(CharacterAttribute, self).setValue(instance, newValue) attrGraph = AttributeDependentGraph(self) changedAttributes = {self.id: self.getValue(instance)} for dependentAttribute in attrGraph.items(): newValue = dependentAttribute.calculateNewValue(instance) changedAttributes[dependentAttribute.id] = newValue return changedAttributes
def testThatDependentsOfAllAttributesAreListed(self): pathAFirst = self.addAttributeToCharacter() pathASecond = self.addAttributeToCharacter([pathAFirst]) pathAThird = self.addAttributeToCharacter([pathASecond]) pathBFirst = self.addAttributeToCharacter() pathBSecond = self.addAttributeToCharacter([pathBFirst]) pathBThird = self.addAttributeToCharacter([pathBSecond]) bottomAttr = self.addAttributeToCharacter([pathASecond, pathBThird]) expected = [[pathASecond, pathBSecond], [pathAThird, pathBThird], [bottomAttr]] graph = AttributeDependentGraph([pathAFirst, pathBFirst]) actual = list(graph.items()) self.assertGraphEqual(actual, expected)