Beispiel #1
0
        [Test] public void RedundantRequirements()
        {
            ComponentRequirementMap map = new ComponentRequirementMap();

            CollectionAssert.AreEquivalent(new[] { typeof(TestComponentB1) }, map.GetRequirements(typeof(TestComponentB2)));
            CollectionAssert.AreEqual(new[] { typeof(TestComponentB1) }, map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentB2)));

            Assert.IsTrue(map.IsRequired(typeof(TestComponentB2), typeof(TestComponentB1)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentB2), typeof(TestComponentB2)));

            Assert.IsFalse(map.IsRequirementMet(new GameObject(), typeof(TestComponentB2)));
            Assert.IsTrue(map.IsRequirementMet(new GameObject(), typeof(TestComponentB2), new[] { typeof(TestComponentB1) }));
        }
Beispiel #2
0
        [Test] public void InvalidRequirements()
        {
            ComponentRequirementMap map = new ComponentRequirementMap();

            // Expect that all invalid requirements have been ignored
            CollectionAssert.AreEquivalent(new Type[0], map.GetRequirements(typeof(TestComponentE1)));
            CollectionAssert.AreEquivalent(new Type[0], map.GetRequirements(typeof(TestComponentE2)));
            CollectionAssert.AreEqual(new Type[0], map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentE1)));
            CollectionAssert.AreEqual(new Type[0], map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentE2)));

            Assert.IsFalse(map.IsRequired(typeof(TestComponentE1), typeof(Pixmap)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentE2), typeof(NonPublicComponent)));

            Assert.IsTrue(map.IsRequirementMet(new GameObject(), typeof(TestComponentE1)));
            Assert.IsTrue(map.IsRequirementMet(new GameObject(), typeof(TestComponentE2)));
        }
Beispiel #3
0
        [Test] public void CyclicRequirements()
        {
            ComponentRequirementMap map = new ComponentRequirementMap();

            // In a cyclic dependency situation, behavior is undefined and there is no "right" solution.
            // For this test, just expect the system to not crash. Check some select results that we
            // can safely expect.
            TestingLogOutput logWatcher = new TestingLogOutput();

            Logs.AddGlobalOutput(logWatcher);

            map.GetRequirements(typeof(TestComponentC1));
            map.GetRequirements(typeof(TestComponentC2));
            map.GetRequirements(typeof(TestComponentC3));

            logWatcher.AssertNoErrors();
            logWatcher.AssertWarning();

            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC1));
            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC2));
            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC3));

            logWatcher.AssertNoErrors();
            logWatcher.AssertWarning();

            Assert.IsFalse(map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC1)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC2)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC3)));

            map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC2));
            map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC3));
            map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC1));
            map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC3));
            map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC1));
            map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC2));

            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2), typeof(TestComponentC3) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3), typeof(TestComponentC1) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1), typeof(TestComponentC2) });

            Logs.RemoveGlobalOutput(logWatcher);
        }