lundi 24 février 2020

TDD approach to randomize List Items using C#? [closed]

I have a below list of 10 items and each item is categorized as Production or Stage. How to approach with TDD to achieve below functionality -

  1. 10 items are present in the list. 7 Production and 3 Stage.
  2. Randomize the order of the items such that
    • First 2 items are stage, selected randomly from 3 stage items.
    • Next 8 items are mix of stage and production items ordered from remaining 8 items.
class Program
    {
        static void Main(string[] args)
        {   
            List<Environment> myitems = new List<Environment>();
            myitems.Add(new Environment { ItemId = "op1", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "op2", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "op3", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "op4", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "op5", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "op6", ItemType = TypeEnum.Production });
            myitems.Add(new Environment { ItemId = "stage1", ItemType = TypeEnum.Stage });
            myitems.Add(new Environment { ItemId = "stage2", ItemType = TypeEnum.Stage });
            myitems.Add(new Environment { ItemId = "stage3", ItemType = TypeEnum.Stage });
            myitems.Add(new Environment { ItemId = "stage4", ItemType = TypeEnum.Stage });

            Testlet t = new Testlet("one", myitems);
            t.TestletId = "One";
            var x = t.Randomize();

        }


        public class Environment
        {
            public string ItemId;
            public TypeEnum ItemType;
        }
        public enum TypeEnum
        {
            Production = 0,
            Stage = 1
        }

        public class Testlet
        {
            public string TestletId;
            private List<Environment> Items;
            public Testlet(string testletId, List<Environment> items)
            {
                TestletId = testletId;
                Items = items;
            }
            public List<Environment> Randomize()
            {                   
               //logic to randomize the list  
               // Randomize the order of the items such that
               //First 2 items are stage, selected randomly from 3 stage items.
               //Next 8 items are mix of stage and production items ordered from remaining 8 items.              

                return Items;             
            }
        }


    }

Aucun commentaire:

Enregistrer un commentaire