Exemple #1
0
        ///
        /// <param name="noOfInheritanceChains"> : User defined desired number of inheritance chains </param>
        /// <param name="inheritanceDepth"> : Maximum allowed inheritance depth </param>
        /// <param name="range">: Total number of classes </param>
        /// <returns> Something like this: {<3,5,1>,<7,2,6>} random but unique list of integers  </returns>
        public static List <List <int?> > getInheritanceList(int noOfInheritanceChains, int inheritanceDepth, int range) // number of classes
        {
            //Ishtiaque: this is probably already checked
            //Bala: This is a static method which can be reused for Interfaces
            //Even if the main stub is replaced with a GUI, this check will be needed.
            if (range < (noOfInheritanceChains * inheritanceDepth))
            {
                Console.WriteLine("getInheritanceList:: Invalid range");
                return(null);
            }
            List <List <int?> > inheritanceList = new List <List <int?> >();

            List <int?> usedList = new List <int?>();

            for (int i = 0; i < noOfInheritanceChains; i++)
            {
                Random random = new Random();

                //we don't want a 0 depth inheritance chain.
                int randomizedInheritanceDepth = random.Next(inheritanceDepth) + 1;

                // considering MinInheritanceDepth;  Min. InheritanceDepth should be less than equal to Max.,=> this is checked in GUI
                if (randomizedInheritanceDepth < minInheritanceDepth)
                {
                    randomizedInheritanceDepth = minInheritanceDepth;
                }



                inheritanceList.Add(ProgGenUtil.getRandomList(randomizedInheritanceDepth, range, usedList));
            }
            return(inheritanceList);
        }
Exemple #2
0
        public static string getClassToConstruct(string classname, List <ClassGenerator> classList)
        {
            ClassGenerator lhsClass = getClassByName(classList, classname);

            if (lhsClass == null)
            {
                return(classname);
            }

            if (ProgGenUtil.coinFlip())
            {
                //return the same class
                return(classname);
            }

            //else pick one of its subclasses to return
            HashSet <ClassGenerator> directKnownSubClasses = lhsClass.SubClasses;

            if (directKnownSubClasses.Count == 0)
            {
                //no subclasses
                return(classname);
            }

            //Using linked hash set for predictable iteration order
            HashSet <ClassGenerator> knownSubClasses = new HashSet <ClassGenerator>(directKnownSubClasses);

            foreach (ClassGenerator generator in knownSubClasses)
            {
                knownSubClasses.Add(generator);
                HashSet <ClassGenerator> subclasses = generator.SubClasses;
                foreach (ClassGenerator subclass in subclasses)
                {
                    knownSubClasses.Add(subclass);
                }
            }

            object[]       subClassArray = knownSubClasses.ToArray();
            ClassGenerator chosenOne     = (ClassGenerator)subClassArray[(new Random()).Next(subClassArray.Length)];

            return(chosenOne.FileName);
        }