Beispiel #1
0
        public IEnumerator ScaleMinMax()
        {
            float minScale = 0.5f;
            float maxScale = 2f;

            var bbox         = InstantiateSceneAndDefaultBbox();
            var scaleHandler = bbox.EnsureComponent <MinMaxScaleConstraint>();

            scaleHandler.ScaleMinimum = minScale;
            scaleHandler.ScaleMaximum = maxScale;
            yield return(null);

            Vector3 initialScale = bbox.transform.localScale;

            const int numHandSteps = 1;

            Vector3  initialHandPosition = new Vector3(0, 0, 0.5f);
            var      frontRightCornerPos = bbox.ScaleCorners[3].transform.position; // front right corner is corner 3
            TestHand hand = new TestHand(Handedness.Right);

            // Hands grab object at initial position
            yield return(hand.Show(initialHandPosition));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint));

            yield return(hand.MoveTo(frontRightCornerPos, numHandSteps));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            // No change to scale yet
            Assert.AreEqual(initialScale, bbox.transform.localScale);

            // Move hands beyond max scale limit
            yield return(hand.MoveTo(new Vector3(scaleHandler.ScaleMaximum * 2, scaleHandler.ScaleMaximum * 2, 0) + frontRightCornerPos, numHandSteps));

            // Assert scale at max
            Assert.AreEqual(Vector3.one * scaleHandler.ScaleMaximum, bbox.transform.localScale);

            // Move hands beyond min scale limit
            yield return(hand.MoveTo(new Vector3(-scaleHandler.ScaleMinimum * 2, -scaleHandler.ScaleMinimum * 2, 0) + frontRightCornerPos, numHandSteps));

            // Assert scale at min
            Assert.AreEqual(Vector3.one * scaleHandler.ScaleMinimum, bbox.transform.localScale);

            GameObject.Destroy(bbox.gameObject);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
        public void TestOnActionReceived()
        {
            var ar = new TestActionReceiver();
            var va = new VectorActuator(ar, ActionSpec.MakeDiscrete(1, 2, 3), "name");

            var discreteActions = new[] { 0, 1, 1 };
            var ab = new ActionBuffers(ActionSegment <float> .Empty,
                                       new ActionSegment <int>(discreteActions, 0, 3));

            va.OnActionReceived(ab);

            Assert.AreEqual(ar.LastActionBuffers, ab);
            va.ResetData();
            Assert.AreEqual(va.ActionBuffers.ContinuousActions, ActionSegment <float> .Empty);
            Assert.AreEqual(va.ActionBuffers.DiscreteActions, ActionSegment <int> .Empty);
        }
        public unsafe void TestBoxColliderCreate()
        {
            float3     center       = new float3(-10.10f, 10.12f, 0.01f);
            quaternion orientation  = quaternion.AxisAngle(math.normalize(new float3(1.4f, 0.2f, 1.1f)), 38.50f);
            float3     size         = new float3(0.01f, 120.40f, 5.4f);
            float      convexRadius = 0.0f;
            var        collider     = BoxCollider.Create(center, orientation, size, convexRadius);
            var        boxCollider  = UnsafeUtilityEx.AsRef <BoxCollider>(collider.GetUnsafePtr());

            Assert.AreEqual(center, boxCollider.Center);
            Assert.AreEqual(orientation, boxCollider.Orientation);
            Assert.AreEqual(size, boxCollider.Size);
            Assert.AreEqual(convexRadius, boxCollider.ConvexRadius);
            Assert.AreEqual(CollisionType.Convex, boxCollider.CollisionType);
            Assert.AreEqual(ColliderType.Box, boxCollider.Type);
        }
Beispiel #4
0
        public void MessageDisaposeTest()
        {
            int count      = 0;
            var subject    = new Subject <int>();
            var disposable = subject.Subscribe(num => count += num, () => count += 1);

            subject.OnNext(1);

            // 購読終了
            disposable.Dispose();

            subject.OnNext(1);
            subject.OnCompleted();

            Assert.AreEqual(1, count, "Disposeを呼び出したので途中で購読が中止されている");
        }
Beispiel #5
0
        public void NodeNoDuplicationTest()
        {
            Node a = new Node();
            Node b = new Node();

            a.ConnectTo(b);
            a.ConnectTo(b);

            int count = 0;

            foreach (var e in a.OutEdges)
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
Beispiel #6
0
        public void SolveTest()
        {
            var jacobian = new AngularLimit2DJacobian()
            {
                BFromA = quaternion.identity
            };

            var velocityA = MotionVelocity.Zero;
            var velocityB = MotionVelocity.Zero;
            var timestep  = 1.0f;

            jacobian.Solve(ref velocityA, ref velocityB, timestep);

            Assert.AreEqual(MotionVelocity.Zero, velocityA);
            Assert.AreEqual(MotionVelocity.Zero, velocityB);
        }
Beispiel #7
0
        public void SolveTest()
        {
            var jacobian = new LinearLimitJacobian()
            {
                WorldFromA = RigidTransform.identity, WorldFromB = RigidTransform.identity
            };

            var velocityA = MotionVelocity.Zero;
            var velocityB = MotionVelocity.Zero;
            var timestep  = 1.0f;

            jacobian.Solve(ref velocityA, ref velocityB, timestep);

            Assert.AreEqual(MotionVelocity.Zero, velocityA);
            Assert.AreEqual(MotionVelocity.Zero, velocityB);
        }
Beispiel #8
0
        public void CaseInsensitiveMatch()
        {
            // disabling stripEngineCode will be reported as an issue
            PlayerSettings.stripEngineCode = false;

            var issues       = Utility.Analyze(IssueCategory.ProjectSettings);
            var stringFilter = new TextFilter
            {
                matchCase          = false,
                searchDependencies = false,
                searchText         = "engine code stripping"
            };
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

            Assert.AreEqual(1, filteredIssues.Count());
        }
Beispiel #9
0
        public void FilenameMatch()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Code);
            var stringFilter  = new TextFilter
            {
                matchCase          = false,
                searchDependencies = false,
                searchText         = "FilterTests.cs"
            };
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

            Assert.AreEqual(1, filteredIssues.Count());
        }
        public void SourceScope()
        {
            var registry     = new UTinyRegistry();
            var builtInCount = registry.Count;
            var sourceId     = "test";

            using (registry.SourceIdentifierScope(sourceId))
            {
                registry.CreateType(UTinyId.New(), "TestType", UTinyTypeCode.Component);
            }

            Assert.AreEqual(builtInCount + 1, registry.Count);

            registry.UnregisterAllBySource(sourceId);
            Assert.AreEqual(builtInCount, registry.Count);
        }
        public static void TestMyParentPrivateComponent(GameObject obj)
        {
            Assert.IsTrue(obj != null);
            var test = obj.GetComponent <ProcessorTestComponent>();

            Assert.IsTrue(test != null);
            SerializedObject so = new SerializedObject(test);
            var prop            = so.FindProperty("parentPrivateComponent");
            var result          = test.GetComponentInParent <Renderer>();

            if (result == null)
            {
                Assert.IsNull(prop.objectReferenceValue);
            }
            Assert.AreEqual(result, prop.objectReferenceValue);
        }
        public void MarkersShouldSetCorrectly()
        {
            const int MAX_MARKERS    = 5;
            const int EXCLUSION_AREA = 1;

            var markerPrefab = new GameObject().AddComponent <UserMarkerObject>();
            var overlay      = new GameObject();

            Func <float, float, Vector3> coordToMapPosFunc = (x, y) => { return(new Vector3(x, y, 0)); };

            // create scenes to test
            var scenes = new List <HotScenesController.HotSceneInfo>();

            scenes.Add(CreateSceneInfo(new Vector2Int(0, 0)));
            scenes.Add(CreateSceneInfo(new Vector2Int(3, 4)));
            scenes.Add(CreateSceneInfo(new Vector2Int(-4, -4)));

            // create handler
            MarkersHandler handler = new MarkersHandler(markerPrefab, overlay.transform, MAX_MARKERS, coordToMapPosFunc);

            Assert.AreEqual(MAX_MARKERS, handler.availableMarkers.Count);
            Assert.AreEqual(0, handler.usedMarkers.Count);

            // set exclusion area and set markers for scenes
            handler.SetExclusionArea(Vector2Int.zero, EXCLUSION_AREA);
            handler.SetMarkers(scenes);

            // check pools count and marker hidden by exclusion area
            Assert.AreEqual(MAX_MARKERS - scenes.Count, handler.availableMarkers.Count);
            Assert.AreEqual(scenes.Count, handler.usedMarkers.Count);
            Assert.AreEqual(scenes.Count - 1, GetActiveGameObjectsInParent(overlay.transform), "A marker should be hidden by exclusion area");

            // move exclusion area and check markers hidden by exclusion area
            handler.SetExclusionArea(new Vector2Int(6, 6), EXCLUSION_AREA);
            Assert.AreEqual(scenes.Count, GetActiveGameObjectsInParent(overlay.transform), "All markers should be visible");

            // remove a scene and check pools count
            scenes.RemoveAt(0);
            handler.SetMarkers(scenes);
            Assert.AreEqual(MAX_MARKERS - scenes.Count, handler.availableMarkers.Count);
            Assert.AreEqual(scenes.Count, handler.usedMarkers.Count);

            handler.Dispose();
            UnityEngine.Object.Destroy(markerPrefab);
            UnityEngine.Object.Destroy(overlay);
        }
Beispiel #13
0
        public void AStarTest()
        {
            Assert.IsTrue(map.AStar(
                              first,
                              third,
                              Lunari.Tsuki.Graphs.Graphs.ZeroHeuristics,
                              out var path
                              ));
            Assert.IsNotNull(path);

            var expected = new[] { first, second, third };

            for (var i = 0; i < path.Indices.Length; i++)
            {
                Assert.AreEqual(expected[i], path.Indices[i]);
            }
        }
Beispiel #14
0
        public void ReactivePropetyTest()
        {
            var rp = new ReactiveProperty <int>(10);

            rp.Value = 20;
            Assert.AreEqual(20, rp.Value, "値を代入したので20");

            // Subscribeもできる(Subscribe時に現在の値も発行される)
            int count = 0;

            rp.Subscribe(num => count += num);
            Assert.AreEqual(20, count, "Subscribeしたときに現在の値が発行されて20");

            // 値を書き換えたときにOnNextが飛ぶ
            rp.Value = 30;
            Assert.AreEqual(50, count, "30を代入することでSubscribeが呼び出されて50");
        }
Beispiel #15
0
        public void SubjectにIObserverの代わりにラムダを登録する()
        {
            var value = default(string);

            var subject = new Subject <string>();

            subject.Subscribe(
                onNext: x => value       = x,
                onError: error => value  = "Error",
                onCompleted: () => value = "Complete");

            subject.OnNext("Next");
            Assert.AreEqual("Next", value);

            subject.OnCompleted();
            Assert.AreEqual("Complete", value);
        }
Beispiel #16
0
        public void SubjectMyWhereTest()
        {
            var subject = new Subject <int>();

            int count = 0;

            // 自分で作ったFilterを挟んでSubscribeしてみる
            subject
            .FilterOperator(num => num == 1)
            .Subscribe(num => count += num);

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);

            Assert.AreEqual(1, count, "自作したフィルタで1以外は弾く");
        }
Beispiel #17
0
        public void SubjectWhereTest()
        {
            var subject = new Subject <int>();

            int count = 0;

            subject
            .Where(num => num == 1)
            .Subscribe(num => count += num);

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnNext(4);

            Assert.AreEqual(1, count, "Whereで1以外はフィルタリングされたので1");
        }
Beispiel #18
0
        public void ValidationError()
        {
            bool errorFixed = false;

            // Set up a validation check ...
            MockRuntime.Instance.TestCallback = (s, o) =>
            {
                if (s == "GetValidationChecks")
                {
                    var validationChecks = o as List <OpenXRFeature.ValidationRule>;
                    validationChecks?.Add(new OpenXRFeature.ValidationRule
                    {
                        message        = "Mock Validation Fail",
                        checkPredicate = () => errorFixed,
                        fixIt          = () => errorFixed = true,
                        error          = true
                    });
                }

                return(true);
            };

            // Try to build the player ...
            var report = zBuildHookTests.BuildMockPlayer();

            // It will fail because of the above validation issue ...
            Assert.AreEqual(BuildResult.Failed, report.summary.result);

            // There's one validation issue ...
            var validationIssues = new List <OpenXRFeature.ValidationRule>();

            OpenXRProjectValidation.GetCurrentValidationIssues(validationIssues, BuildTargetGroup.Standalone);
            Assert.AreEqual(1, validationIssues.Count);

            // Fix it ...
            Assert.IsFalse(errorFixed);
            validationIssues[0].fixIt.Invoke();
            Assert.IsTrue(errorFixed);

            // Now there's zero validation issues ...
            OpenXRProjectValidation.GetCurrentValidationIssues(validationIssues, BuildTargetGroup.Standalone);
            Assert.AreEqual(0, validationIssues.Count);

            // Close the validation window ...
            OpenXRProjectValidationWindow.CloseWindow();
        }
        public IEnumerator AddSingletonByAwake()
        {
            DummySingletonB singleton = new GameObject("TrueSingleton").AddComponent <DummySingletonB>();

            yield return(null);

            DummySingletonB secondSingleton = DummySingletonB.GetOrCreateInstance();

            DummySingletonB thirdSingleton = new GameObject("FakeSingleton").AddComponent <DummySingletonB>();

            yield return(null);

            Assert.IsNotNull(singleton);
            Assert.IsNotNull(secondSingleton);
            Assert.IsNull(thirdSingleton);
            Assert.AreEqual(singleton, secondSingleton);
        }
Beispiel #20
0
        public void TearDown()
        {
            bool leak = false;

            Api.uv_walk(Api.uv_default_loop(), (handle, arg) =>
            {
                leak = true;
                Api.uv_close(handle, null);
            }, IntPtr.Zero);
            Assert.AreEqual(0, Api.uv_run(Api.uv_default_loop(), RunMode.Default));
            Assert.AreEqual(0, Api.uv_loop_close(Api.uv_default_loop()));

            if (leak)
            {
                throw new Exception("leak handles");
            }
        }
        public void SolveTest()
        {
            var jacobian = new ContactJacobian();

            var jacHeader             = new JacobianHeader();
            var velocityA             = MotionVelocity.Zero;
            var velocityB             = MotionVelocity.Zero;
            var stepInput             = new Solver.StepInput();
            var collisionEventsWriter = new BlockStream.Writer();

            jacobian.Solve(ref jacHeader, ref velocityA, ref velocityB, stepInput, ref collisionEventsWriter);

            Assert.AreEqual(new JacobianHeader(), jacHeader);
            Assert.AreEqual(MotionVelocity.Zero, velocityA);
            Assert.AreEqual(MotionVelocity.Zero, velocityB);
            Assert.AreEqual(new BlockStream.Writer(), collisionEventsWriter);
        }
            public void MockListRequest()
            {
                mockListRequester.Get
                .Subscribe(x =>
                {
                    x.ForEach(xx =>
                              Debug.Log(xx.title)
                              );
                    Assert.AreEqual(x[0].title, "Array index zero");
                    Assert.AreEqual(x[1].title, "Array index one");
                })
                .AddTo(dispose);

                var param = new SampleParamter(city: 130010);

                mockListRequester.Dispatch(param);
            }
        public static void TestMyParentPublicComponent(GameObject obj)
        {
            Assert.IsTrue(obj != null);
            var test = obj.GetComponent <ProcessorTestComponent>();

            Assert.IsTrue(test != null);
            var result = test.GetComponentInParent <Renderer>();

            if (result == null)
            {
                Assert.IsNull(test.parentPublicComponent);
            }
            else
            {
                Assert.AreEqual(result, test.parentPublicComponent);
            }
        }
Beispiel #24
0
        public void EmptyStringMatchesAllIssues()
        {
            // disabling stripEngineCode will be reported as an issue
            PlayerSettings.stripEngineCode = false;

            var stringFilter = new TextFilter
            {
                matchCase          = true,
                searchDependencies = false,
                searchText         = string.Empty
            };

            var issues         = Utility.Analyze(IssueCategory.ProjectSettings);
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

            Assert.AreEqual(issues.Length, filteredIssues.Count());
        }
        public IEnumerator DisableObject()
        {
            float minScale = 0.5f;
            float maxScale = 2f;

            var bbox         = InstantiateSceneAndDefaultBbox();
            var scaleHandler = bbox.EnsureComponent <MinMaxScaleConstraint>();

            scaleHandler.ScaleMinimum = minScale;
            scaleHandler.ScaleMaximum = maxScale;
            yield return(null);

            Vector3 initialScale = bbox.transform.localScale;

            const int numHandSteps = 1;

            Vector3  initialHandPosition = new Vector3(0, 0, 0.5f);
            var      frontRightCornerPos = bbox.ScaleCorners[3].transform.position; // front right corner is corner 3
            TestHand hand = new TestHand(Handedness.Right);

            // Hands grab object at initial position
            yield return(hand.Show(initialHandPosition));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint));

            yield return(hand.MoveTo(frontRightCornerPos, numHandSteps));

            yield return(hand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            // Verify that scale works before deactivating
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Vector3 afterTransformScale = bbox.transform.localScale;

            Assert.AreNotEqual(initialScale, afterTransformScale);

            // Deactivate object and ensure that we don't scale
            bbox.gameObject.SetActive(false);
            yield return(null);

            bbox.gameObject.SetActive(true);
            yield return(hand.Move(Vector3.right * 0.2f, numHandSteps));

            Assert.AreEqual(afterTransformScale, bbox.transform.localScale);
        }
        public void CheckingPositions()
        {
            for (var z = 0u; z < WorldPosition.ChunkSize; z++)
            {
                for (var y = 0u; y < WorldPosition.ChunkSize; y++)
                {
                    for (var x = 0u; x < WorldPosition.ChunkSize; x++)
                    {
                        var lp = new WorldPosition.LocalPosition(x, y, z);
                        Assert.AreEqual(lp.x, x);
                        Assert.AreEqual(lp.y, y);
                        Assert.AreEqual(lp.z, z);

                        Assert.AreEqual(lp, new WorldPosition.LocalPosition(lp.Index));
                    }
                }
            }
        }
Beispiel #27
0
        public void ObservableCreateTest()
        {
            int count = 0;

            Observable.Create <int>(observer =>
            {
                observer.OnNext(1);
                observer.OnCompleted();

                return(Disposable.Create(() =>
                {
                    // 終了時の処理
                    count += 1;
                }));
            }).Subscribe(num => count += num);

            Assert.AreEqual(2, count, "Observable.Create内でOnNextが呼び出されたのと、終了時の処理で2");
        }
Beispiel #28
0
        public void TestAddEdge()
        {
            Graph <NavGraphNode, GraphEdge> graph = new Graph <NavGraphNode, GraphEdge>();

            int[] edgeNodes = { 5, 7, 8 };
            int   node      = 5;

            for (int i = 0; i < edgeNodes.Length; i++)
            {
                graph.AddEdge(new GraphEdge(5, edgeNodes[i]), node);
            }

            GraphEdge expectEdge = new GraphEdge(node, edgeNodes[2]);
            GraphEdge actualEdge = graph.GetNodeEdges(node)[2];

            Assert.AreEqual(expectEdge.To, actualEdge.To);
            Assert.AreEqual(expectEdge.From, actualEdge.From);
        }
Beispiel #29
0
        public void TestSortActuators(string culture)
        {
            List <IActuator> actuators = new List <IActuator>();
            var actuator0 = new TestActuator(ActionSpec.MakeContinuous(2), "Apple");
            var actuator1 = new TestActuator(ActionSpec.MakeContinuous(2), "Æble");

            actuators.Add(actuator0);
            actuators.Add(actuator1);

            var originalCulture = CultureInfo.CurrentCulture;

            CultureInfo.CurrentCulture = new CultureInfo(culture);
            ActuatorManager.SortActuators(actuators);
            CultureInfo.CurrentCulture = originalCulture;

            Assert.AreEqual(actuator1, actuators[0]);
            Assert.AreEqual(actuator0, actuators[1]);
        }
Beispiel #30
0
        public void TestHeuristic()
        {
            var manager = new ActuatorManager(2);
            var va1     = new TestActuator(ActionSpec.MakeDiscrete(1, 2, 3), "name");
            var va2     = new TestActuator(ActionSpec.MakeDiscrete(3, 2, 1, 8), "name1");

            manager.Add(va1);
            manager.Add(va2);

            var actionBuf = new ActionBuffers(Array.Empty <float>(), new[] { 0, 0, 0, 0, 0, 0, 0 });

            manager.ApplyHeuristic(actionBuf);

            Assert.IsTrue(va1.m_HeuristicCalled);
            Assert.AreEqual(va1.m_DiscreteBufferSize, 3);
            Assert.IsTrue(va2.m_HeuristicCalled);
            Assert.AreEqual(va2.m_DiscreteBufferSize, 4);
        }