Ejemplo n.º 1
0
        public void GivenNotIntegerPropertyToAnonymzed_ShouldThrowException()
        {
            var pid        = new Expression <Func <Person, object> >[] { p => p.Job, p => p.City };
            var algorithm  = new KEAnonimization(2, 3, _jobDictionary, _cityDictionary, pid, p => p.Surname);
            var anonymized = algorithm.GetAnonymizedData(_people);

            Assert.IsTrue(!anonymized.Any());
        }
Ejemplo n.º 2
0
        public void GivenEmptyPeopleList_ShouldReturn_EmptyList()
        {
            var pid        = new Expression <Func <Person, object> >[] { p => p.Job, p => p.City };
            var algorithm  = new KEAnonimization(2, 3, _jobDictionary, _cityDictionary, pid, p => p.Age);
            var anonymized = algorithm.GetAnonymizedData(new List <Person>());

            Assert.IsTrue(!anonymized.Any());
        }
Ejemplo n.º 3
0
        public void GivenKParameterOneAndEParametr0_ShouldReturnTheSameList()
        {
            var pid        = new Expression <Func <Person, object> >[] { p => p.Job, p => p.City };
            var algorithm  = new KEAnonimization(1, 0, _jobDictionary, _cityDictionary, pid, p => p.Age);
            var anonymized = algorithm.GetAnonymizedData(_people);

            Assert.IsTrue(anonymized.Any());
            Assert.IsTrue(_people.Count == anonymized.Count);
            Assert.IsTrue(_people.All(p => anonymized.Exists(x => x.FirstName == p.FirstName && x.Surname == p.Surname &&
                                                             x.Age == p.Age && x.Job == p.Job && x.City == p.City &&
                                                             x.Gender == p.Gender)));
        }
Ejemplo n.º 4
0
        public void GivenKParameter_GreaterThan_1_ShouldReturnAnonymizedList(int parameterK, int parameterE)
        {
            var pid       = new Expression <Func <Person, object> >[] { p => p.Job, p => p.City };
            var algorithm = new KEAnonimization(parameterK, parameterE, _jobDictionary, _cityDictionary, pid, p => p.Age);

            var anonymzed = algorithm.GetAnonymizedData(_people);

            Assert.AreEqual(_people.Count, anonymzed.Count);
            //All Groups grouped by X set have at least K unique Y set attribute values
            Assert.IsTrue(anonymzed.GroupBy(x => new { x.Job, x.City })
                          .All(g =>
            {
                var uniqueYValues = g.GroupBy(p => p.Age).Count();
                return(uniqueYValues >= parameterK);
            }));
            Assert.IsTrue(anonymzed.GroupBy(x => new { x.Job, x.City })
                          .All(g =>
            {
                var max = g.Select(p => Convert.ToInt32(p.Age)).Max();
                var min = g.Select(p => Convert.ToInt32(p.Age)).Min();
                return((max - min) >= parameterE);
            }));
        }