public void Test1()
        {
            IndexedSet <int>  set1 = new IndexedSet <int>();
            IEnumerable <int> set2 = new List <int>();

            Assert.False(set1.IsProperSubsetOf(set2));
        }
        public void Test1()
        {
            Random           rand    = new Random(0);
            int              size    = 20000;
            IndexedSet <int> set     = new IndexedSet <int>();
            HashSet <int>    hashSet = new HashSet <int>();
            List <int>       list    = new List <int>();

            while (size-- > 0)
            {
                Debug.WriteLine(size);
                set.Clear();
                hashSet.Clear();
                list.Clear();
                int n = rand.Next(100);
                for (int i = 0; i < n; i++)
                {
                    int item = rand.Next(100);
                    hashSet.Add(item);
                    set.Add(item);
                }
                n = rand.Next(100);
                for (int i = 0; i < n; i++)
                {
                    list.Add(rand.Next(100));
                }
                hashSet.SymmetricExceptWith(list);
                set.SymmetricExceptWith(list);
                Assert.Equal(set.Count, hashSet.Count);
            }
        }
예제 #3
0
        private static void Test2()
        {
            Random           rand    = new Random(0);
            int              size    = 20000;
            IndexedSet <int> set     = new IndexedSet <int>();
            HashSet <int>    hashSet = new HashSet <int>();
            List <int>       list    = new List <int>();

            while (true)
            {
                set.Clear();
                hashSet.Clear();
                int n = rand.Next(100);
                for (int i = 0; i < n; i++)
                {
                    int item = rand.Next(100);
                    hashSet.Add(item);
                    set.Add(item);
                }
                n = rand.Next(100);
                for (int i = 0; i < n; i++)
                {
                    list.Add(rand.Next(100));
                }
                try
                {
                    hashSet.SymmetricExceptWith(list);
                    set.SymmetricExceptWith(list);
                    //Assert.Equal(set.Count, hashSet.Count);
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #4
0
    static void Main(string[] args)
    {
        Console.WriteLine("Generating test set.");
        var rand = new Random();
        IndexedSet <Sha256_Long> set =
            new IndexedSet <Sha256_Long>(
                GenerateRandomHashes(rand, NTestItems),
                Sha256_Long.KeyBits);

        Console.WriteLine("Testing with random input.");
        int nFound           = 0;
        int nItems           = NTestItems;
        int waypointDistance = 100000;
        int waypoint         = 0;

        for (int i = 0; i < nItems; i++)
        {
            if (++waypoint == waypointDistance)
            {
                Console.WriteLine("Test lookups complete: " + (i + 1));
                waypoint = 0;
            }
            var item = RandomHash(rand);
            nFound += set.Contains(item) ? 1 : 0;
        }
        Console.WriteLine("Testing complete.");
        Console.WriteLine(String.Format("Found: {0} / {0}", nFound, nItems));
        Console.ReadKey();
    }
예제 #5
0
        public void CopyToTest()
        {
            var set   = new IndexedSet <string>();
            var array = new string[2];

            Assert.IsEmpty(set);
            Assert.That(array, Is.All.Null);

            set.CopyTo(array, 0);

            Assert.IsEmpty(set);
            Assert.That(array, Is.All.Null);

            set.Add("A");
            set.Add("B");
            set.CopyTo(array, 0);

            Assert.That(set.Count, Is.EqualTo(2));
            Assert.That(set, Contains.Item("A").And.Contains("B"));
            Assert.That(array.Length, Is.EqualTo(2));
            Assert.That(array, Is.All.Not.Null);
            Assert.That(array, Contains.Item("A").And.Contains("B"));
            Assert.That(array[0], Is.EqualTo("A"));
            Assert.That(array[1], Is.EqualTo("B"));
        }
예제 #6
0
        public void Test1()
        {
            IndexedSet <int>  set1 = new IndexedSet <int>();
            IEnumerable <int> set2 = new List <int>();

            Assert.True(set1.IsSupersetOf(set2));
        }
예제 #7
0
        public void InsertTest()
        {
            var set = new IndexedSet <string>();

            set.Insert(0, "A");
            Assert.That(set[0], Is.EqualTo("A"));
            Assert.That(set.Count, Is.EqualTo(1));

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                set.Insert(5, "B");
            });

            Assert.That(set[0], Is.EqualTo("A"));
            Assert.That(set.Count, Is.EqualTo(1));

            set.Insert(1, "B");
            Assert.That(set.Count, Is.EqualTo(2));
            Assert.That(set[0], Is.EqualTo("A"));
            Assert.That(set[1], Is.EqualTo("B"));

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var _ = set[2];
            });
        }
예제 #8
0
        public void IsReadOnlyTest()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            var set = new IndexedSet <object>();

            Assert.False(((ICollection <object>)set).IsReadOnly);
        }
예제 #9
0
    static object Solve()
    {
        var n  = int.Parse(Console.ReadLine());
        var a  = Read();
        var qc = int.Parse(Console.ReadLine());
        var qs = Array.ConvertAll(new bool[qc], _ => int.Parse(Console.ReadLine()));

        var set = new IndexedSet <int>();

        foreach (var v in a)
        {
            set.Add(v);
        }
        set.Add(-1 << 30);
        set.Add(int.MaxValue);

        return(string.Join("\n", qs.Select(GetMin)));

        int GetMin(int bv)
        {
            var an2 = set.Root.SearchFirstNode(x => x >= bv);
            var an1 = an2.SearchPreviousNode();

            return(Math.Min(an2.Item - bv, bv - an1.Item));
        }
    }
예제 #10
0
        /// <summary>
        /// Associates a Graphic with a Canvas and stores this association in the registry.
        /// </summary>
        /// <param name="c">The canvas being associated with the Graphic.</param>
        /// <param name="graphic">The Graphic being associated with the Canvas.</param>
        public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic)
        {
            if (c == null || graphic == null)
            {
                return;
            }

            IndexedSet <Graphic> graphics;

            instance.m_Graphics.TryGetValue(c, out graphics);

            if (graphics != null)
            {
                graphics.AddUnique(graphic);

                RegisterRaycastGraphicForCanvas(c, graphic);

                return;
            }

            // Dont need to AddUnique as we know its the only item in the list
            graphics = new IndexedSet <Graphic>();
            graphics.Add(graphic);
            instance.m_Graphics.Add(c, graphics);

            RegisterRaycastGraphicForCanvas(c, graphic);
        }
예제 #11
0
        public void NullInitialValues_CtorTest()
        {
            IndexedSet <string> sut = null;
            Action ctor             = () => { sut = new IndexedSet <string>(null); };

            Assert.Throws <ArgumentNullException>(ctor);
            Assert.Null(sut);
        }
예제 #12
0
        public void Test1()
        {
            IndexedSet <int>  set1 = new IndexedSet <int>();
            IEnumerable <int> set2 = new List <int>();

            set1.ExceptWith(set2);
            Assert.Empty(set1);
        }
예제 #13
0
        public void Test9()
        {
            IndexedSet <int> set1 = new IndexedSet <int>();
            IndexedSet <int> set2 = new IndexedSet <int>();

            set1.ExceptWith(set2);
            Assert.Empty(set1);
        }
예제 #14
0
        public void Test1()
        {
            IndexedSet <int> set1 = new IndexedSet <int>();
            List <int>       set2 = new List <int>();

            set1.IntersectWith(set2);
            Assert.Empty(set1);
        }
예제 #15
0
        public void EmptyInitialValues_CtorTest()
        {
            IndexedSet <string> sut = null;
            Action ctor             = () => { sut = new IndexedSet <string>(new string[] { }); };

            ctor();
            Assert.NotNull(sut);
            Assert.Empty(sut);
        }
예제 #16
0
        public void Default_CtorTest()
        {
            var sut = new IndexedSet <object>();

            Assert.NotNull(sut);
            Assert.Empty(sut);
            Assert.False(sut.IsReadOnly);
            Assert.Null(sut[0]);
        }
예제 #17
0
        public void ContainsTest()
        {
            var set = new IndexedSet <string>();

            Assert.False(set.Contains("A"));
            Assert.True(set.Add("A"));
            Assert.True(set.Contains("A"));
            Assert.False(set.Contains("B"));
        }
예제 #18
0
        public void AddCollectionExplicitTest()
        {
            var set = new IndexedSet <string>();

            ((ICollection <string>)set).Add("A");
            ((ICollection <string>)set).Add("A");

            Assert.That(set.Count, Is.EqualTo(1));
        }
        /// <summary>
        /// Sets the class labels.
        /// </summary>
        /// <param name="instanceSource">The instance source.</param>
        /// <param name="labelSource">An optional label source.</param>
        public void SetClassLabels(TInstanceSource instanceSource, TLabelSource labelSource = default(TLabelSource))
        {
            Debug.Assert(instanceSource != null, "The instance source must not be null.");

            // Guarantee consistent order of class label indexes
            var orderedClassLabels = this.StandardMapping.GetClassLabelsSafe(instanceSource, labelSource).OrderBy(classLabel => classLabel);

            this.classLabelSet = new IndexedSet <TLabel>(orderedClassLabels);
        }
예제 #20
0
        public void DisposableTest()
        {
            IndexedSet <string> sut;

            using (sut = new IndexedSet <string>())
            {
                Assert.NotNull(sut);
            }
            Assert.True(sut.Disposed);
        }
예제 #21
0
        public void GetEnumeratorTest()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            var set = new IndexedSet <object>();

            using var enumerator = set.GetEnumerator();

            Assert.Null(enumerator.Current);
            Assert.False(enumerator.MoveNext());
        }
예제 #22
0
        public void Test3()
        {
            IndexedSet <int>  set1 = new IndexedSet <int>();
            IEnumerable <int> set2 = new List <int>()
            {
                0, 0
            };

            Assert.False(set1.IsSupersetOf(set2));
        }
예제 #23
0
        public void Test8()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                1, 2, 3
            };
            IEnumerable <int> set2 = set1;

            Assert.True(set1.SetEquals(set2));
        }
예제 #24
0
        public void Test11()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            List <int> set2 = null;

            Assert.Throws <ArgumentNullException>(() => set1.IntersectWith(set2));
        }
예제 #25
0
        public void Test17()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                1, 2, 3
            };
            IndexedSet <int> set2 = null;

            Assert.Throws <ArgumentNullException>(() => set1.ExceptWith(set2));
        }
예제 #26
0
        public void Test9()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                1, 2, 3
            };
            IEnumerable <int> set2 = null;

            Assert.Throws <ArgumentNullException>(() => set1.UnionWith(set2));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MulticlassNativeClassifierMapping{TInstanceSource,TInstance,TLabelSource,TLabel}"/>
        /// class from a reader of a binary stream.
        /// </summary>
        /// <param name="reader">The binary reader to read the mapping from.</param>
        /// <param name="standardMapping">The mapping for accessing data in standard format.</param>
        public MulticlassNativeClassifierMapping(BinaryReader reader, IClassifierMapping <TInstanceSource, TInstance, TLabelSource, TLabel, Vector> standardMapping)
            : base(reader, standardMapping)
        {
            int deserializedVersion = reader.ReadSerializationVersion(CustomSerializationVersion);

            if (deserializedVersion == CustomSerializationVersion)
            {
                this.classLabelSet = new IndexedSet <TLabel>(reader);
            }
        }
        public void Test11()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                1, 2, 3, 3, 3, 3, 3, 3
            };
            IEnumerable <int> set2 = null;

            Assert.Throws <ArgumentNullException>(() => set1.IsProperSubsetOf(set2));
        }
예제 #29
0
        private void Start()
        {
            list = new List <int>(count);
            set  = new HashSet <int>(new IntComparer());
            var comparer = new IntComparer();

            indexedSet = new IndexedSet <int>(count, comparer);
            multiSet   = new IndexedMultiSet <int>(count, comparer);
            data       = new int[count];
        }
예제 #30
0
        public void Test8()
        {
            IndexedSet <int> set1 = new IndexedSet <int>()
            {
                1, 2, 3
            };
            IEnumerable <int> set2 = set1;

            set1.UnionWith(set2);
            Assert.Equal(3, set1.Count);
        }
예제 #31
0
 /// <summary>
 /// 
 /// <para>
 /// Store a link between the given canvas and graphic in the registry.
 /// </para>
 /// 
 /// </summary>
 /// <param name="c">Canvas to register.</param><param name="graphic">Graphic to register.</param>
 public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic)
 {
   if ((Object) c == (Object) null)
     return;
   IndexedSet<Graphic> indexedSet;
   GraphicRegistry.instance.m_Graphics.TryGetValue(c, out indexedSet);
   if (indexedSet != null)
   {
     indexedSet.AddUnique(graphic);
   }
   else
   {
     indexedSet = new IndexedSet<Graphic>();
     indexedSet.Add(graphic);
     GraphicRegistry.instance.m_Graphics.Add(c, indexedSet);
   }
 }
예제 #32
0
 /// <summary>
 /// <para>Store a link between the given canvas and graphic in the registry.</para>
 /// </summary>
 /// <param name="c">Canvas to register.</param>
 /// <param name="graphic">Graphic to register.</param>
 public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic)
 {
     if (c != null)
     {
         IndexedSet<Graphic> set;
         instance.m_Graphics.TryGetValue(c, out set);
         if (set != null)
         {
             set.AddUnique(graphic);
         }
         else
         {
             set = new IndexedSet<Graphic> {
                 graphic
             };
             instance.m_Graphics.Add(c, set);
         }
     }
 }
예제 #33
0
        public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic)
        {
            if (c == null)
                return;

            IndexedSet<Graphic> graphics;
            instance.m_Graphics.TryGetValue(c, out graphics);

            if (graphics != null)
            {
                graphics.AddUnique(graphic);
                return;
            }

            // Dont need to AddUnique as we know its the only item in the list
            graphics = new IndexedSet<Graphic>();
            graphics.Add(graphic);
            instance.m_Graphics.Add(c, graphics);
        }