Exemplo n.º 1
0
  public Recursion()
    : this("foo")
  {
    this.m_child = this;

    // this.m_Parent = owner;

    // Stack overflow on next line analysis   
    this.s.ToString();

    //this.m_child.IsOpen = true;
  }
Exemplo n.º 2
0
        public void IsPalindrome()
        {
            // Arrange
            var recursion = new Recursion();

            // Act
            var isRadarPalindrome1 = recursion.IsPalindrome("RADAR");
            var isRadarPalindrome  = recursion.IsPalindrome("RADDAR");
            var isWrongPalindrome  = recursion.IsPalindrome("Wrong");

            // Assert
            Assert.IsTrue(isRadarPalindrome);
            Assert.IsTrue(isRadarPalindrome1);
            Assert.IsFalse(isWrongPalindrome);
        }
Exemplo n.º 3
0
        public void Opdracht10_MyListGetLast2547135Test()
        {
            //Arrange
            Recursion    recursion = new Recursion();
            MyList <int> list      = new MyList <int>(25);

            list.Add(47);
            list.Add(13);
            list.Add(5);
            //Act
            int result = list.GetLast();

            //Assert
            Assert.AreEqual(5, result);
        }
        internal static bool DisposedByReturnValue(ArgumentSyntax candidate, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out ExpressionSyntax?creation)
        {
            if (candidate.TryFirstAncestor(out TypeDeclarationSyntax? containingTypeDeclaration) &&
                semanticModel.TryGetNamedType(containingTypeDeclaration, cancellationToken, out var containingType))
            {
                using var recursion = Recursion.Borrow(containingType, semanticModel, cancellationToken);
                if (recursion.Target(candidate) is { } target)
                {
                    return(DisposedByReturnValue(target, recursion, out creation));
                }
            }

            creation = null;
            return(false);
        }
Exemplo n.º 5
0
 public override string ToString()
 {
     if (Recursion.TryLock(this))
     {
         try
         {
             return(SequenceToString(storage.GetSequence(offset), "[", "]", zo => zo.ToString()));
         }
         finally
         {
             Recursion.Unlock(this);
         }
     }
     return("[...]");
 }
Exemplo n.º 6
0
 protected override string ToStringContextImpl(Context ctx, bool friendly)
 {
     if (Recursion.TryLock(this))
     {
         try
         {
             return(SequenceToString(storage.GetSequence(offset), "[", "]", zo => zo.ToStringContext(ctx, friendly)));
         }
         finally
         {
             Recursion.Unlock(this);
         }
     }
     return("[...]");
 }
Exemplo n.º 7
0
        public void Opdracht11_MyListCountAapNootMiesTest()
        {
            //Arrange
            Recursion       recursion = new Recursion();
            MyList <string> list      = new MyList <string>("aap");

            list.Add("noot");
            list.Add("mies");
            list.Add("geen idee wat daarna komt");
            //Act
            int result = list.Count();

            //Assert
            Assert.AreEqual(4, result);
        }
Exemplo n.º 8
0
        public void testgetEncryptedString()
        {
            var encString = Recursion.findEncryptedWord("abcxcba");

            Assert.AreEqual("xbacbca", encString);

            encString = Recursion.findEncryptedWord("abcd");
            Assert.AreEqual("bacd", encString);

            encString = Recursion.findEncryptedWord("abc");
            Assert.AreEqual("bac", encString);

            encString = Recursion.findEncryptedWord("facebook");
            Assert.AreEqual("eafcobok", encString);
        }
Exemplo n.º 9
0
        internal static bool Stores(LocalOrParameter localOrParameter, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out ISymbol?container)
        {
            using var recursion = Recursion.Borrow(localOrParameter.Symbol.ContainingType, semanticModel, cancellationToken);
            using var walker    = UsagesWalker.Borrow(localOrParameter, semanticModel, cancellationToken);
            foreach (var usage in walker.Usages)
            {
                if (Stores(usage, recursion, out container))
                {
                    return(true);
                }
            }

            container = null;
            return(false);
        }
Exemplo n.º 10
0
        public void Opdracht12_MyListReverse2547135Test()
        {
            //Arrange
            var recursion = new Recursion();
            var list      = new MyList <int>(25);

            list.Add(47);
            list.Add(13);
            list.Add(5);
            //Act
            var result = list.Reverse().GetLast();

            //Assert
            Assert.AreEqual(25, result);
        }
Exemplo n.º 11
0
        public void GetIncreasingSequenceTest()
        {
            Recursion             target = new Recursion();             // TODO: Initialize to an appropriate value
            List <Recursion.HtWt> items  = new List <Recursion.HtWt>(); // TODO: Initialize to an appropriate value

            items.Add(new Recursion.HtWt(1, 2));
            items.Add(new Recursion.HtWt(2, 3));
            items.Add(new Recursion.HtWt(1, 4));
            items.Add(new Recursion.HtWt(5, 7));
            items.Add(new Recursion.HtWt(3, 9))
            ;
            List <Recursion.HtWt> expected = null; // TODO: Initialize to an appropriate value
            List <Recursion.HtWt> actual;

            actual = target.GetIncreasingSequence(items);
        }
Exemplo n.º 12
0
        public void Opdracht09_MergeSort51829342Test()
        {
            //Arrange
            Recursion  recursion = new Recursion();
            List <int> input     = new List <int> {
                5, 1, 8, 2, 9, 3, 4, 2
            };
            List <int> expectedResult = new List <int> {
                1, 2, 2, 3, 4, 5, 8, 9
            };
            //Act
            List <int> result = recursion.MergeSort(input);

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 13
0
        public string MiddlePermutation(string s)
        {
            var rec = new Recursion();

            rec.InputSet = rec.MakeCharArray(s);
            rec.CalcPermutation(0);
            var permutations         = rec.Result.OrderBy(r => r).ToList();
            var numberOfPermutations = permutations.Count;
            var result = permutations.Count == 0
                ? s
                : permutations.ElementAt(numberOfPermutations % 2 == 0
                    ? numberOfPermutations / 2 - 1
                    : (numberOfPermutations + 1) / 2 - 1);

            return(result);
        }
        public void Opdracht11_MyListEdgarsTest2()
        {
            //Arrange
            var recursion = new Recursion();
            var list      = new MyList <string>("aap");

            list.Add("noot");
            list.Add("mies");
            list.Add("mifvses");
            list.Add("vf");
            list.Add("geen idee wat daarna komt");
            //Act
            var result = list.Count();

            //Assert
            Assert.AreEqual(6, result);
        }
Exemplo n.º 15
0
        public void PowersetProblem()
        {
            Recursion          rec     = new Recursion();
            List <List <int> > results = rec.GetAllSubsetsProblem(new int[] { 3, 4 });
            StringBuilder      sb      = new StringBuilder();

            foreach (List <int> r in results)
            {
                sb.Clear();
                foreach (int n in r)
                {
                    sb.Append(n.ToString());
                }

                Console.WriteLine(sb.ToString());
            }
        }
Exemplo n.º 16
0
        public void TestFindPossiblePathsToReachACellInGrid()
        {
            var paths = Recursion.FindAllPathsToAGridCellFromTopLeftCorner(3, 3, 3, 3);

            Assert.IsNotNull(paths);
            Assert.AreEqual(paths.Count, 6);
            paths.ForEach(p => {
                Console.WriteLine(p);
            });

            paths = Recursion.FindAllPathsToAGridCellFromTopLeftCorner(4, 4, 4, 4);
            Assert.IsNotNull(paths);
            paths.ForEach(p =>
            {
                Console.WriteLine(p);
            });
        }
        private string GetItemsListCacheKey(Recursion recursion, int revision, string path)
        {
            switch (recursion)
            {
            case Recursion.Full:
                return(GetItemFullPathCacheKey(revision, path));

            case Recursion.OneLevel:
                return(GetItemOneLevelCacheKey(revision, path));

            case Recursion.None:
                return(GetItemNoRecursionCacheKey(revision, path));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Random random  = new Random();
            int    counter = 0;

            while (true)
            {
                if (counter > 4)
                {
                    break;
                }
                List <int> num = new List <int> {
                    1, 2, 3, 4, 5
                };
                //int n = random.Next(1, 5);
                //int n1 = random.Next(1, 5);
                //int n2 = random.Next(1, 5);
                //int n3 = random.Next(1, 5);
                //int n4 = random.Next(1, 5);
                HashSet <int> numbers = new HashSet <int>();
                // if (n != n1 && n != n2 && n !=n3 && n != n4 && n1 != n2 && n1 != n3 && n1 != n4 && n2 != n3 && n2 != n4 && n3 != n4){
                num
                //numbers.Add(n);
                //numbers.Add(n1);
                //numbers.Add(n2);
                //numbers.Add(n3);
                //numbers.Add(n4);
                    counter++;
                foreach (var m in numbers)
                {
                    Console.Write(m);
                }
                Console.WriteLine();
                // }

                //Console.Write("Input String>");
                string inputLine = "12345";

                Recursion rec = new Recursion();
                rec.InputSet = rec.MakeCharArray(inputLine);
                rec.CalcPermutation(0);

                Console.Write("# of Permutations: " + rec.PermutationCount);
            }
        }
Exemplo n.º 19
0
        public void FirstNaturalNumbers()
        {
            // Arrange
            var recursion = new Recursion();
            var expected  = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            // Act
            var actual = recursion.GetNaturalNumbers(10);

            // Assert
            Assert.AreEqual(10, actual.Count());
            foreach (var foundNumber in actual)
            {
                Assert.IsTrue(expected.Contains(foundNumber));
            }
        }
Exemplo n.º 20
0
        public List <string> ToStringCustom(Recursion limit)
        {
            List <string> tmp = new List <string>();

            tmp.Add("Article " + Id + " " + ArtText);
            if ((Comments.Count == 0) || (limit == 0))
            {
                return(tmp);
            }
            else
            {
                foreach (Comment item in Comments.Where(x => x.ParentId == null))
                {
                    tmp = tmp.Concat(item.ToStringCustom(limit--)).ToList();
                }
                return(tmp);
            }
        }
Exemplo n.º 21
0
    ///////////////////////////////////////////////////////////////////////////////////
    void WaitForNumOfSeconds()
    {
        var wait = Recursion.Action <int>((count, stack) =>
        {
            if (count == 0)
            {
                stack.Exit();
            }
            else
            {
                Thread.Sleep(1000);
                WriteLine("tick...");
                stack.Push(count - 1);
            }
        });

        wait(5);
    }
Exemplo n.º 22
0
        public bool IsPredictable(Recursion recursion)
        {
            if (!hasValidConnection)
            {
                return(true);
            }

            if (!recursion?.TryEnter(this) ?? false)
            {
                return(false);
            }

            var isPredictable = validConnectedPorts.All(cop => cop.IsPredictable(recursion));

            recursion?.Exit(this);

            return(isPredictable);
        }
Exemplo n.º 23
0
        public bool IsPredictable(Recursion recursion)
        {
            if (unit.isControlRoot)
            {
                return(true);
            }

            if (!recursion?.TryEnter(this) ?? false)
            {
                return(false);
            }

            var isPredictable = unit.relations.WithDestination(this).Where(r => r.source is ControlInput).All(r => ((ControlInput)r.source).IsPredictable(recursion));

            recursion?.Exit(this);

            return(isPredictable);
        }
Exemplo n.º 24
0
        private List <T> GetValue(Recursion recursion)
        {
            float   squaredRadius = Radius.GetValue <float>() * Radius.GetValue <float>();
            Vector3 originPoint   = Origin.GetValue <GameObject>().transform.position;

            T[] objects = Object.FindObjectsOfType <T>();

            List <T> radius = new List <T>(objects.Length);

            for (int i = 0; i < objects.Length; i++)
            {
                if ((objects[i].transform.position - originPoint).sqrMagnitude < squaredRadius)
                {
                    radius.Add(objects[i]);
                }
            }
            return(radius);
        }
        public void Opdracht08_Merge102030100Test()
        {
            //Arrange
            var recursion = new Recursion();
            var list_a    = new List <int> {
                10, 20, 30
            };
            var list_b = new List <int> {
                100
            };
            var expectedResult = new List <int> {
                10, 20, 30, 100
            };
            //Act
            var result = recursion.Merge(list_a, list_b);

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 26
0
        public void Opdracht08_Merge1020304025Test()
        {
            //Arrange
            Recursion  recursion = new Recursion();
            List <int> list_a    = new List <int> {
                10, 20, 30, 40
            };
            List <int> list_b = new List <int> {
                25
            };
            List <int> expectedResult = new List <int> {
                10, 20, 25, 30, 40
            };
            //Act
            List <int> result = recursion.Merge(list_a, list_b);

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 27
0
        public void Opdracht08_Merge13791379Test()
        {
            //Arrange
            Recursion  recursion = new Recursion();
            List <int> list_a    = new List <int> {
                1, 3, 7, 9
            };
            List <int> list_b = new List <int> {
                1, 3, 7, 9
            };
            List <int> expectedResult = new List <int> {
                1, 1, 3, 3, 7, 7, 9, 9
            };
            //Act
            List <int> result = recursion.Merge(list_a, list_b);

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Exemplo n.º 28
0
    ///////////////////////////////////////////////////////////////////////////////////
    void TailedRecursionWithLambda()
    {
        var fib_iter = Recursion.Func <int, int, int, int>(
            (fnext, f, count, stack) =>
        {
            if (count == 0)
            {
                stack.Exit(f);
            }
            else
            {
                stack.Push(fnext + f, fnext, count - 1);
            }
        });

        Func <int, int> fib = n => fib_iter(1, 0, n);

        fib(5);
    }
        private static ItemMetaData GetItems(TFSSourceControlProvider sourceControlProvider,
                                             int version,
                                             string path,
                                             Recursion recursion,
                                             bool loadPropertiesFromFile)
        {
            // Make sure path is decoded
            ItemMetaData item = null;

            if (loadPropertiesFromFile)
            {
                item = sourceControlProvider.GetItems(version, Helper.Decode(path), recursion);
            }
            else
            {
                item = sourceControlProvider.GetItemsWithoutProperties(version, Helper.Decode(path), recursion);
            }
            return(item);
        }
Exemplo n.º 30
0
        public override string ToString()
        {
            string MaybeQuote(ZilObject zo)
            {
                return(zo is ZilAtom ? "'" + zo : zo.ToString());
            }

            if (Recursion.TryLock(this))
            {
                try
                {
                    return($"%<OFFSET {Index} {MaybeQuote(StructurePattern)} {MaybeQuote(ValuePattern)}>");
                }
                finally
                {
                    Recursion.Unlock(this);
                }
            }
            return("%<OFFSET ...>");
        }
Exemplo n.º 31
0
        protected override string ToStringContextImpl(Context ctx, bool friendly)
        {
            string MaybeQuote(ZilObject zo)
            {
                return(zo is ZilAtom ? "'" + zo : zo.ToStringContext(ctx, friendly));
            }

            if (Recursion.TryLock(this))
            {
                try
                {
                    return($"%<OFFSET {Index} {MaybeQuote(StructurePattern)} {MaybeQuote(ValuePattern)}>");
                }
                finally
                {
                    Recursion.Unlock(this);
                }
            }
            return("%<OFFSET ...>");
        }
Exemplo n.º 32
0
 public void initInventory()
 {
     inventorySkills = new baseSkill[14];
     inventorySkills [0] = new Arrays ();
     inventorySkills [1] = new BreakAndContinue ();
     inventorySkills [2] = new DDOS ();
     inventorySkills [3] = new DefaultFunctions ();
     inventorySkills [4] = new FireWall ();
     inventorySkills [5] = new FunctionsWithInputOutput ();
     inventorySkills [6] = new FunctionsWithOutput ();
     inventorySkills [7] = new Hash ();
     inventorySkills [8] = new IfElse ();
     inventorySkills [9] = new InfiniteLoop ();
     inventorySkills [10] = new Loop ();
     inventorySkills [11] = new PacketSniffing ();
     inventorySkills [12] = new Recursion ();
     inventorySkills [13] = new Stack ();
     Debug.Log ("Finished Loading Inventory");
 }
Exemplo n.º 33
0
 private void Initialize(Application anApp, bool bAllTypes, Recursion recur, bool bDebug, bool bVBNet, int nVersion)
 {
     this._app = anApp;
     string languageName = GetLanguageName(bVBNet, nVersion);
     LZ.Reverse.Info._bVBNet = bVBNet;
     LZ.Reverse.Info._nVersion = nVersion;
     this._bAllTypes = bAllTypes;
     this._recur = recur;
     LZ.Reverse.Info._bDebug = bDebug;
     this._mdl = (Model) this._app.CreateModel(0x18112060, "|Language=" + languageName + "|Diagram=ClassDiagram", OpenModelFlags.omf_Default);
     this._mdl.Name = "Reverse";
     this._mdl.Code = "Reverse";
     NamespaceMapping.Model = this._mdl;
     ProperRef.Model = this._mdl;
     TypeMapping.Clear();
 }
Exemplo n.º 34
0
 public Reverser(Application anApp, bool bAllTypes, Recursion recur, bool bDebug, bool bVBNet, int nVersion)
 {
     this.Initialize(anApp, bAllTypes, recur, bDebug, bVBNet, nVersion);
 }
Exemplo n.º 35
0
 public Reverser(bool bAllTypes, Recursion recur, bool bDebug, bool bVBNet, int nVersion)
 {
     Application anApp = new ApplicationClass();
     anApp.Locked = true;
     this.Initialize(anApp, bAllTypes, recur, bDebug, bVBNet, nVersion);
 }