private static void IndexComparisonHelper <T>(params T[] data)
        {
            //Comparing to a list here just because it implements all the operations.
            //No particular reason this colleciton was chosen.
            var systemList = new List <T>(data);

            var testedList = new SingleList <T>();

            foreach (var value in systemList)
            {
                testedList.Add(value);
            }
            //Index Test
            foreach (var value in systemList)
            {
                var correctIndex = systemList.IndexOf(value);
                var testedIndex  = testedList.IndexOf(value);
                Assert.Equal(correctIndex, testedIndex);
                Assert.True(testedList.Contains(value));
            }
            //Removal Tests
            for (int i = 0; i < data.Length; i++)
            {
                //Let's check it behaves in a manner identical to deference list
                Assert.Equal(testedList.Remove(data[2]), systemList.Remove(data[2]));
                Assert.Equal(testedList.Count, systemList.Count);
            }
        }
        public static void DisplayResult()
        {
            SingleList <int> linkedList = new SingleList <int>();

            CreateList(ref linkedList);
            DisplayList(linkedList);
        }
        public void PerfTestRandomRead()
        {
            var systemList = new System.Collections.Generic.List <int>();

            var testedList = new SingleList <int>();

            for (int i = 0; i < 50000; i++)
            {
                testedList.Add(BenchmarkData[i]);
                systemList.Add(BenchmarkData[i]);
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < systemList.Count; i++)
            {
                var index = BenchmarkData[i % 50];
                var it    = systemList[index];
            }
            stopwatch.Stop();
            var systemListTime = stopwatch.ElapsedTicks;

            stopwatch.Restart();
            for (int i = 0; i < testedList.Count; i++)
            {
                var index = BenchmarkData[i % 50];
                var it    = testedList[index];
            }
            stopwatch.Stop();
            output.WriteLine($"LinkedList {stopwatch.ElapsedTicks} t | System.List {systemListTime} t");
        }
Example #4
0
 public void TestSetup()
 {
     this.list = new SingleList <int>();
     for (int i = maxIndex; i >= 0; i--)
     {
         this.list.InsertNode(i);
     }
 }
Example #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_task);

            EditText content = FindViewById <EditText>(Resource.Id.task_content);
            Button   submit  = FindViewById <Button>(Resource.Id.task_submit);
            Button   cancel  = FindViewById <Button>(Resource.Id.task_cancel);
            int      usrId   = Intent.GetIntExtra("IdUser", 0);
            bool     edit    = Intent.GetBooleanExtra("Edit", false);

            if (edit)
            {
                int lstId = Intent.GetIntExtra("IdList", 0);
                int tskId = Intent.GetIntExtra("IdTask", 0);
                lst          = localStorage.GetList(lstId);
                tsk          = localStorage.GetTask(tskId);
                content.Text = tsk.Content;
            }
            else
            {
                tsk = new SingleTask {
                    Content = "", IdList = 0
                };
            }

            usr = localStorage.GetUser(usrId);

            submit.Click += async delegate
            {
                if (edit)
                {
                    tsk.Content = content.Text;
                    localStorage.UpdateTask(tsk);
                }
                else
                {
                    // A l'avenir, chercher la liste concernée, et ne pas rajouter à la première liste de l'user
                    List <SingleList> myLists = localStorage.GetMyList(usr);
                    await localStorage.AddTask(
                        new SingleTask { Content = content.Text, IdList = myLists.First().Id }
                        );
                }

                var activity = new Intent(this, typeof(ProjectActivity));
                activity.PutExtra("IdUser", usr.Id);
                StartActivity(activity);
                Finish();
            };

            cancel.Click += delegate
            {
                var activity = new Intent(this, typeof(ProjectActivity));
                activity.PutExtra("IdUser", usr.Id);
                StartActivity(activity);
                Finish();
            };
        }
        public void LoadListList()
        {
            myLists = localStorage.GetMyList(usr);
            SingleList myList = myLists.FirstOrDefault();

            TextView lstListTitle = FindViewById <TextView>(Resource.Id.proj_title_list);

            lstListTitle.Text = myList.Title;
        }
Example #7
0
 static public void GetDefaultTask(SingleList lst)
 {
     db.Insert(new SingleTask {
         Content = "First task", IdList = lst.Id
     }, typeof(SingleTask));
     db.Insert(new SingleTask {
         Content = "Second task", IdList = lst.Id
     }, typeof(SingleTask));
     db.Insert(new SingleTask {
         Content = "Third task", IdList = lst.Id
     }, typeof(SingleTask));
 }
        public void PerfTestSequentialRead()
        {
            var systemList       = new System.Collections.Generic.List <int>(BenchmarkData);
            var systemLinkedList = new System.Collections.Generic.LinkedList <int>(BenchmarkData);

            var testedLinkedList = new SingleList <int>();

            foreach (var number in BenchmarkData)
            {
                testedLinkedList.Add(number);
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < BenchmarkData.Length; i++)
            {
                var it = systemList[i];
            }
            stopwatch.Stop();
            var systemListDuration = stopwatch.ElapsedMilliseconds;

            stopwatch.Restart();
            foreach (var item in systemLinkedList)
            {
                var it = item;
            }
            stopwatch.Stop();
            var systemLinkedListDuration = stopwatch.ElapsedMilliseconds;

            stopwatch.Restart();
            for (int i = 0; i < BenchmarkData.Length; i++)
            {
                var it = testedLinkedList[i];
            }
            stopwatch.Stop();
            var linkedListIterated = stopwatch.ElapsedMilliseconds;

            stopwatch.Restart();
            //Tested this for comparison, it's about three times faster
            foreach (var item in testedLinkedList)
            {
                var it = item;
            }
            stopwatch.Stop();
            var linkedListEnumerated = stopwatch.ElapsedMilliseconds;

            output.WriteLine($"'Enumerator' {linkedListEnumerated} | Indexer | {linkedListIterated}| " +
                             $"System.List {systemListDuration}| System.LinkedList {systemLinkedListDuration}");
        }
        private static void CreateList(ref SingleList <int> linkedList)
        {
            linkedList.Head = new SingleNode <int>(10);
            SingleNode <int> node1 = new SingleNode <int>(1);
            SingleNode <int> node2 = new SingleNode <int>(2);
            SingleNode <int> node3 = new SingleNode <int>(3);
            SingleNode <int> node4 = new SingleNode <int>(4);
            SingleNode <int> node5 = new SingleNode <int>(5);

            linkedList.Head.Next = node1;
            node1.Next           = node2;
            node2.Next           = node3;
            node3.Next           = node4;
            node4.Next           = node5;
        }
Example #10
0
        static void Main(string[] args)
        {
            Console.Write("Ingrese la cantidad de elementos de la lista:");
            int cantidad = Convert.ToInt32(Console.ReadLine());

            Console.Write("Agregar un Nodo al final: 1=si ");
            int nodofinal = Convert.ToInt32(Console.ReadLine());

            Console.Write("Agregar un Nodo al inicial: 1=si ");
            int nodoinicial = Convert.ToInt32(Console.ReadLine());


            SingleList <int> listaDeEnteros = new SingleList <int>();

            Random random = new Random();


            for (int i = 0; i < cantidad; i++)
            {
                int nuevoNumero = random.Next(0, 100);
                listaDeEnteros.AddNode(nuevoNumero);


                if (i == cantidad - 1)
                {
                    Console.Write(" ");
                    if (nodofinal == 1)
                    {
                        listaDeEnteros.AddNodefinal(56);
                    }

                    if (nodoinicial == 1)
                    {
                        listaDeEnteros.AddNodeinicial(23);
                    }
                }
            }


            listaDeEnteros.ImprimirLista();



            Console.Read();
        }
Example #11
0
        public static async void AddList(SingleList lst)
        {
            if (CheckInternet())
            {
                using (HttpClient webAPI = new HttpClient())
                {
                    string result;
                    result = await webAPI.GetStringAsync("http://dtaction.azurewebsites.net/api/getlastlist");

                    SingleList obj = JsonConvert.DeserializeObject <SingleList>(result);

                    int newId = obj.Id + 1;
                    lst.Id = newId;

                    if (GetAllList() == null || GetAllList().Count == 0)
                    {
                        lst.Position = 0;
                    }
                    else
                    {
                        lst.Position = GetAllList().LastOrDefault().Position + 1;
                    }

                    db.Insert(lst, typeof(SingleList));

                    webAPI.MaxResponseContentBufferSize = 256000;
                    string json    = Newtonsoft.Json.JsonConvert.SerializeObject(lst);
                    var    content = new StringContent(json, Encoding.UTF8, "application/json");

                    HttpResponseMessage response;
                    try
                    {
                        response = await webAPI.PostAsync("http://dtaction.azurewebsites.net/api/list", content);
                    }
                    catch (Exception err)
                    {
                        string sHold = err.Message;
                        throw;
                    }
                }
            }
        }
Example #12
0
        static void List(string[] args)
        {
            SingleList<int> SList = new SingleList<int>();

            SList.Print();

            SList.Push(45);
            SList.Print();
            SList.Reverse();
            SList.Print();
            SList.Push(54);
            SList.Print();
            SList.Reverse();
            SList.Print();
            int[] intArray = { 234, 632, 123, 654, 1, 354, 0 };
            SList.Push(intArray);
            SList.Print();
            SList.Reverse();
            SList.Print();
        }
Example #13
0
 public static async void RemoveList(SingleList lst)
 {
     db.Delete <SingleList>(lst.Id);
     if (CheckInternet())
     {
         using (HttpClient webAPI = new HttpClient())
         {
             webAPI.MaxResponseContentBufferSize = 256000;
             HttpResponseMessage response;
             try
             {
                 response = await webAPI.DeleteAsync("http://dtaction.azurewebsites.net/api/list/" + lst.Id);
             }
             catch (Exception err)
             {
                 string sHold = err.Message;
                 throw;
             }
         }
     }
 }
        public void PerfTestInsert()
        {
            var       systemList = new System.Collections.Generic.LinkedList <int>();
            Stopwatch stopwatch  = new Stopwatch();

            stopwatch.Start();
            foreach (var number in BenchmarkData)
            {
                systemList.AddLast(number);
            }
            stopwatch.Stop();
            var SystemListTime = stopwatch.ElapsedMilliseconds;
            var testedList     = new SingleList <int>();

            stopwatch.Restart();
            foreach (var number in BenchmarkData)
            {
                testedList.Add(number);
            }
            stopwatch.Stop();
            output.WriteLine($"LinkedList {stopwatch.ElapsedMilliseconds}ms | System.LinkedList {SystemListTime}");
        }
Example #15
0
        public void SingleListTest()
        {
            SingleList <TestEntity> list = new SingleList <TestEntity>();

            Assert.AreEqual(0, list.Count);

            var link1 = new TestEntity(1);

            list.AddFirst(link1);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(link1, list.First);

            var link2 = new TestEntity(2);

            SingleList <TestEntity> .AddAfter(link1, link2);

            Assert.AreEqual(2, list.Count);

            var link3 = new TestEntity(2);

            SingleList <TestEntity> .AddAfter(link2, link3);

            Assert.AreEqual(3, list.Count);

            list.RemoveFirst();

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(link2, list.First);

            SingleList <TestEntity> .RemoveAfter(link2);

            Assert.AreEqual(1, list.Count);

            list.RemoveFirst();

            Assert.AreEqual(0, list.Count);
        }
Example #16
0
        public static async void UpdateList(SingleList lst)
        {
            db.Update(lst);
            if (CheckInternet())
            {
                using (HttpClient webAPI = new HttpClient())
                {
                    webAPI.MaxResponseContentBufferSize = 256000;
                    string json    = Newtonsoft.Json.JsonConvert.SerializeObject(lst);
                    var    content = new StringContent(json, Encoding.UTF8, "application/json");

                    HttpResponseMessage response;
                    try
                    {
                        response = await webAPI.PutAsync("http://dtaction.azurewebsites.net/api/list/" + lst.Id, content);
                    }
                    catch (Exception err)
                    {
                        string sHold = err.Message;
                        throw;
                    }
                }
            }
        }
Example #17
0
        public void SingleList_Serialized()
        {
            int lc = 0;
              int cc = 0;
              Csla.Core.ChildChangedEventArgs cca = null;

              var root = new SingleList();
              root.Add(new SingleRoot(true));
              root = root.Clone();

            #if !SILVERLIGHT
              System.ComponentModel.PropertyDescriptor lcp = null;
              root.ListChanged += (o, e) =>
              {
            lc++;
            lcp = e.PropertyDescriptor;
              };
            #else
              root.CollectionChanged += (o, e) =>
              {
            lc++;
              };
            #endif
              root.ChildChanged += (o, e) =>
              {
            cc++;
            cca = e;
              };
              root[0].Name = "abc";
            #if !SILVERLIGHT
              Assert.AreEqual(1, lc, "ListChanged should have fired");
              Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
              Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
            #endif
              Assert.AreEqual(1, cc, "ChildChanged should have fired");
              Assert.IsTrue(ReferenceEquals(root[0], cca.ChildObject), "Ref should be equal");
        }
Example #18
0
        static void Main(string[] args)
        {
            SingleList <int> listaDeEnteros = new SingleList <int>();

            Console.Write("Ingrese la cantidad de elementos de la lista:");
            int    cantidad = Convert.ToInt32(Console.ReadLine());
            Random random   = new Random();

            for (int i = 0; i < cantidad; i++)
            {
                int nuevoNumero = random.Next(0, 100);
                listaDeEnteros.AddNode(nuevoNumero);
            }

            listaDeEnteros.ImprimirLista();

            Console.WriteLine("\n Escoja una opcion\n ");

            int option = 0;

            Console.WriteLine("1. Imprimir Lista");
            Console.WriteLine("2. Agregar Valor al Inicio");
            Console.WriteLine("3. Agregar Valor al Final ");
            Console.WriteLine("4. Ordenamiento Burbuja");
            Console.WriteLine("5. Buscar Elemento");
            Console.WriteLine("6. Salir");
            Console.WriteLine("99. Creditos a Davies Hinestroza");

            option = Convert.ToInt32(Console.ReadLine());
            switch (option)
            {
            case 1:

                listaDeEnteros.ImprimirLista();

                break;

            case 2:
                Console.WriteLine("Ingrese el nuevo valor");
                int valor = Convert.ToInt32(Console.ReadLine());
                listaDeEnteros.AddNodeInicio(valor);
                listaDeEnteros.ImprimirLista();

                break;

            case 3:

                Console.WriteLine("Ingrese el nuevo valor");
                int valor2 = Convert.ToInt32(Console.ReadLine());
                listaDeEnteros.AddNodeFinal(listaDeEnteros, valor2);
                listaDeEnteros.ImprimirLista();

                break;

            case 4:
                BurbujaList burbujaList = new BurbujaList();
                burbujaList.Cargar(listaDeEnteros);

                break;

            case 5:
                Console.WriteLine("Ingrese el valor a buscar");
                int valor3 = Convert.ToInt32(Console.ReadLine());
                listaDeEnteros.SearchNode(listaDeEnteros, valor3);

                break;
            }
            Console.Read();
        }
 private static void DisplayList(SingleList <int> linkedList)
 {
     linkedList.Display();
 }