Esempio n. 1
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));
        }
Esempio n. 2
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));
            }
        }
Esempio n. 3
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));
            }
        }
Esempio n. 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.True(fp3.CompareTo(fp1) < 0);
            Assert.True(fp1.CompareTo(fp3) > 0);
            fp3.Touch(2);
            Assert.True(fp3.CompareTo(fp1) < 0);
            Assert.True(fp1.CompareTo(fp3) > 0);

            Assert.True(fp4.CompareTo(fp2) > 0);
            Assert.True(fp2.CompareTo(fp4) < 0);
            fp2.Touch(64);
            Assert.True(fp4.CompareTo(fp2) > 0);
            Assert.True(fp2.CompareTo(fp4) < 0);
            fp2.Wipe(64);

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

            fp1.Touch(31);
            Assert.True(fp1.CompareTo(fp2) > 0);
            Assert.True(fp2.CompareTo(fp1) < 0);

            fp2.Touch(32);
            Assert.True(fp1.CompareTo(fp2) < 0);
            Assert.True(fp2.CompareTo(fp1) > 0);

            fp1.Touch(32);
            Assert.True(fp1.CompareTo(fp2) > 0);
            Assert.True(fp2.CompareTo(fp1) < 0);

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

            fp2.Touch(64);
            Assert.True(fp1.CompareTo(fp2) < 0);
            Assert.True(fp2.CompareTo(fp1) > 0);
        }
Esempio n. 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]);
        }
Esempio n. 6
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));
        }
Esempio n. 7
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 x2net.Buffer();

            fp1.Serialize(new Serializer(buffer));
            buffer.Rewind();
            fp2.Deserialize(new Deserializer(buffer));

            Assert.True(fp2.Equals(fp1));
        }
Esempio n. 8
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]);
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }
Esempio n. 11
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]);
        }
Esempio n. 12
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.Equal(fp1.GetHashCode(), fp2.GetHashCode());
            Assert.NotEqual(fp1.GetHashCode(), fp3.GetHashCode());
            Assert.NotEqual(fp2.GetHashCode(), fp4.GetHashCode());

            fp1.Touch(32);
            Assert.NotEqual(fp1.GetHashCode(), fp2.GetHashCode());
            fp2.Touch(32);
            Assert.Equal(fp1.GetHashCode(), fp2.GetHashCode());
        }
Esempio n. 13
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));
        }
Esempio n. 14
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);
        }
Esempio n. 15
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));
        }
Esempio n. 16
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());
        }
Esempio n. 17
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));
        }
Esempio n. 18
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));
        }
Esempio n. 19
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));
        }
Esempio n. 20
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));
            */
        }