Beispiel #1
0
        public void TestT0()
        {
            var hs    = new HagelSource();
            var first = hs.Monotonic(now: hs.Start);

            Assert.IsTrue(first.All(c => c == hs.Alphabet[0]));
        }
 public void TestBase()
 {
     Assert.AreEqual("09", HagelSource.Base(9, "0123456789ABCDEF", 2));
     Assert.AreEqual("0D", HagelSource.Base(13, "0123456789ABCDEF", 2));
     Assert.AreEqual("10", HagelSource.Base(16, "0123456789ABCDEF", 2));
     Assert.AreEqual("100", HagelSource.Base(256, "0123456789ABCDEF", 2));
 }
        public void TestEquivalence()
        {
            var    hs           = new HagelSource();
            var    now          = DateTime.Now;
            string hs_monotonic = hs.Monotonic(now);
            string hs_hagelkorn = HagelSource.Monotonic(now: now);

            Assert.AreEqual(hs_monotonic, hs_hagelkorn);
        }
Beispiel #4
0
        public void TestTOverflow()
        {
            var hs       = new HagelSource();
            var overflow = hs.Monotonic(now: hs.End);

            Assert.AreEqual(hs.Digits + 1, overflow.Length);
            string expected = hs.Alphabet[1].ToString() + new string(hs.Alphabet[0], hs.Digits);

            Assert.AreEqual(expected, overflow);
        }
Beispiel #5
0
        public void TestConstructor()
        {
            var hs = new HagelSource(overflow_years: 42);

            Assert.AreEqual((hs.End - hs.Start).TotalSeconds, hs.TotalSeconds);
            Assert.AreEqual(42 * 31536000, hs.TotalSeconds);
            Assert.AreEqual(hs.Alphabet.Length, hs.B);
            Assert.AreEqual(hs.Combinations, Math.Pow(hs.B, hs.Digits));
            Assert.AreEqual(hs.Resolution, hs.TotalSeconds / hs.Combinations);
        }
        public void TestRandom()
        {
            HashSet <string> ids = new HashSet <string>();

            for (int i = 0; i < 100; i++)
            {
                ids.Add(HagelSource.Random());
            }
            Assert.AreEqual(100, ids.Count);
        }
Beispiel #7
0
        public void TestMonotonic()
        {
            var hs = new HagelSource(
                resolution: Resolution.Days,
                alphabet: "0123456789",
                start: new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                overflow_years: 1);
            var id = hs.Monotonic(now: new DateTime(2018, 12, 31, 23, 59, 59, DateTimeKind.Utc));

            Assert.AreEqual(hs.Digits, id.Length);
            Assert.AreEqual("999", id);
        }
        public void TestMonotonic()
        {
            string id = HagelSource.Monotonic(
                resolution: Resolution.Days,
                now: new DateTime(2018, 12, 31, 23, 59, 59, DateTimeKind.Utc),
                alphabet: "0123456789",
                start: new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                overflow_years: 1
                );

            Assert.AreEqual("999", id);
        }
        public void TestKeyLength()
        {
            (int D1, long K1, double T1) = HagelSource.KeyLength(
                overflow_years: 1,
                resolution: Resolution.Days,
                B: 10);
            Assert.AreEqual(3, D1);
            Assert.AreEqual(Math.Pow(10, D1), K1);
            Assert.AreEqual(3, D1);
            Assert.IsTrue(T1 < Resolution.Days);

            (int D2, long K2, double T2) = HagelSource.KeyLength(
                overflow_years: 30,
                resolution: Resolution.Days,
                B: 27);
            Assert.AreEqual(Math.Pow(27, D2), K2);
            Assert.IsTrue(T2 < Resolution.Days);
        }