Example #1
0
        public void adding_few_item_sould_work_properly()
        {
            QList <Person> list    = new QList <Person>();
            Person         person1 = PersonHelper.CreateTestPerson();
            Person         person2 = PersonHelper.CreateTestPerson();
            Person         person3 = PersonHelper.CreateTestPerson();
            Person         person4 = PersonHelper.CreateTestPerson();
            Person         person5 = PersonHelper.CreateTestPerson();

            list.Add(person1);
            list.Add(person2);
            list.Add(person3);
            list.Add(person4);
            list.Add(person5);

            Assert.AreEqual(5, list.Count);
            Assert.AreEqual(person1, list[0]);
            Assert.AreEqual(person1, list.FirstOrDefault());


            Assert.AreEqual(person2, list[1]);
            Assert.AreEqual(person3, list[2]);
            Assert.AreEqual(person4, list[3]);

            Assert.AreEqual(person5, list[4]);
            Assert.AreEqual(person5, list.LastOrDefault());
        }
Example #2
0
        public void inserting_sould_work_properly()
        {
            QList <Person> list = new QList <Person>();

            Int32 count = 100;

            for (var i = 0; i < count; i++)
            {
                list.Add(PersonHelper.CreateTestPerson());
            }

            Person firstPerson = PersonHelper.CreateTestPerson();

            list.Insert(0, firstPerson);

            Person lastPerson = PersonHelper.CreateTestPerson();

            list.Insert(list.Count, lastPerson);

            Person middlePerson = PersonHelper.CreateTestPerson();

            list.Insert(50, middlePerson);

            Assert.IsTrue(list.IndexOf(firstPerson) >= 0);
            Assert.IsTrue(list.IndexOf(lastPerson) >= 0);
            Assert.IsTrue(list.IndexOf(middlePerson) >= 0);
            Assert.AreEqual(count + 3, list.Items.Count());
        }
Example #3
0
        public void adding_one_item_sould_work_properly()
        {
            QList <Person> list      = new QList <Person>();
            Person         newPerson = PersonHelper.CreateTestPerson();

            list.Add(newPerson);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(newPerson, list[0]);
            Assert.AreEqual(newPerson, list.FirstOrDefault());
        }
Example #4
0
        QList <string> GetTop(string table, int ct)
        {
            QList <string> list = new QList <string>(QListSort.Descending);

            foreach (DbTable t in tables.Values)
            {
                list.Add(t.objectName, t.affinities.Get(table));
            }
            LogTop(table, list, ct);
            return(list);
        }
Example #5
0
        public void AddAllColumnsInQuery()
        {
            QList <Column> list = new QList <Column>(QListSort.Descending);

            foreach (Column c in Query.rootQuery.allColumns.tokens)
            {
                list.Add(c, c.significance);
            }
            foreach (Column c in list.Each())
            {
                AddColumn(c);
            }
        }
Example #6
0
        public string GetTableNameForTableAlias(string alias)
        {
            QList <Column> list = new QList <Column>(QListSort.Descending);

            foreach (Column c in tokens)
            {
                if (alias == c.columnAlias)
                {
                    list.Add(c, c.significance);
                }
            }

            return(list.Count > 0 ? list[0].tableName : null);
        }
Example #7
0
 public void addQueueVariable(int queue, double tcurr)
 {
     QList.Add(queue);
     QInterval.Add(tcurr - lastQMove);
     lastQMove = tcurr;
 }
Example #8
0
        static void Main(string[] args)
        {
            var    count  = 10000;
            object tmpObj = null;

            var items_to_add = new List <Person>();

            for (var i = 0; i < count; i++)
            {
                items_to_add.Add(PersonHelper.CreateTestPerson());
            }

            var list1 = new List <Person>(count);
            var list2 = new QList <Person>();

            Stopwatch st_create_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                list1.Add(item);
            }
            st_create_1.Stop();


            Stopwatch st_create_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                list2.Add(item);
            }
            st_create_2.Stop();


            Stopwatch st_read_1 = Stopwatch.StartNew();

            for (var i = 0; i < count; i++)
            {
                tmpObj = list1[i];
            }
            st_read_1.Stop();


            Stopwatch st_read_2 = Stopwatch.StartNew();

            for (var i = 0; i < count; i++)
            {
                tmpObj = list2[i];
            }
            st_read_2.Stop();


            Stopwatch st_enumerator_1 = Stopwatch.StartNew();

            foreach (var item in list1)
            {
                tmpObj = item;
            }
            st_enumerator_1.Stop();


            Stopwatch st_enumerator_2 = Stopwatch.StartNew();

            foreach (var item in list2)
            {
                tmpObj = item;
            }
            st_enumerator_2.Stop();


            Stopwatch st_indexof_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list1.IndexOf(item);
            }
            st_indexof_1.Stop();


            Stopwatch st_indexof_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list2.IndexOf(item);
            }
            st_indexof_2.Stop();



            Stopwatch st_Contains_1 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list1.Contains(item);
            }
            st_Contains_1.Stop();


            Stopwatch st_Contains_2 = Stopwatch.StartNew();

            foreach (var item in items_to_add)
            {
                tmpObj = list2.Contains(item);
            }
            st_Contains_2.Stop();



            var rand            = new Random(DateTime.Now.Millisecond);
            var items_to_remove = items_to_add.OrderBy(i => rand.Next(0, count)).ToList();

            Stopwatch st_remove_1 = Stopwatch.StartNew();

            foreach (var item in items_to_remove)
            {
                list1.Remove(item);
            }
            st_remove_1.Stop();


            Stopwatch st_remove_2 = Stopwatch.StartNew();

            foreach (var item in items_to_remove)
            {
                list2.Remove(item);
            }
            st_remove_2.Stop();

            list2.Clear();
            foreach (var item in items_to_add)
            {
                list2.Add(item);
            }

            list1.Clear();
            foreach (var item in items_to_add)
            {
                list1.Add(item);
            }


            Stopwatch st_remove2_1 = Stopwatch.StartNew();

            for (var i = count - 1; i >= 0; i--)
            {
                list1.RemoveAt(i);
            }
            st_remove2_1.Stop();


            Stopwatch st_remove2_2 = Stopwatch.StartNew();

            for (var i = count - 1; i >= 0; i--)
            {
                list2.RemoveAt(i);
            }
            st_remove2_2.Stop();



            var index = 0;

            foreach (var item2 in list2)
            {
                var item1 = list1[index];

                if (item1 != item2 || list1.Count != list2.Count)
                {
                    throw new NotImplementedException();
                }

                index++;
            }

            var c = 4;

            Console.WriteLine($"         |  Insert  |  Delete  |    Read  |  IndexOf  |  RemoveAt  |  Contains   |  Enumerator ");
            Console.WriteLine($" List<>  |  {format(st_create_1.ElapsedMilliseconds, c)}ms  |  {format(st_remove_1.ElapsedMilliseconds, c)}ms  |  {format(st_read_1.ElapsedMilliseconds, c)}ms  |   {format(st_indexof_1.ElapsedMilliseconds, c)}ms  |    {format(st_remove2_1.ElapsedMilliseconds, c)}ms  |  {format(st_Contains_1.ElapsedMilliseconds, c)}ms  |  {format(st_enumerator_1.ElapsedMilliseconds, c)}ms");
            Console.WriteLine($"QList<>  |  {format(st_create_2.ElapsedMilliseconds, c)}ms  |  {format(st_remove_2.ElapsedMilliseconds, c)}ms  |  {format(st_read_2.ElapsedMilliseconds, c)}ms  |   {format(st_indexof_2.ElapsedMilliseconds, c)}ms  |    {format(st_remove2_2.ElapsedMilliseconds, c)}ms  |  {format(st_Contains_2.ElapsedMilliseconds, c)}ms  |  {format(st_enumerator_2.ElapsedMilliseconds, c)}ms");
            Console.ReadKey();
        }
Example #9
0
 public void AddClient(Client visitor)
 {
     clients.Add(visitor);
     visitor.received     += new Client.ClientReceivedHandler(client_received);
     visitor.disconnected += new Client.ClientDisconnectedHandler(visitor_disconnected);
 }
Example #10
0
        public int FindInferredRelationships()
        {
            DbColumn primaryKeyColumn = GetSinglePrimaryKeyColumn();

            if (primaryKeyColumn == null)
            {
                return(0);
            }

            QList <DbColumn> references = new QList <DbColumn>(QListSort.Descending);

            foreach (DbColumn c in DbColumn.allNames.Each(name.ToLower()))
            {
                references.Add(c, 10);
            }
            foreach (DbColumn c in DbColumn.allNameStems.Each(name.Stem().ToLower()))
            {
                references.Add(c, 7);
            }
            foreach (DbColumn c in DbColumn.allWords.Each(name.ToLower()))
            {
                if (c.likeIdentifier)
                {
                    references.Add(c, 4 - c.objectNameWords.Count);
                }
            }
            foreach (DbColumn c in DbColumn.allWordStems.Each(name.Stem().ToLower()))
            {
                if (c.likeIdentifier)
                {
                    references.Add(c, 3 - c.objectNameWords.Count);
                }
            }

            /*
             * if (!primaryKeyColumn.objectName.In("id,code,name,label"))
             * {
             *  if (primaryKeyColumn.dataType == typeof(int) || primaryKeyColumn.dataType == typeof(string))
             *  {
             *      foreach (DbColumn c in DbColumn.allNames.Each(primaryKeyColumn.objectName.ToLower()))
             *          references.Add(c, 5);
             *  }
             * }
             */


            // todo: should these fields have zero empty values?

            int ct = 0;

            List <string> tablesAdded = new List <string>();

            foreach (DbColumn c in references.Each())
            {
                if (c != primaryKeyColumn && !tablesAdded.Contains(c.objectName))
                {
                    if (c.dataType == primaryKeyColumn.dataType && c.columnLength == primaryKeyColumn.columnLength)
                    {
                        if (c.table.GetForeignKey(objectName, primaryKeyColumn.objectName) == null)
                        {
                            DbTableConstraint constraint = c.table.GetOrAddConstraint("inferred" + objectName, "inferred");
                            constraint.AddInferredRelationship(c.objectName, this, primaryKeyColumn);
                            tablesAdded.Add(c.table.name);
                            ct++;
                        }
                    }
                }
            }

            return(ct);
        }