Exemple #1
0
        public void Bloom_SamePropertiesAdded_DuplicateExistsInFilter_Success()
        {
            var filter = new BloomFilter();
            var item   = new Dto {
                Name = "I'm in the filter"
            };
            var item2 = new Dto {
                Name = "I'm in the filter"
            };

            filter.AddItem(item);
            filter.AddItem(item2);
            Assert.True(filter.PossiblyExists(item));
            Assert.True(filter.PossiblyExists(item2));
        }
Exemple #2
0
            public static Name Gen(bool allowDuplicates, bool firstNameOnly)
            {
                string fName, lName;

                bool isUnique = true;

                long dupCounter = 0;

                do
                {
                    //Generate first Name
                    fName = _firstNames[random.Next(0, _firstNames.Count)];
                    //Generate last Name
                    lName = _lastNames[random.Next(0, _lastNames.Count)];
                    //Enforce Uniqueness.
                    isUnique = !filter.CheckFor(fName + lName);
                    if (!isUnique)
                    {
                        dupCounter++;
                    }
                    if (dupCounter >= (CALC_CONSTANT ^ 2))

                    {
                        throw new Exception("Out of combinations...");
                    }
                } while (!isUnique);

                //Add to used names
                filter.AddItem(fName + lName);
                //Return new Name Object => See class for more info...
                return(new Name(fName, lName));
            }
            /// <summary>
            /// Generates a DID, Given the dept name
            /// </summary>
            /// <param name="deptName"></param>
            /// <returns></returns>
            public static string DID(string deptName, string STRID)
            {
                var id = "Dpt" + (
                    Convert.ToBase64String(
                        hasher.ComputeHash(
                            Encoding.ASCII.GetBytes(deptName + STRID))).Substring(0, 20) +
                    Convert.ToBase64String(
                        Encoding.ASCII.GetBytes(deptName))).Substring(0, 10);

                if (!filter.CheckFor(id))
                {
                    filter.AddItem(id);
                }

                return(id.Replace("/", "c").Replace("=", "b").Replace("+", "A").Replace("\\", "C"));
            }
Exemple #4
0
        public void Bloom_AddToBloom_PropertyExist_Success()
        {
            var filter = new BloomFilter();
            var item   = new Dto {
                Name = "I'm in the filter"
            };

            filter.AddItem(item);
            Assert.True(filter.PossiblyExists(item));
        }
Exemple #5
0
        public void Bloom_SameProperties_DuplicateExistsInFilter_Success()
        {
            var filter = new BloomFilter();
            var item   = new Dto {
                Name = "I'm in the filter"
            };
            var notInTheFilter = new Dto {
                Name = "I'm in the filter"
            };                                                           // not in the filter. It's a lie.

            filter.AddItem(item);
            Assert.True(filter.PossiblyExists(item));
            Assert.False(filter.PossiblyExists(notInTheFilter));
        }