Ejemplo n.º 1
0
        public void ShouldMerge()
        {
            DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;
            float one = 8192f / 5512;
            var   a   = new TimedHashes(new List <HashedFingerprint>
            {
                new HashedFingerprint(new[] { 1 }, 1, one),
                new HashedFingerprint(new[] { 1 }, 2, 2 * one),
                new HashedFingerprint(new[] { 1 }, 0, 0),
            },
                                        DateTime.Parse("01/15/2019 10:00:00", dtfi));

            var b = new TimedHashes(new List <HashedFingerprint>
            {
                new HashedFingerprint(new[] { 2 }, 1, one),
                new HashedFingerprint(new[] { 2 }, 2, 2 * one),
                new HashedFingerprint(new[] { 2 }, 0, 0)
            },
                                    DateTime.Parse("01/15/2019 10:00:01", dtfi));

            Assert.IsTrue(a.MergeWith(b, out var result));
            Assert.AreEqual(0, result.HashedFingerprints[0].StartsAt);
            Assert.AreEqual(1f, result.HashedFingerprints[1].StartsAt, 0.0001);
            Assert.AreEqual(one, result.HashedFingerprints[2].StartsAt, 0.0001);
            Assert.AreEqual(1 + one, result.HashedFingerprints[3].StartsAt, 0.0001);
            Assert.AreEqual(2 * one, result.HashedFingerprints[4].StartsAt, 0.0001);
            Assert.AreEqual(1 + 2 * one, result.HashedFingerprints[5].StartsAt, 0.0001);
        }
Ejemplo n.º 2
0
        public void ShouldMergeLongSequences()
        {
            DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;
            var first  = new List <HashedFingerprint>();
            var second = new List <HashedFingerprint>();

            float one = 8192f / 5512;

            for (int i = 0; i < 100; ++i)
            {
                first.Add(new HashedFingerprint(new[] { 1 }, (uint)i, i * one));
                second.Add(new HashedFingerprint(new[] { 2 }, (uint)i, i * one));
            }

            var r = new Random();
            var a = new TimedHashes(first.OrderBy(x => r.Next()).ToList(), DateTime.Parse("01/15/2019 10:00:00", dtfi));
            var b = new TimedHashes(second.OrderBy(x => r.Next()).ToList(), DateTime.Parse("01/15/2019 10:00:01.3", dtfi));

            Assert.IsTrue(a.MergeWith(b, out var c));
            for (int i = 0; i < 200; ++i)
            {
                Assert.AreEqual(i, c.HashedFingerprints[i].SequenceNumber);
                if (i % 2 == 0)
                {
                    Assert.AreEqual(one * (i / 2), c.HashedFingerprints[i].StartsAt, 0.0001);
                    CollectionAssert.AreEqual(new[] { 1 }, c.HashedFingerprints[i].HashBins);
                }
                else
                {
                    Assert.AreEqual(1.3f + one * (i / 2), c.HashedFingerprints[i].StartsAt, 0.0001);
                    CollectionAssert.AreEqual(new[] { 2 }, c.HashedFingerprints[i].HashBins);
                }
            }
        }
Ejemplo n.º 3
0
        public void CantMergeSinceTheGapIsTooBig()
        {
            var dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;
            var a    = new TimedHashes(new List <HashedFingerprint>
            {
                new HashedFingerprint(new[] { 1 }, 0, 0)
            },
                                       DateTime.Parse("01/15/2019 10:00:00", dtfi));

            var b = new TimedHashes(new List <HashedFingerprint>
            {
                new HashedFingerprint(new[] { 2 }, 0, 0)
            },
                                    DateTime.Parse("01/15/2019 10:01:00", dtfi));

            Assert.IsFalse(a.MergeWith(b, out _));
        }