/// <summary> /// Construct a depdenency graph of the <see cref="Character"/>'s <see cref="ModifierSource"/>s. /// </summary> /// <param name="character"> /// The <see cref="Character"/> to generate the dependency graph for. This cannot be null. /// </param> /// <param name="modifierSources"> /// The already extracted list of <see cref="ModifierSource"/>s to use. This cannot be null. /// </param> /// <returns> /// A <see cref="GraphNode{ModifierSource}"/> that is the root node of a dependency graph. The root /// node can be ignored and is not part of the graph itself. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> internal static GraphNode<ModifierSource> ConstructDependencyGraph(Character character, IList<ModifierSource> modifierSources) { if (character == null) { throw new ArgumentNullException("character"); } if (modifierSources == null) { throw new ArgumentNullException("modifierSources"); } GraphNode<ModifierSource> root; IEqualityComparer<ModifierSource> comparer; Dictionary<ModifierSource, GraphNode<ModifierSource>> graphNodeLookup; // Rather than use "EqualityComparer<ModifierSource>.Default", use identity equality. // This allows two instances of the same modifier source with the same name to be used // within the graph. This can occur frequently with powers. comparer = new IdentityEqualityComparer<ModifierSource>(); // Optimization for GraphNode.Find(). graphNodeLookup = new Dictionary<ModifierSource, GraphNode<ModifierSource>>(); // Construct a dependency graph. root = new GraphNode<ModifierSource>(new NullModifierSource(), comparer); foreach (ModifierSource modifierSource in modifierSources) { List<KeyValuePair<ModifierSource, ModifierSource>> dependencies; GraphNode<ModifierSource> parentGraphNode; GraphNode<ModifierSource> childGraphNode; // Get the dependencies dependencies = modifierSource.GetDependencies(character); // For each dependency, find the source ModifierSource and add // the destination under it. foreach (KeyValuePair<ModifierSource, ModifierSource> dependency in dependencies) { // Find the parent of the dependency if (!graphNodeLookup.TryGetValue(dependency.Key, out parentGraphNode)) { parentGraphNode = new GraphNode<ModifierSource>(dependency.Key, comparer); root.AddChild(parentGraphNode); graphNodeLookup[dependency.Key] = parentGraphNode; } // Find the child of the dependency if (!graphNodeLookup.TryGetValue(dependency.Value, out childGraphNode)) { childGraphNode = new GraphNode<ModifierSource>(dependency.Value, comparer); graphNodeLookup[dependency.Value] = childGraphNode; } // Add the child to the parent parentGraphNode.AddChild(childGraphNode); } } return root; }
public void Equals_returns_true_if_entity_types_and_values_are_equal([Frozen] IGetsEntityTypeForIdentityEquality equalityTypeProvider, IdentityEqualityComparer sut, IIdentity identity1, IIdentity identity2) { Mock.Get(identity1).SetupGet(x => x.Value).Returns(1); Mock.Get(identity1).SetupGet(x => x.EntityType).Returns(typeof(Cat)); Mock.Get(equalityTypeProvider).Setup(x => x.GetIdentityEqualityType(typeof(Cat))).Returns(typeof(Animal)); Mock.Get(identity2).SetupGet(x => x.Value).Returns(1); Mock.Get(identity2).SetupGet(x => x.EntityType).Returns(typeof(Dog)); Mock.Get(equalityTypeProvider).Setup(x => x.GetIdentityEqualityType(typeof(Dog))).Returns(typeof(Animal)); Assert.That(sut.Equals(identity1, identity2), Is.True); }
public void Equals_returns_false_if_right_identity_is_null(IdentityEqualityComparer sut, IIdentity identity) { Assert.That(sut.Equals(identity, null), Is.False); }
public void Equals_returns_true_if_both_identities_are_reference_equal(IdentityEqualityComparer sut, IIdentity identity) { Assert.That(sut.Equals(identity, identity), Is.True); }
public void GetHashCode_gets_hash_code_equal_to_hash_of_entity_type_and_identity_value([Frozen] IGetsEntityTypeForIdentityEquality equalityTypeProvider, IdentityEqualityComparer sut, IIdentity identity) { Mock.Get(identity).SetupGet(x => x.Value).Returns(55); Mock.Get(identity).SetupGet(x => x.EntityType).Returns(typeof(Cat)); Mock.Get(equalityTypeProvider).Setup(x => x.GetIdentityEqualityType(typeof(Cat))).Returns(typeof(Animal)); Assert.That(sut.GetHashCode(identity), Is.EqualTo(55.GetHashCode() ^ typeof(Animal).GetHashCode())); }
public override int GetHashCode() => IdentityEqualityComparer <Utilisateur> .StaticGetHashCode(this);
public bool Equals(Utilisateur other) => IdentityEqualityComparer <Utilisateur> .StaticEquals(this, other) && Nom == other.Nom;
public override int GetHashCode() => IdentityEqualityComparer <Projet> .StaticGetHashCode(this);
public bool Equals(Projet other) => IdentityEqualityComparer <Projet> .StaticEquals(this, other) && Nom == other.Nom;