Ejemplo n.º 1
0
        [RecursiveMethod] // Just here to test calling out to other types from recursive methods
        public void ExecuteTests()
        {
            tester.TestAssertion("Basic recursion 4!", Factorial(4) == 24);
            tester.TestAssertion("Basic recursion 5!", Factorial(5) == 120);
            tester.TestAssertion("Basic recursion 12!", Factorial(12) == 479001600);

            int arraySize = Random.Range(10000, 11000);

            int[] shuffleArray = InitTestArray(arraySize); // Fuzz a little

            ShuffleArray(shuffleArray);
            QuickSortStatic(shuffleArray, 0, shuffleArray.Length - 1);

            bool sorted = IsSorted(shuffleArray);

            if (!sorted)
            {
                Debug.LogWarning($"Array size that failed {arraySize}");
            }

            tester.TestAssertion("Quicksort recursion", sorted);

            RecursionTest self = this;

            ShuffleArray(shuffleArray);
            self.QuickSort(shuffleArray, 0, shuffleArray.Length - 1);

            tester.TestAssertion("Quicksort external call", IsSorted(shuffleArray));

            tester.TestAssertion("Function parameter swap recursion", CombineStrings(6, "a", "b") == "abababababababababababababababababababababababababababababababa");

            tester.TestAssertion("Function parameter swap recursion external call", self.CombineStringsExtern(6, "a", "b") == "abababababababababababababababababababababababababababababababa");
            tester.TestAssertion("Params array recursion", CombineStringsParams(4, "a", "b", "c", "d", "e") == "aeaeaaaaeaeeeeeaeeeeeaeeeeeaeeeeaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaa");
            tester.TestAssertion("Nested call recursion", CombineStringsNested(3, "a", "b") == "abaccbcccabccacccccbaccbccccccabccacccbaccbcccccabccaccccccc");

            tester.TestAssertion("Count children recursively foreach", CountChildren(transform) == 20);
            tester.TestAssertion("Count children recursively foreach expression", CountChildrenForeachExpression(transform) == 20);
            tester.TestAssertion("Count children recursively foreach access", CountChildrenForeachAccessExpression(transform) == 20);

            externChildCount = 0;
            CountChildrenExternalCount(transform);

            tester.TestAssertion("Count children recursively foreach external counter", externChildCount == 20);

            customEventCounter = 4;
            CustomEventExternRecursion();

            tester.TestAssertion("SendCustomEvent extern recursion", customEventCounter == 24);

            customEventCounter = 4;
            CustomEventRecursion();
            tester.TestAssertion("SendCustomEvent recursion", customEventCounter == 24);

            tester.TestAssertion("Recursive short circuit operators", ShortCircuitRecursion(true, 2, true) == false);

            memory = 10;
            tester.TestAssertion("Postfix recursion", Sum() == 55);
        }
Ejemplo n.º 2
0
        public string CombineStringsExtern(int count, string a, string b)
        {
            if (count == 0)
            {
                return("");
            }

            RecursionTest self = this;

            //Debug.Log($"count: {count}, a: {a}, b: {b}"/*, a result: {aResult}, b result: {bResult}"*/);

            return(string.Concat(a, self.CombineStringsExtern(count - 1, b, a), self.CombineStringsExtern(count - 1, a, b)));
        }
Ejemplo n.º 3
0
        public void CustomEventExternRecursion()
        {
            int originalCounter = customEventCounter;

            RecursionTest self = this;

            if (customEventCounter == 1)
            {
                return;
            }

            customEventCounter -= 1;
            self.SendCustomEvent(nameof(CustomEventExternRecursion));

            customEventCounter = originalCounter * customEventCounter;
        }