public void RemoveItem()
        {
            // PowerSet {21 5 0 53 102}
            testPowerSet.Put(21);
            testPowerSet.Put(5);
            testPowerSet.Put(0);
            testPowerSet.Put(53);
            testPowerSet.Put(102);
            Assert.AreEqual(5, testPowerSet.capacity);

            // Remove wrong value (zero effect)
            Assert.AreEqual(false, testPowerSet.Remove(13));
            Assert.AreEqual(5, testPowerSet.capacity);

            // Remove existing value
            Assert.AreEqual(true, testPowerSet.Remove(21));
            Assert.AreEqual(4, testPowerSet.capacity);

            Assert.AreEqual(true, testPowerSet.Remove(5));
            Assert.AreEqual(3, testPowerSet.capacity);

            Assert.AreEqual(true, testPowerSet.Remove(0));
            Assert.AreEqual(2, testPowerSet.capacity);

            Assert.AreEqual(true, testPowerSet.Remove(53));
            Assert.AreEqual(1, testPowerSet.capacity);

            Assert.AreEqual(true, testPowerSet.Remove(102));
            Assert.AreEqual(0, testPowerSet.capacity);

            // Remove value from empty list (zero effect)
            Assert.AreEqual(false, testPowerSet.Remove(0));
            Assert.AreEqual(0, testPowerSet.capacity);
        }
        /// <summary>
        /// вычисляет и возвращает новое множество - разницу текущего множества и множества set2
        /// </summary>
        /// <param name="set2">множество PowerSet<T> значений типа T</param>
        /// <returns>множество PowerSet<T> разница текущего множества и множества set2</returns>
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            PowerSet <T> difSet = new PowerSet <T>();

            foreach (T item in items)
            {
                // добавляем все элементы первого множества
                difSet.Put(item);
            }

            foreach (T item in set2.items)
            {
                // удаляем все элементы второго множества, которые присутствуют в первом
                difSet.Remove(item);
            }

            return(difSet);
        }
Esempio n. 3
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            PowerSet <T> temp = new PowerSet <T>();

            foreach (T a in dict.Values)
            {
                temp.Put(a);
            }
            foreach (T a in set2.dict.Values)
            {
                if (dict.ContainsKey(Convert.ToString(a)))
                {
                    temp.Remove(a);
                }
            }
            return(temp);
            // разница текущего множества и set2
        }
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            // разница текущего множества и set2
            PowerSet <T> Differed = new PowerSet <T>();

            if (capacity > 0)
            {
                foreach (T item in slots)
                {
                    Differed.Put(item);
                }
                foreach (T item in set2.slots)
                {
                    Differed.Remove(item);
                }
            }
            return(Differed);
        }
Esempio n. 5
0
        public PowerSet <T> Difference(PowerSet <T> set2)
        {
            PowerSet <T> result = new PowerSet <T>();

            foreach (var slot in slots)
            {
                foreach (var item in slot)
                {
                    result.Put(item);
                }
            }
            foreach (var slot in set2.slots)
            {
                foreach (var item in slot)
                {
                    result.Remove(item);
                }
            }
            return(result);
        }
Esempio n. 6
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));
        }