Beispiel #1
0
        public void TestClear()
        {
            // Length > 32
            Fingerprint fp = new Fingerprint(65);
            for (int i = 0; i < 65; ++i)
            {
                fp.Touch(i);
                Assert.True(fp.Get(i));
            }
            fp.Clear();
            for (int i = 0; i < 65; ++i)
            {
                Assert.False(fp.Get(i));
            }

            // Length <= 32
            var fp2 = new Fingerprint(6);
            for (int i = 0; i < 6; ++i)
            {
                fp2.Touch(i);
                Assert.True(fp2.Get(i));
            }
            fp.Clear();
            for (int i = 0; i < 6; ++i)
            {
                Assert.False(fp.Get(i));
            }
        }
Beispiel #2
0
        public void TestCreation()
        {
            var fp = new Fingerprint(7);

            var window = new Capo<bool>(fp, 0);
            Assert.AreEqual(7, window.Length);

            window = new Capo<bool>(fp, 3);
            Assert.AreEqual(4, window.Length);

            // Invalid offset initialization attempt never throws
            Assert.DoesNotThrow(() => { window = new Capo<bool>(fp, 7); });
        }
Beispiel #3
0
 public override int GetHashCode(Fingerprint fingerprint)
 {
     var hash = new Hash(base.GetHashCode(fingerprint));
     if (fingerprint.Length <= tag.Offset)
     {
         return hash.Code;
     }
     var touched = new Capo<bool>(fingerprint, tag.Offset);
     if (touched[0])
     {
         hash.Update(message_);
     }
     return hash.Code;
 }
Beispiel #4
0
        public void TestComparison()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);
            Fingerprint fp3 = new Fingerprint(64);
            Fingerprint fp4 = new Fingerprint(66);

            // Length first

            Assert.Less(fp3.CompareTo(fp1), 0);
            Assert.Greater(fp1.CompareTo(fp3), 0);
            fp3.Touch(2);
            Assert.Less(fp3.CompareTo(fp1), 0);
            Assert.Greater(fp1.CompareTo(fp3), 0);

            Assert.Greater(fp4.CompareTo(fp2), 0);
            Assert.Less(fp2.CompareTo(fp4), 0);
            fp2.Touch(64);
            Assert.Greater(fp4.CompareTo(fp2), 0);
            Assert.Less(fp2.CompareTo(fp4), 0);
            fp2.Wipe(64);

            // Bits second
            Assert.AreEqual(0, fp1.CompareTo(fp2));

            fp1.Touch(31);
            Assert.Greater(fp1.CompareTo(fp2), 0);
            Assert.Less(fp2.CompareTo(fp1), 0);

            fp2.Touch(32);
            Assert.Less(fp1.CompareTo(fp2), 0);
            Assert.Greater(fp2.CompareTo(fp1), 0);

            fp1.Touch(32);
            Assert.Greater(fp1.CompareTo(fp2), 0);
            Assert.Less(fp2.CompareTo(fp1), 0);

            fp2.Touch(31);
            Assert.AreEqual(0, fp1.CompareTo(fp2));
            Assert.AreEqual(0, fp2.CompareTo(fp1));

            fp2.Touch(64);
            Assert.Less(fp1.CompareTo(fp2), 0);
            Assert.Greater(fp2.CompareTo(fp1), 0);
        }
Beispiel #5
0
        public void TestCapoing()
        {
            var fp = new Fingerprint(8);
            fp.Touch(2);
            fp.Touch(4);

            var window = new Capo<bool>(fp, 3);
            Assert.False(window[0]);
            Assert.True(window[1]);
            Assert.False(window[2]);

            fp.Wipe(4);
            Assert.False(window[1]);

            // Out-of-range indexing never throws
            Assert.False(window[-8]);
            Assert.False(window[8]);
        }
Beispiel #6
0
        public void TestCapoing()
        {
            var fp = new Fingerprint(8);
            fp.Touch(2);
            fp.Touch(4);

            // Capo just displaces Fingerprint index with a provided offset.

            var window = new Capo<bool>(fp, 3);
            Assert.False(window[0]);
            Assert.True(window[1]);
            Assert.False(window[2]);

            fp.Wipe(4);
            Assert.False(window[1]);

            // Out-of-range indexing never throws
            Assert.False(window[-8]);
            Assert.False(window[8]);
        }
Beispiel #7
0
        public void TestAccessors()
        {
            var fp = new Fingerprint(33);

            Assert.Throws(typeof(IndexOutOfRangeException),
                () => { fp.Get(-1); });
            Assert.Throws(typeof(IndexOutOfRangeException),
                () => { fp.Get(33); });

            Assert.False(fp.Get(31));
            fp.Touch(31);
            Assert.True(fp.Get(31));
            fp.Wipe(31);
            Assert.False(fp.Get(31));

            Assert.False(fp.Get(32));
            fp.Touch(32);
            Assert.True(fp.Get(32));
            fp.Wipe(32);
            Assert.False(fp.Get(32));
        }
Beispiel #8
0
        public void TestEquivalence()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);
            Fingerprint fp3 = new Fingerprint(64);
            Fingerprint fp4 = new Fingerprint(66);

            // Reference first
            Assert.True(fp1.Equivalent(fp1));
            Assert.True(fp2.Equivalent(fp2));
            Assert.True(fp3.Equivalent(fp3));
            Assert.True(fp4.Equivalent(fp4));

            // Length second

            Assert.True(fp3.Equivalent(fp1));
            Assert.False(fp1.Equivalent(fp3));

            Assert.False(fp4.Equivalent(fp2));
            Assert.True(fp2.Equivalent(fp4));

            // Bits third

            Assert.True(fp1.Equivalent(fp2));
            Assert.True(fp2.Equivalent(fp1));

            fp1.Touch(32);
            Assert.False(fp1.Equivalent(fp2));
            Assert.True(fp2.Equivalent(fp1));

            fp2.Touch(32);
            Assert.True(fp1.Equivalent(fp2));
            Assert.True(fp2.Equivalent(fp1));

            fp2.Touch(31);
            Assert.True(fp1.Equivalent(fp2));
            Assert.False(fp2.Equivalent(fp1));

            fp4.Touch(31);
            fp4.Touch(32);
            fp4.Touch(33);
            Assert.True(fp2.Equivalent(fp4));
            Assert.False(fp4.Equivalent(fp2));
        }
Beispiel #9
0
        public void TestEquality()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);
            Fingerprint fp3 = new Fingerprint(64);
            Fingerprint fp4 = new Fingerprint(66);

            // Reference first
            Assert.True(fp1.Equals(fp1));
            Assert.True(fp2.Equals(fp2));
            Assert.True(fp3.Equals(fp3));
            Assert.True(fp4.Equals(fp4));

            // Type second
            Assert.False(fp1.Equals(new Object()));

            // Length third

            Assert.False(fp3.Equals(fp1));
            Assert.False(fp1.Equals(fp3));

            Assert.False(fp4.Equals(fp2));
            Assert.False(fp2.Equals(fp4));

            // Bits forth

            Assert.True(fp1.Equals(fp2));
            Assert.True(fp2.Equals(fp1));

            fp1.Touch(32);
            Assert.False(fp1.Equals(fp2));
            Assert.False(fp2.Equals(fp1));

            fp2.Touch(32);
            Assert.True(fp1.Equals(fp2));
            Assert.True(fp2.Equals(fp1));

            // Length <= 32
            var fp5 = new Fingerprint(7);
            var fp6 = new Fingerprint(7);
            fp5.Touch(0);
            Assert.False(fp5.Equals(fp6));
            fp6.Touch(0);
            Assert.True(fp5.Equals(fp6));
        }
Beispiel #10
0
 /// <summary>
 /// Sets the fingerprint of this cell as the specified one.
 /// </summary>
 internal void SetFingerprint(Fingerprint fingerprint)
 {
     this.fingerprint = fingerprint;
 }
Beispiel #11
0
        public void TestCreation()
        {
            var fp1 = new Fingerprint(1);
            Assert.AreEqual(1, fp1.Length);
            Assert.False(fp1.Get(0));

            Fingerprint fp2 = new Fingerprint(33);
            Assert.AreEqual(33, fp2.Length);
            for (int i = 0; i < 33; ++i)
            {
                Assert.False(fp2.Get(i));
            }
        }
Beispiel #12
0
 public void TestNegativeLength()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => { var fp = new Fingerprint(-1); });
 }
Beispiel #13
0
 protected override bool IsEquivalent(Cell other, Fingerprint fingerprint)
 {
     if (!base.IsEquivalent(other, fingerprint))
     {
         return false;
     }
     return true;
 }
Beispiel #14
0
 protected override bool IsEquivalent(Cell other, Fingerprint fingerprint)
 {
     if (!base.IsEquivalent(other, fingerprint))
     {
         return false;
     }
     TimeoutEvent o = (TimeoutEvent)other;
     var touched = new Capo<bool>(fingerprint, tag.Offset);
     if (touched[0])
     {
         if (key_ != o.key_)
         {
             return false;
         }
     }
     if (touched[1])
     {
         if (intParam_ != o.intParam_)
         {
             return false;
         }
     }
     return true;
 }
		// FIXME: return fingerprint of resource stream somehow

		public override Fingerprint GetFingerprint (IBuildContext ctxt, Fingerprint cached) {
			return GenericFingerprints.Null;
		}
Beispiel #16
0
 protected override bool IsEquivalent(Cell other, Fingerprint fingerprint)
 {
     if (!base.IsEquivalent(other, fingerprint))
     {
         return false;
     }
     HelloResp o = (HelloResp)other;
     var touched = new Capo<bool>(fingerprint, tag.Offset);
     if (touched[0])
     {
         if (result_ != o.result_)
         {
             return false;
         }
     }
     return true;
 }
Beispiel #17
0
 /// <summary>
 /// Determines whether the specified Cell object is equivalent to this
 /// one based on the given fingerprint.
 /// </summary>
 public bool Equivalent(Cell other, Fingerprint fingerprint)
 {
     if (!other.IsKindOf(this))
     {
         return false;
     }
     if (!fingerprint.Equivalent(other.fingerprint))
     {
         return false;
     }
     return IsEquivalent(other, fingerprint);
 }
 public override int GetHashCode(Fingerprint fingerprint)
 {
     var hash = new Hash(base.GetHashCode(fingerprint));
     if (fingerprint.Length <= tag.Offset)
     {
         return hash.Code;
     }
     var touched = new Capo<bool>(fingerprint, tag.Offset);
     if (touched[0])
     {
         hash.Update(linkName);
     }
     if (touched[1])
     {
         hash.Update(result);
     }
     if (touched[2])
     {
         hash.Update(context);
     }
     return hash.Code;
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new Cell instance with the given fingerprint length.
 /// </summary>
 protected Cell(int length)
 {
     fingerprint = new Fingerprint(length);
 }
Beispiel #20
0
 /// <summary>
 /// Overridden by subclasses to build an equivalence test chain.
 /// </summary>
 protected virtual bool IsEquivalent(Cell other, Fingerprint fingerprint)
 {
     return true;
 }
Beispiel #21
0
        public void TestGetLength()
        {
            var fp1 = new Fingerprint(99);

            Assert.AreEqual(99, fp1.Length);

            var blen = fp1.GetLength();

            var lengthInBytes = (((fp1.Length - 1) >> 3) + 1);
            var expectedBytesLen = lengthInBytes  + Serializer.GetLengthVariableNonnegative(99);

            Assert.AreEqual(expectedBytesLen, blen);
        }
Beispiel #22
0
 public override int GetHashCode(Fingerprint fingerprint)
 {
     var hash = new Hash(base.GetHashCode(fingerprint));
     return hash.Code;
 }
Beispiel #23
0
        public void TestHashing()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);
            Fingerprint fp3 = new Fingerprint(64);
            Fingerprint fp4 = new Fingerprint(66);

            Assert.AreEqual(fp1.GetHashCode(), fp2.GetHashCode());
            Assert.AreNotEqual(fp1.GetHashCode(), fp3.GetHashCode());
            Assert.AreNotEqual(fp2.GetHashCode(), fp4.GetHashCode());

            fp1.Touch(32);
            Assert.AreNotEqual(fp1.GetHashCode(), fp2.GetHashCode());
            fp2.Touch(32);
            Assert.AreEqual(fp1.GetHashCode(), fp2.GetHashCode());
        }
Beispiel #24
0
 public override int GetHashCode(Fingerprint fingerprint)
 {
     var hash = new Hash(base.GetHashCode(fingerprint));
     if (fingerprint.Length <= tag.Offset)
     {
         return hash.Code;
     }
     var touched = new Capo<bool>(fingerprint, tag.Offset);
     if (touched[0])
     {
         hash.Update(tag.Offset + 0);
         hash.Update(key_);
     }
     if (touched[1])
     {
         hash.Update(tag.Offset + 1);
         hash.Update(intParam_);
     }
     return hash.Code;
 }
Beispiel #25
0
        public void TestSerialization()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);

            fp1.Touch(0);
            fp1.Touch(2);
            fp1.Touch(31);
            fp1.Touch(32);

            Assert.False(fp2.Equals(fp1));

            var buffer = new x2.Buffer();
            fp1.Serialize(new Serializer(buffer));
            buffer.Rewind();
            fp2.Deserialize(new Deserializer(buffer));

            Assert.True(fp2.Equals(fp1));
        }
Beispiel #26
0
        public void TestCopyCreation()
        {
            Fingerprint fp1 = new Fingerprint(65);
            fp1.Touch(32);
            Fingerprint fp2 = new Fingerprint(fp1);
            Assert.True(fp2.Get(32));

            // Ensure that the original block array is not shared
            fp1.Touch(64);
            Assert.False(fp2.Get(64));
        }
Beispiel #27
0
 public void TestNegativeLength()
 {
     Fingerprint fp = new Fingerprint(-1);
 }
Beispiel #28
0
 /// <summary>
 /// Overridden by subclasses to build a hash code generator chain.
 /// </summary>
 public virtual int GetHashCode(Fingerprint fingerprint)
 {
     return Hash.Seed;
 }
Beispiel #29
0
 public override int GetHashCode(Fingerprint fingerprint)
 {
     return Hash.Update(base.GetHashCode(fingerprint), tag.TypeId);
 }
Beispiel #30
0
        public void TestSerialization()
        {
            Fingerprint fp1 = new Fingerprint(65);
            Fingerprint fp2 = new Fingerprint(65);

            fp1.Touch(0);
            fp1.Touch(2);
            fp1.Touch(31);
            fp1.Touch(32);

            Assert.False(fp2.Equals(fp1));

            /*
            Buffer buffer = new Buffer(12);
            fp1.Dump(buffer);
            buffer.Rewind();
            fp2.Load(buffer);

            Assert.True(fp2.Equals(fp1));
            */
        }