コード例 #1
0
        public void TestCopyTo()
        {
            var          ids     = new uint[] { 20, 19, 15, 12, 11, 10, 9, 6, 5, 3, 2, 1 };
            const string example = "20:19,15,12:9,6:5,3:1";
            var          copy    = new UniqueId[ids.Length];
            UniqueIdSet  uids;

            Assert.IsTrue(UniqueIdSet.TryParse(example, 20160117, out uids), "Failed to parse uids.");
            Assert.AreEqual(SortOrder.Descending, uids.SortOrder);
            Assert.AreEqual(20160117, uids.Validity);
            Assert.AreEqual(example, uids.ToString());
            Assert.AreEqual(ids.Length, uids.Count);

            for (int i = 0; i < uids.Count; i++)
            {
                Assert.AreEqual(20160117, uids[i].Validity);
                Assert.AreEqual(ids[i], uids[i].Id);
            }

            uids.CopyTo(copy, 0);

            for (int i = 0; i < copy.Length; i++)
            {
                Assert.AreEqual(20160117, copy[i].Validity);
                Assert.AreEqual(ids[i], copy[i].Id);
            }
        }
コード例 #2
0
        public void TestEnumerator()
        {
            var          ids     = new uint[] { 20, 19, 15, 12, 11, 10, 9, 6, 5, 3, 2, 1 };
            const string example = "20:19,15,12:9,6:5,3:1";
            UniqueIdSet  uids;

            Assert.IsTrue(UniqueIdSet.TryParse(example, 20160117, out uids), "Failed to parse uids.");
            Assert.AreEqual(SortOrder.Descending, uids.SortOrder);
            Assert.AreEqual(20160117, uids.Validity);
            Assert.AreEqual(example, uids.ToString());
            Assert.AreEqual(ids.Length, uids.Count);

            for (int i = 0; i < uids.Count; i++)
            {
                Assert.AreEqual(ids[i], uids[i].Id);
            }

            var list = new List <UniqueId> ();

            foreach (var uid in uids)
            {
                Assert.AreEqual(20160117, uid.Validity);
                list.Add(uid);
            }

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(ids[i], list[i].Id);
            }
        }
コード例 #3
0
        public void TestArgumentExceptions()
        {
            var      uids = new UniqueIdSet(SortOrder.Ascending);
            UniqueId uid;

            Assert.IsFalse(uids.IsReadOnly);

            uids.Add(UniqueId.MinValue);

            Assert.Throws <ArgumentOutOfRangeException> (() => new UniqueIdSet((SortOrder)500));
            Assert.Throws <ArgumentException> (() => uids.Add(UniqueId.Invalid));
            Assert.Throws <ArgumentNullException> (() => uids.AddRange(null));
            Assert.Throws <ArgumentNullException> (() => uids.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.CopyTo(new UniqueId[1], -1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uid = uids[-1]);
            Assert.Throws <NotSupportedException> (() => uids[0]   = UniqueId.MinValue);
            Assert.Throws <NotSupportedException> (() => uids.Insert(0, UniqueId.MinValue));

            var list = new List <UniqueId> {
                UniqueId.Invalid
            };

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.ToString(null));
            Assert.Throws <ArgumentException> (() => UniqueIdSet.ToString(list));

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.TryParse(null, out uids));
        }
コード例 #4
0
        public void TestParsingInvalidInputs()
        {
            UniqueIdSet uids;

            Assert.IsFalse(UniqueIdSet.TryParse("xyz", out uids));
            Assert.IsFalse(UniqueIdSet.TryParse("1:x", out uids));
            Assert.IsFalse(UniqueIdSet.TryParse("1:1x", out uids));
        }
コード例 #5
0
        public void TestParsingSimple()
        {
            const string example = "1:3,5:6,9:12,15,19:20";
            UniqueIdSet  uids;

            Assert.IsTrue(UniqueIdSet.TryParse(example, out uids), "Failed to parse uids.");
            Assert.AreEqual(example, uids.ToString());
        }
コード例 #6
0
        public void TestParsingReversedSet()
        {
            var          ids     = new uint[] { 20, 19, 15, 12, 11, 10, 9, 6, 5, 3, 2, 1 };
            const string example = "20:19,15,12:9,6:5,3:1";
            UniqueIdSet  uids;

            Assert.IsTrue(UniqueIdSet.TryParse(example, out uids), "Failed to parse uids.");
            Assert.AreEqual(example, uids.ToString());
            Assert.AreEqual(ids.Length, uids.Count);

            for (int i = 0; i < uids.Count; i++)
            {
                Assert.AreEqual(ids[i], uids[i].Id);
            }
        }