public void Intersection()
        {
            // Intersection with empty set
            Assert.AreEqual(0, testPowerSet1.Intersection(testPowerSet0).capacity);

            // Intersection with PowerSet2 contains 5 items (expected 2 items)
            testPowerSet = testPowerSet1.Intersection(testPowerSet2);
            Assert.AreEqual(2, testPowerSet.capacity);
            Assert.AreEqual(true, testPowerSet.Get(14));
            Assert.AreEqual(true, testPowerSet.Get(16));
            Assert.AreEqual(false, testPowerSet.Get(100));

            // Putting 5 items to empty set
            testPowerSet0.Put(101);
            testPowerSet0.Put(102);
            testPowerSet0.Put(103);
            testPowerSet0.Put(104);
            testPowerSet0.Put(105);
            Assert.AreEqual(5, testPowerSet0.capacity);

            // Intersection with PowerSet0 contains 5 different items (expected empty set)
            testPowerSet = testPowerSet1.Intersection(testPowerSet0);
            Assert.AreEqual(0, testPowerSet.capacity);
            Assert.AreEqual(false, testPowerSet.Get(101));
        }
Esempio n. 2
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            // разница текущего множества и set2

            PowerSet <T> differenced = new PowerSet <T>();

            if (set2.count == 0)
            ///return this;
            {
                foreach (T item in slots)
                {
                    differenced.Put(item);
                }
            }

            foreach (T item in this.slots)
            {
                if (!set2.Get(item))
                {
                    differenced.Put(item);
                }
            }
            if (differenced.count > 0)
            {
                return(differenced);
            }
            else
            {
                return(differenced);
            }
        }
Esempio n. 3
0
        public PowerSet <T> Intersection(PowerSet <T> set2) // пересечение текущего множества и set2
        {
            PowerSet <T> setIntersection = new PowerSet <T>();

            if (set2 != null)
            {
                for (int i = 0; i < size; i++)
                {
                    if (slots[i] == null)
                    {
                        continue;
                    }
                    else if (slots[i].Equals(default(T)))
                    {
                        continue;
                    }
                    if (set2.Get(slots[i]))
                    {
                        setIntersection.Put(slots[i]);
                    }
                }
                return(setIntersection);
            }
            return(setIntersection);
        }
Esempio n. 4
0
        public PowerSet <T> Intersection(PowerSet <T> set2)
        {
            PowerSet <T> interset = new PowerSet <T>();

            if (set2 != null)
            {
                for (int i = 0; i < size; i++)
                {
                    if (slots[i] == null)
                    {
                        continue;
                    }
                    else if (slots[i].Equals(default(T)))
                    {
                        continue;
                    }
                    if (set2.Get(slots[i]))
                    {
                        interset.Put(slots[i]);
                    }
                }
                return(interset);
            }
            return(null);
        }
        public void Union()
        {
            // Union with PowerSet2 contains 5 items (expected 8 unique items)
            testPowerSet = testPowerSet1.Union(testPowerSet2);
            Assert.AreEqual(8, testPowerSet.capacity);
            Assert.AreEqual(true, testPowerSet.Get(8));
            Assert.AreEqual(true, testPowerSet.Get(10));
            Assert.AreEqual(true, testPowerSet.Get(12));
            Assert.AreEqual(true, testPowerSet.Get(14));
            Assert.AreEqual(true, testPowerSet.Get(16));
            Assert.AreEqual(true, testPowerSet.Get(162));
            Assert.AreEqual(true, testPowerSet.Get(0));
            Assert.AreEqual(true, testPowerSet.Get(5));
            Assert.AreEqual(false, testPowerSet.Get(13));

            // Union with empty set
            Assert.AreEqual(5, testPowerSet1.Union(testPowerSet0).capacity);
            Assert.AreEqual(5, testPowerSet0.Union(testPowerSet1).capacity);
        }
Esempio n. 6
0
        public PowerSet <T> Intersection(PowerSet <T> set2)
        {
            // пересечение текущего множества и set2
            PowerSet <T> intersect = new PowerSet <T>();

            foreach (var item in ps)
            {
                if (set2.Get(item))
                {
                    intersect.Put(item);
                }
            }
            return(intersect);
        }
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            // разница текущего множества и set2
            var diff = new PowerSet <T>();

            foreach (var item in items.Keys)
            {
                if (!set2.Get(item))
                {
                    diff.Put(item);
                }
            }
            return(diff);
        }
        public PowerSet <T> Union(PowerSet <T> set2)
        {
            // объединение текущего множества и set2
            PowerSet <T> temp = new PowerSet <T>();

            temp = Intersection(set2);

            for (int i = 0; i < pool.Count; i++)
            {
                if (temp.Get(pool[i]) == false)
                {
                    temp.Put(pool[i]);
                }
            }
            for (int i = 0; i < set2.pool.Count; i++)
            {
                if (temp.Get(set2.pool[i]) == false)
                {
                    temp.Put(set2.pool[i]);
                }
            }
            return(temp);
        }
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            // разница текущего множества и set2
            PowerSet <T> temp = new PowerSet <T>();

            for (int i = 0; i < pool.Count; i++)
            {
                if (set2.Get(pool[i]) == false)
                {
                    temp.Put(pool[i]);
                }
            }
            return(temp);
        }
        public void Difference()
        {
            // Difference with PowerSet2 contains 2 similar items (expected 3 different items)
            testPowerSet = testPowerSet1.Difference(testPowerSet2);
            Assert.AreEqual(3, testPowerSet.capacity);
            Assert.AreEqual(true, testPowerSet.Get(8));
            Assert.AreEqual(true, testPowerSet.Get(10));
            Assert.AreEqual(true, testPowerSet.Get(12));
            Assert.AreEqual(false, testPowerSet.Get(16));

            testPowerSet = testPowerSet2.Difference(testPowerSet1);
            Assert.AreEqual(3, testPowerSet.capacity);
            Assert.AreEqual(true, testPowerSet.Get(162));
            Assert.AreEqual(true, testPowerSet.Get(0));
            Assert.AreEqual(true, testPowerSet.Get(5));
            Assert.AreEqual(false, testPowerSet.Get(12));

            // Difference with empty set (A / 0 = A)
            Assert.AreEqual(5, testPowerSet1.Difference(testPowerSet0).capacity);

            // Difference with empty set (0 / A = 0)
            Assert.AreEqual(0, testPowerSet0.Difference(testPowerSet1).capacity);
        }
        public PowerSet <T> Intersection(PowerSet <T> set2)
        {
            // пересечение текущего множества и set2
            PowerSet <T> temp = new PowerSet <T>();

            for (int i = 0; i < pool.Count; i++)
            {
                if (set2.Get(pool[i]) == true)
                {
                    temp.Put(pool[i]);
                }
            }
            return(temp);
        }
Esempio n. 12
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            // разница текущего множества и set2
            // пересечение текущего множества и set2
            PowerSet <T> difset = new PowerSet <T>();

            foreach (var item in ps)
            {
                if (!set2.Get(item))
                {
                    difset.Put(item);
                }
            }
            return(difset);
        }
Esempio n. 13
0
        public PowerSet <T> Intersection(PowerSet <T> set2)
        {
            PowerSet <T> result = new PowerSet <T>();

            foreach (var slot in slots)
            {
                foreach (var item in slot)
                {
                    if (set2.Get(item))
                    {
                        result.Put(item);
                    }
                }
            }
            return(result);
        }
        public PowerSet <T> Intersection(PowerSet <T> set2)
        {
            // пересечение текущего множества и set2
            PowerSet <T> Intersected = new PowerSet <T>();

            if (capacity > 0 && set2.capacity > 0)
            {
                foreach (T item in slots)
                {
                    if (set2.Get(item))
                    {
                        Intersected.Put(item);
                    }
                }
            }
            return(Intersected);
        }
Esempio n. 15
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            PowerSet <T> diff = new PowerSet <T>();

            if (set2 != null)
            {
                for (int i = 0; i < size; i++)
                {
                    if (slots[i] != null)
                    {
                        if (!set2.Get(slots[i]))
                        {
                            diff.Put(slots[i]);
                        }
                    }
                }
                return(diff);
            }
            return(null);
        }
        public bool IsSubset(PowerSet <T> set2)
        {
            // возвращает true, если set2 есть
            // подмножество текущего множества,
            // иначе false
            int count = 0;

            for (int i = 0; i < pool.Count; i++)
            {
                if (set2.Get(pool[i]) == true)
                {
                    count++;
                }
            }
            if (count == set2.pool.Count)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 17
0
        public PowerSet <T> Difference(PowerSet <T> set2) // разница текущего множества и set2
        {
            PowerSet <T> setDifference = new PowerSet <T>();

            if (set2 != null)
            {
                for (int i = 0; i < size; i++)
                {
                    if (slots[i] != null)
                    {
                        if (!set2.Get(slots[i]))
                        {
                            setDifference.Put(slots[i]);
                        }
                    }
                }
                return(setDifference);
            }
            return(setDifference);
        }
Esempio n. 18
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            if (set2 == null)
            {
                return(null);
            }

            PowerSet <T> resultSet = new PowerSet <T>();

            for (int i = 0; i < _values.Length; i++)
            {
                T currentValue = _values[i];
                if (_slotsStatus[i] == SlotStatus.Fill && !set2.Get(currentValue))
                {
                    resultSet.Put(currentValue);
                }
            }

            return(resultSet);
        }
        public bool IsSubset(PowerSet <T> set2)
        {
            // возвращает true, если set2 есть
            // подмножество текущего множества,
            // иначе false
            int count = 0;

            if (capacity >= set2.capacity)
            {
                foreach (T item in slots)
                {
                    if (set2.Get(item))
                    {
                        count++;
                    }
                }
                if (count == set2.capacity)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 20
0
        static void TestPowerSet()
        {
            Console.WriteLine("test power set");
            PowerSet <int> powerSet = new PowerSet <int>();

            for (int i = 0; i <= 10; i++)
            {
                powerSet.Put(i);
            }

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test put 11");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            powerSet.Put(11);
            Console.WriteLine("power set size after = " + powerSet.Size());

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();

            Console.WriteLine("test put 10");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            powerSet.Put(10);
            Console.WriteLine("power set size after = " + powerSet.Size());

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 4");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            bool result = powerSet.Remove(4);

            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 4");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            result = powerSet.Remove(4);
            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine();
            Console.WriteLine("test remove 20");
            Console.WriteLine("power set size before  = " + powerSet.Size());
            result = powerSet.Remove(20);
            Console.WriteLine("power set size after = " + powerSet.Size());
            Console.WriteLine("remove result = " + result);
            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.Write(powerSet._values[i] + " ");
            }

            Console.WriteLine("test get");

            for (int i = 0; i < powerSet._values.Length; i++)
            {
                Console.WriteLine(i + " get result = " + powerSet.Get(i));
            }

            Console.WriteLine();
            Console.WriteLine(new string('=', 50));
        }