Пример #1
0
        public void Basic_NoComparer()
        {
            using (var set = new CappedSet <string>())
            {
                Aver.IsTrue(set.Put("Gagarin"));
                Aver.IsTrue(set.Put("Titov"));
                Aver.IsTrue(set.Put("Glenn"));

                Aver.IsTrue(set.Contains("Glenn"));
                Aver.IsFalse(set.Contains("GLENN"));

                Aver.IsFalse(set.Put("Titov"));
                Aver.AreEqual(3, set.Count);
                Aver.AreEqual(3, set.ToArray().Length);

                DateTime cd;
                Aver.IsTrue(set.Get("Titov", out cd));
                Aver.IsTrue((App.TimeSource.UTCNow - cd).TotalSeconds < 2d);//unless machine freezes :(

                Aver.IsFalse(set.Get("Neverflew", out cd));

                set.Clear();

                Aver.AreEqual(0, set.Count);
                Aver.AreEqual(0, set.ToArray().Length);

                Aver.IsTrue(set.Put("Gagarin"));
                Aver.IsTrue(set.Put("GAGARIN"));

                Aver.IsFalse(set.Put("Gagarin"));
                Aver.IsTrue(set.Remove("Gagarin"));
                Aver.IsTrue(set.Put("Gagarin"));
            }
        }
Пример #2
0
        public void Basic_Comparer()
        {
            using (var set = new CappedSet <string>(NOPApplication.Instance, StringComparer.OrdinalIgnoreCase))
            {
                Aver.IsTrue(set.Put("Gagarin"));
                Aver.IsTrue(set.Put("Titov"));
                Aver.IsTrue(set.Put("Glenn"));

                Aver.IsTrue(set.Contains("Glenn"));
                Aver.IsTrue(set.Contains("GLENN"));

                Aver.IsFalse(set.Put("Titov"));
                Aver.AreEqual(3, set.Count);
                Aver.AreEqual(3, set.ToArray().Length);

                DateTime cd;
                Aver.IsTrue(set.Get("Titov", out cd));
                Aver.IsTrue((Ambient.UTCNow - cd).TotalSeconds < 2d);//unless machine freezes :(

                Aver.IsFalse(set.Get("Neverflew", out cd));

                set.Clear();

                Aver.AreEqual(0, set.Count);
                Aver.AreEqual(0, set.ToArray().Length);

                Aver.IsTrue(set.Put("Gagarin"));
                Aver.IsFalse(set.Put("GAGARIN"));

                Aver.IsTrue(set.Remove("Gagarin"));
                Aver.IsTrue(set.Put("Gagarin"));
            }
        }
Пример #3
0
        public void Mutithreaded()
        {
            using (var set = new CappedSet <int>())
            {
                set.TimeLimitSec = 30;//
                set.SizeLimit    = 7000;

                Parallel.For(0, 1500000, (i) => { set.Put(i); set.Contains(i); });

                for (var i = 0; i < 40; i++)
                {
                    Console.WriteLine(" count: {0}".Args(set.Count));
                    Thread.Sleep(1000);
                }
                Aver.AreEqual(0, set.Count);
            }
        }
Пример #4
0
        public void Max_Size()
        {
            using (var set = new CappedSet <int>())
            {
                set.SizeLimit = 10000;

                for (var i = 0; i < 150000; i++)
                {
                    set.Put(i);
                }

                for (var i = 0; i < 40; i++)
                {
                    Console.WriteLine(" count: {0}".Args(set.Count));
                    Thread.Sleep(1000);
                }
                Aver.IsTrue(set.Count <= (set.SizeLimit + 1024));//1024 margin of error
            }
        }
Пример #5
0
        public void Max_SizeandTime()
        {
            using (var set = new CappedSet <int>())
            {
                set.TimeLimitSec = 30;//
                set.SizeLimit    = 7000;

                for (var i = 0; i < 150000; i++)
                {
                    set.Put(i);
                }

                for (var i = 0; i < 40; i++)
                {
                    Console.WriteLine(" count: {0}".Args(set.Count));
                    Thread.Sleep(1000);
                }
                Aver.AreEqual(0, set.Count);
            }
        }
Пример #6
0
        public void Max_Age()
        {
            using (var set = new CappedSet <int>())
            {
                set.TimeLimitSec = 10;

                for (var i = 0; i < 1000; i++)
                {
                    set.Put(i);
                }

                Aver.AreEqual(1000, set.Count);
                for (var i = 0; i < 40; i++)
                {
                    Console.WriteLine(" count: {0}".Args(set.Count));
                    Thread.Sleep(1000);
                }
                Aver.AreEqual(0, set.Count);

                Aver.IsFalse(set.Any());
            }
        }