public void TestSubsets()
        {
            SetList<int> lista = new SetList<int>(new int[] { 5, 10, 20 });
            SetList<int> listb = new SetList<int>(new int[] { 2, 4, 6, 8, 10 });

            SetList<int>subt = lista.SubtractSet(listb);
            Assert.IsFalse(subt.IsEqualTo(lista));
            Assert.IsTrue(subt.Contains(5));
            Assert.IsFalse(subt.Contains(10));
            Assert.IsTrue(subt.IsEqualTo(new SetList<int>(new int[] { 5, 20 })));

            Assert.IsTrue(subt.IsSubsetOf(lista));
            Assert.IsFalse(subt.IsSupersetOf(lista));

            Assert.IsTrue(lista.IsSupersetOf(subt));
            Assert.IsFalse(lista.IsSubsetOf(subt));
            
            SetList<int> copy = lista.Clone();
            copy.RemoveAll(listb);
            Assert.IsFalse(copy.IsEqualTo(lista));
            Assert.IsTrue(copy.IsEqualTo(subt));

            copy.Add(11);
            Assert.IsFalse(copy.IsEqualTo(lista));

            SetList<int> xor = lista.ExclusiveOrWith(listb);
            Assert.IsTrue(xor.IsEqualTo(new SetList<int>(new int[] { 2, 4, 6, 8, 5, 20 })));

            SetList<int> comp = lista.ComplementOf(listb);
            Assert.IsTrue(comp.IsEqualTo(new SetList<int>(new int[] { 2, 4, 6, 8 })));
        }
示例#2
0
        public void TestBasics()
        {
            SetList <int> list = new SetList <int>();

            Assert.IsFalse(list.IsReadOnly);

            for (int i = 512; i >= 0; i--)
            {
                list.Add(i);
            }

            int offset = 0;

            foreach (int item in list)
            {
                Assert.AreEqual(offset++, item);
            }

            Assert.AreEqual(513, offset);
            Assert.AreEqual(513, list.Count);

            list.Clear();
            list.AddRange(new int[] { 5, 10, 20 });
            list.AddRange(new int[] { });

            Assert.AreEqual(3, list.Count);

            Assert.IsTrue(list.Contains(20));
            Assert.IsTrue(list.Remove(20));

            Assert.IsFalse(list.Contains(20));
            Assert.IsFalse(list.Remove(20));

            Assert.AreEqual(2, list.Count);

            int pos;

            list.Add(10, out pos);
            Assert.AreEqual(1, pos);
            Assert.AreEqual(2, list.Count);

            int[] items = new int[2];
            list.CopyTo(items, 0);
            Assert.AreEqual(5, items[0]);
            Assert.AreEqual(10, items[1]);

            items = list.ToArray();
            Assert.AreEqual(5, items[0]);
            Assert.AreEqual(10, items[1]);

            List <int> tmp = new List <int>();

            foreach (int i in list)
            {
                tmp.Add(i);
            }
            Assert.AreEqual(2, tmp.Count);
            Assert.AreEqual(5, tmp[0]);
            Assert.AreEqual(10, tmp[1]);
        }
示例#3
0
        /// <summary>
        /// Processes a single value .
        /// If the data value is text, the boundaries are
        /// updated and the number of items is increased by one (if not contained already). The function returns true
        /// in this case. On the other hand, if the value is outside the range, the function has to
        /// return false.
        /// </summary>
        /// <param name="item">The data item.</param>
        /// <returns>True if data is in the tracked range, false if the data is not in the tracked range.</returns>
        public bool Add(Altaxo.Data.AltaxoVariant item)
        {
            if (!(item.IsType(Altaxo.Data.AltaxoVariant.Content.VString)))
            {
                return(false);
            }

            string s = item.ToString();

            if (string.IsNullOrEmpty(s))
            {
                return(false); // we consider empty string as invalid data here
            }
            if (IsSuspended)   // when suspended: performance tweak, see overrides OnSuspended and OnResume for details (if suspended, we have saved the state of the instance for comparison when we resume).
            {
                if (!_itemList.Contains(s))
                {
                    _itemList.Add(s);
                }
            }
            else // not suspended: normal behaviour with change notification
            {
                if (!_itemList.Contains(s))
                {
                    _itemList.Add(s);
                    EhSelfChanged(new BoundariesChangedEventArgs(BoundariesChangedData.NumberOfItemsChanged | BoundariesChangedData.UpperBoundChanged));
                }
            }
            return(true);
        }
示例#4
0
        public void TestIList()
        {
            IList list = new SetList <string>(StringComparer.Ordinal);

            Assert.AreEqual(0, list.Count);
            list.Add("a");
            Assert.AreEqual(1, list.Count);
            list.Add("B");
            Assert.AreEqual(2, list.Count);

            Assert.AreEqual("B", list[0]);
            Assert.AreEqual("a", list[1]);

            Assert.IsTrue(list.Contains("a"));
            Assert.IsFalse(list.Contains("A"));
            Assert.IsFalse(list.Contains("b"));
            Assert.IsTrue(list.Contains("B"));

            Assert.AreEqual(0, list.IndexOf("B"));
            Assert.AreEqual(1, list.IndexOf("a"));

            list = new SetList <string>((IEnumerable <string>)list, StringComparer.OrdinalIgnoreCase);
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("a", list[0]);
            Assert.AreEqual("B", list[1]);

            Assert.IsTrue(list.Contains("a"));
            Assert.IsTrue(list.Contains("A"));
            Assert.IsTrue(list.Contains("b"));
            Assert.IsTrue(list.Contains("B"));

            Assert.IsFalse(list.Contains(5));
            Assert.IsTrue(list.IndexOf(5) < 0);

            Assert.IsFalse(list.IsFixedSize);
            list.Remove("b");
            Assert.IsFalse(list.Contains("b"));
            Assert.IsFalse(list.Contains("B"));

            list = (IList)((ICloneable)list).Clone();
            Assert.AreEqual(typeof(SetList <string>), list.GetType());
            Assert.IsTrue(list.Contains("a"));
            Assert.IsFalse(list.Contains("b"));
            Assert.AreEqual(0, list.IndexOf("a"));
        }
        /// <summary> </summary>
        public override void StartTag(XmlTagInfo tag)
        {
            if (_nonClosedTags.Contains(tag.FullName))
            {
                tag.SelfClosed = true;
            }

            XmlLightElement parent = _parserStack.Peek();
            List <string>   allowedParents;

            if (_nonNestingTags.Contains(tag.FullName) && StringComparer.OrdinalIgnoreCase.Equals(parent.TagName, tag.FullName))
            {
                _parserStack.Pop();
            }
            else if (_htmlHeirarchy.TryGetValue(tag.FullName, out allowedParents))
            {
                int depth = 0;
                XmlLightElement[] stack = _parserStack.ToArray();
                while (depth < stack.Length && allowedParents.BinarySearch(stack[depth].TagName, StringComparer.OrdinalIgnoreCase) < 0)
                {
                    depth++;
                }

                if (depth < stack.Length)
                {
                    for (; depth > 0; depth--)
                    {
                        _parserStack.Pop();
                    }
                }
                else
                {
                    StartTag(new XmlTagInfo(allowedParents[0], false));
                }
            }

            base.StartTag(tag);
        }
        public void TestIntersectUnion()
        {
            SetList<int> lista = new SetList<int>(new int[] { 5, 10, 20 });
            SetList<int> listb = new SetList<int>(new int[] { 2, 4, 6, 8, 10 });

            SetList<int> union = lista.UnionWith(listb);
            Assert.AreEqual(7, union.Count);
            foreach (int i in union)
                Assert.IsTrue(lista.Contains(i) || listb.Contains(i));

            Assert.AreEqual(0, union.IndexOf(2));
            Assert.AreEqual(6, union.IndexOf(20));

            SetList<int> inter = lista.IntersectWith(listb);
            Assert.AreEqual(1, inter.Count);
            foreach (int i in inter)
                Assert.AreEqual(10, i);
        }