public void CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); anyComponentTypeRule.componentTypes.Add(typeof(RuleStub)); negationRule.rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.targetValidity = new RuleContainer { Interface = negationRule }; subject.ManualOnEnable(); Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3 expectedStart = Vector3.zero; Vector3 expectedEnd = validSurface.transform.position - (Vector3.forward * (validSurface.transform.localScale.z / 2f)); Assert.AreEqual(expectedStart, subject.Points[0]); Assert.AreEqual(expectedEnd, subject.Points[1]); Assert.IsNull(subject.TargetHit); Assert.IsTrue(castResultsChangedMock.Received); }
public void SetUp() { containingObject = new GameObject(); container = new RuleContainer(); subject = containingObject.AddComponent <NegationRule>(); container.Interface = subject; }
public void InvalidSurfaceDueToPolicy() { UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); anyComponentTypeRule.componentTypes.Add(typeof(RuleStub)); negationRule.rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.targetValidity = new RuleContainer { Interface = negationRule }; subject.searchOrigin = searchOrigin; subject.searchDirection = Vector3.forward; Physics.Simulate(Time.fixedDeltaTime); subject.Locate(); Assert.IsFalse(surfaceLocatedMock.Received); }
public IEnumerator AddInvalidCollisionDueToRule() { UnityEventListenerMock firstStartedMock = new UnityEventListenerMock(); UnityEventListenerMock countChangedMock = new UnityEventListenerMock(); UnityEventListenerMock contentsChangedMock = new UnityEventListenerMock(); UnityEventListenerMock allStoppedMock = new UnityEventListenerMock(); subject.FirstStarted.AddListener(firstStartedMock.Listen); subject.CountChanged.AddListener(countChangedMock.Listen); subject.ContentsChanged.AddListener(contentsChangedMock.Listen); subject.AllStopped.AddListener(allStoppedMock.Listen); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.AddComponent <RuleStub>(); NegationRule negationRule = oneContainer.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = oneContainer.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.CollisionValidity = new RuleContainer { Interface = negationRule }; Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); subject.Add(oneData); Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); Object.DestroyImmediate(oneContainer); }
public IEnumerator CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.Origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f + Vector3.down * 4f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); yield return(null); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.MaximumLength = new Vector2(5f, 5f); subject.SegmentCount = 5; Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3[] expectedPoints = new Vector3[] { Vector3.zero, new Vector3(0f, -0.1f, 2.9f), new Vector3(0f, -1.4f, 4.4f), new Vector3(0f, -2.8f, 4.9f), new Vector3(0f, validSurface.transform.position.y + (validSurface.transform.localScale.y / 2f), validSurface.transform.position.z) }; for (int index = 0; index < subject.Points.Count; index++) { Assert.AreEqual(expectedPoints[index].ToString(), subject.Points[index].ToString(), "Index " + index); } Assert.AreEqual(validSurface.transform, subject.TargetHit.Value.transform); Assert.IsFalse(subject.IsTargetHitValid); Assert.IsTrue(castResultsChangedMock.Received); }
public IEnumerator ValidSurfaceDueToEventualTargetValidity() { Physics.autoSimulation = true; GameObject invalidSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject validSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject searchOrigin = new GameObject("SearchOrigin"); UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.transform.position = Vector3.forward * 10f; invalidSurface.transform.position = Vector3.forward * 5f; invalidSurface.AddComponent <RuleStub>(); NegationRule negationRule = invalidSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = invalidSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsTrue(surfaceLocatedMock.Received); Assert.AreEqual(validSurface.transform, subject.surfaceData.Transform); Object.DestroyImmediate(invalidSurface); Object.DestroyImmediate(validSurface); Object.DestroyImmediate(searchOrigin); }
public IEnumerator ConsumeExclusion() { UnityEventListenerMock consumedMock = new UnityEventListenerMock(); UnityEventListenerMock clearedMock = new UnityEventListenerMock(); subject.Consumed.AddListener(consumedMock.Listen); subject.Cleared.AddListener(clearedMock.Listen); GameObject publisherObject = new GameObject(); ActiveCollisionPublisher.PayloadData publisher = new ActiveCollisionPublisher.PayloadData(); publisher.PublisherContainer = publisherObject; publisherObject.AddComponent <RuleStub>(); NegationRule negationRule = containingObject.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = containingObject.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.PublisherValidity = new RuleContainer { Interface = negationRule }; Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); subject.Consume(publisher, null); Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); Object.DestroyImmediate(publisherObject); }
public void CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f + Vector3.down * 4f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); anyComponentTypeRule.componentTypes.Add(typeof(RuleStub)); negationRule.rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.targetValidity = new RuleContainer { Interface = negationRule }; subject.maximumLength = new Vector2(5f, 5f); subject.segmentCount = 5; Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3[] expectedPoints = new Vector3[] { Vector3.zero, new Vector3(0f, -0.1f, 2.9f), new Vector3(0f, -1.4f, 4.4f), new Vector3(0f, -2.8f, 4.9f), new Vector3(0f, validSurface.transform.position.y + (validSurface.transform.localScale.y / 2f), validSurface.transform.position.z) }; for (int i = 0; i < subject.Points.Count; i++) { Assert.AreEqual(expectedPoints[i].ToString(), subject.Points[i].ToString(), "Index " + i); } Assert.IsNull(subject.TargetHit); Assert.IsTrue(castResultsChangedMock.Received); }
public IEnumerator InvalidSurfaceDueToTargetPointValidity() { Physics.autoSimulation = true; GameObject invalidSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject searchOrigin = new GameObject("SearchOrigin"); UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); invalidSurface.transform.position = Vector3.forward * 5f; invalidSurface.AddComponent <RuleStub>(); NegationRule negationRule = invalidSurface.AddComponent <NegationRule>(); Vector3RuleStub vector3Point = invalidSurface.AddComponent <Vector3RuleStub>(); vector3Point.toMatch = invalidSurface.transform.position - (Vector3.forward * invalidSurface.transform.localScale.z * 0.5f); yield return(null); negationRule.Rule = new RuleContainer { Interface = vector3Point }; subject.TargetPointValidity = new RuleContainer { Interface = negationRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsFalse(surfaceLocatedMock.Received); Assert.IsNull(subject.surfaceData.Transform); Object.DestroyImmediate(invalidSurface); Object.DestroyImmediate(searchOrigin); }
public void ConsumeExclusion() { UnityEventListenerMock consumedMock = new UnityEventListenerMock(); UnityEventListenerMock clearedMock = new UnityEventListenerMock(); subject.Consumed.AddListener(consumedMock.Listen); subject.Cleared.AddListener(clearedMock.Listen); GameObject publisherObject = new GameObject(); ActiveCollisionPublisher publisher = publisherObject.AddComponent <ActiveCollisionPublisher>(); publisher.sourceContainer = publisherObject; publisherObject.AddComponent <RuleStub>(); NegationRule negationRule = containingObject.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = containingObject.AddComponent <AnyComponentTypeRule>(); anyComponentTypeRule.componentTypes.Add(typeof(RuleStub)); negationRule.rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.publisherValidity = new RuleContainer { Interface = negationRule }; Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); subject.Consume(publisher, null); Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); Object.DestroyImmediate(publisherObject); }
public IEnumerator CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.Origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); yield return(null); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.ManualOnEnable(); Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3 expectedStart = Vector3.zero; Vector3 expectedEnd = validSurface.transform.position - (Vector3.forward * (validSurface.transform.localScale.z / 2f)); Assert.AreEqual(expectedStart, subject.Points[0]); Assert.AreEqual(expectedEnd, subject.Points[1]); Assert.AreEqual(validSurface.transform, subject.TargetHit.Value.transform); Assert.IsFalse(subject.IsTargetHitValid); Assert.IsTrue(castResultsChangedMock.Received); }
public IEnumerator InvalidSurfaceDueToPolicy() { Physics.autoSimulation = true; UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsFalse(surfaceLocatedMock.Received); }