コード例 #1
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestIntersectionInterface()
        {
            Bag <string> b1 = new Bag <string>();
            Bag <string> b2 = GetTestBag();

            Bag <string> result = (Bag <string>)((IBag <string>)b1).Intersection(b2);

            Assert.AreEqual(result.IsEqual(b1), true);

            b1.Add("50", 2);

            Bag <string> shouldBe = new Bag <string>();

            result = (Bag <string>)((IBag <string>)b1).Intersection(b2);

            Assert.AreEqual(shouldBe.IsEqual(result), true);

            b1.Add("2", 2);

            shouldBe.Add("2", 2);

            result = (Bag <string>)((IBag <string>)b1).Intersection(b2);

            Assert.AreEqual(shouldBe.IsEqual(result), true);
        }
コード例 #2
0
        public void Interface()
        {
            var bag1 = new Bag <int>();
            var bag2 = new Bag <int>();

            bag1.Add(2, 2);
            bag1.Add(3, 3);
            bag1.Add(4, 5);

            bag2.Add(3, 2);
            bag2.Add(4, 3);
            bag2.Add(5, 2);

            var shouldBe = new Bag <int> {
                { 2, 2 }, { 3, 5 }, { 4, 8 }, { 5, 2 }
            };

            var resultBag = (Bag <int>)((IBag <int>)bag1).Union(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));

            resultBag = (Bag <int>)((IBag <int>)bag2).Union(bag1);

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #3
0
ファイル: Subtract.cs プロジェクト: GTuritto/ngenerics
        public void Interface()
        {
            var bag1 = new Bag<int> { 3, 4, 5, 6 };

            var bag2 = new Bag<int> { 3, 4, 5 };

            var shouldBe = new Bag<int> { 6 };

            var resultBag = (Bag<int>)((IBag<int>)bag1).Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1.Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
コード例 #4
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestIsEqualInterface()
        {
            Bag <int> b1 = new Bag <int>();
            Bag <int> b2 = new Bag <int>();

            Assert.AreEqual(((IBag <int>)b1).IsEqual(b2), true);
            Assert.AreEqual(((IBag <int>)b2).IsEqual(b1), true);

            b2.Add(5);

            Assert.AreEqual(((IBag <int>)b1).IsEqual(b2), false);
            Assert.AreEqual(((IBag <int>)b2).IsEqual(b1), false);

            b1.Add(5);

            Assert.AreEqual(((IBag <int>)b1).IsEqual(b2), true);
            Assert.AreEqual(((IBag <int>)b2).IsEqual(b1), true);

            b2.Add(6);

            Assert.AreEqual(((IBag <int>)b1).IsEqual(b2), false);
            Assert.AreEqual(((IBag <int>)b2).IsEqual(b1), false);

            b1.Add(7);

            Assert.AreEqual(((IBag <int>)b1).IsEqual(b2), false);
            Assert.AreEqual(((IBag <int>)b2).IsEqual(b1), false);
        }
コード例 #5
0
        public static MouseButtons[] GetPressedButtons(this MouseState mouseState)
        {
            var pressedButtons = new Bag <MouseButtons>();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                pressedButtons.Add(MouseButtons.LeftButton);
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                pressedButtons.Add(MouseButtons.RightButton);
            }

            if (mouseState.MiddleButton == ButtonState.Pressed)
            {
                pressedButtons.Add(MouseButtons.MiddleButton);
            }

            if (mouseState.XButton1 == ButtonState.Pressed)
            {
                pressedButtons.Add(MouseButtons.XButton1);
            }

            if (mouseState.XButton2 == ButtonState.Pressed)
            {
                pressedButtons.Add(MouseButtons.XButton2);
            }

            return(pressedButtons.ToArray());
        }
コード例 #6
0
ファイル: Subtract.cs プロジェクト: GTuritto/ngenerics
        public void Simple()
        {
            var bag1 = new Bag<int> { 3, 4, 5, 6 };

            var bag2 = new Bag<int> { 3, 4, 5 };

            var shouldBe = new Bag<int> { 6 };

            var resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
コード例 #7
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestUnion()
        {
            Bag <int> b1 = new Bag <int>();
            Bag <int> b2 = new Bag <int>();

            b1.Add(2, 2);
            b1.Add(3, 3);
            b1.Add(4, 5);

            b2.Add(3, 2);
            b2.Add(4, 3);
            b2.Add(5, 2);
            b2.Add(6, 2);

            Bag <int> shouldBe = new Bag <int>();

            shouldBe.Add(2, 2);
            shouldBe.Add(3, 5);
            shouldBe.Add(4, 8);
            shouldBe.Add(5, 2);
            shouldBe.Add(6, 2);

            Bag <int> result = b1 + b2;

            Assert.AreEqual(shouldBe.IsEqual(result), true);

            result = b2 + b1;

            Assert.AreEqual(shouldBe.IsEqual(result), true);
        }
コード例 #8
0
        private Bag CreateBag3()
        {
            Bag  bag  = new Bag(20.0f);
            Junk junk = new Junk(
                Guid.NewGuid(),
                "Leather Scraps",
                null,
                false,
                .5f,
                InventorySlotId.UNEQUIPPABLE,
                1);
            Junk junk1 = new Junk(
                Guid.NewGuid(),
                "Iron Dust",
                null,
                false,
                1f,
                InventorySlotId.UNEQUIPPABLE,
                5);
            Junk junk2 = new Junk(
                Guid.NewGuid(),
                "Rotten Flesh",
                null,
                false,
                1f,
                InventorySlotId.UNEQUIPPABLE,
                1);

            bag.Add(junk);
            bag.Add(junk1);
            bag.Add(junk2);
            return(bag);
        }
コード例 #9
0
ファイル: Intersection.cs プロジェクト: havok/ngenerics
        public void Interface()
        {
            var bag1 = new Bag<string>();
            var bag2 = GetTestBag();

            var resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag<string>();

            resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = (Bag<string>)((IBag<string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #10
0
        /// <summary>
        /// Returns all edges in this edge-weighted graph.
        /// To iterate over the edges in this edge-weighted graph, use foreach notation:
        /// </summary>
        /// <returns>all edges in this edge-weighted graph, as an iterable</returns>
        public IEnumerable <EdgeW> Edges()
        {
            var list = new Bag <EdgeW>();

            for (var v = 0; v < V; v++)
            {
                var selfLoops = 0;
                foreach (var e in Adj(v))
                {
                    if (e.Other(v) > v)
                    {
                        list.Add(e);
                    }
                    // only add one copy of each self loop (self loops will be consecutive)
                    else if (e.Other(v) == v)
                    {
                        if (selfLoops % 2 == 0)
                        {
                            list.Add(e);
                        }
                        selfLoops++;
                    }
                }
            }
            return(list);
        }
コード例 #11
0
        public void TestInventoryGetSum5()
        {
            var  inventory = new Bag();
            Item item1     = new Item();

            item1.Id      = Guid.NewGuid();
            item1.Name    = "a";
            item1.Weight  = 10;
            item1.Count   = 1;
            item1.Effects = new Effect[] { new Effect()
                                           {
                                               Type = EFFECT_TYPE.ATTACK_ADD
                                           } };
            inventory.Add(item1);

            Item item2 = new Item();

            item2.Id      = Guid.NewGuid();
            item2.Name    = "a";
            item2.Weight  = 10;
            item2.Count   = 1;
            item2.Effects = new Effect[] { new Effect()
                                           {
                                               Type = EFFECT_TYPE.ATTACK_ADD
                                           } };
            inventory.Add(item2);

            inventory.Remove("a", 2);

            var amount = inventory.GetItemAmount("a");

            Assert.AreEqual(0, amount);
        }
コード例 #12
0
ファイル: Intersection.cs プロジェクト: havok/ngenerics
        public void Simple()
        {
            var bag1 = new Bag<string>();
            var bag2 = GetTestBag();

            var resultBag = bag1 * bag2;

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag<string>();

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #13
0
ファイル: Add.cs プロジェクト: havok/ngenerics
        public void Simple()
        {
            var bag = new Bag<string>
                          {
                              "aa"
                          };

            Assert.AreEqual(bag.Count, 1);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 1);

            bag.Add("bb");
            Assert.AreEqual(bag.Count, 2);
            Assert.IsTrue(bag.Contains("bb"));
            Assert.AreEqual(bag["bb"], 1);

            bag.Add("aa");
            Assert.AreEqual(bag.Count, 3);
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 2);

            bag.Add("cc", 3);
            Assert.AreEqual(bag.Count, 6);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 3);

            bag.Add("cc", 2);

            Assert.AreEqual(bag.Count, 8);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["cc"], 5);
        }
コード例 #14
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestUnionInterface()
        {
            Bag <int> b1 = new Bag <int>();
            Bag <int> b2 = new Bag <int>();

            b1.Add(2, 2);
            b1.Add(3, 3);
            b1.Add(4, 5);

            b2.Add(3, 2);
            b2.Add(4, 3);
            b2.Add(5, 2);

            Bag <int> shouldBe = new Bag <int>();

            shouldBe.Add(2, 2);
            shouldBe.Add(3, 5);
            shouldBe.Add(4, 8);
            shouldBe.Add(5, 2);

            Bag <int> result = (Bag <int>)((IBag <int>)b1).Union(b2);

            Assert.AreEqual(shouldBe.IsEqual(result), true);

            result = (Bag <int>)((IBag <int>)b2).Union(b1);

            Assert.AreEqual(shouldBe.IsEqual(result), true);
        }
コード例 #15
0
ファイル: AboutGenerics.cs プロジェクト: alexbigkid/learning
        public void UsingSpecificInstanceOfGenericCollectionGivesYouTypeSafety()
        {
            Bag <string> myStrings = new Bag <string>();

            myStrings.Add("c#");

            // myStrings.Add(new Book()); //won't compile

            Assert.Fail("Comment me out, and un-comment the assert below and make it pass by writing a generic Contains method in the Bag class");
            //Assert.True(myStrings.Contains("c#"));

            var cat = new Cat {
                Name = "vega"
            };
            Bag <Animal> animals = new Bag <Animal>();

            animals.Add(cat);

            /* uncomment this below once you have written a Contains method */
            //Assert.True(animals.Contains(cat));

            Assert.Fail("Add a Remove method to Animal");
            animals.Add(cat); // adding it again

            /* uncomment the lines below once you've implemented the Remove method...*/
            //animals.Remove(cat); /*removing it once */

            //Assert.IsTrue(animals.Contains(cat));
            //animals.Remove(cat);

            //Assert.IsFalse(animals.Contains(cat));


            /* notice that the methods we've added to our Bag<T> have nothing to do with animals.  Now we can reuse them for any data type! */
        }
コード例 #16
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestIsEqual()
        {
            Bag <int> b1 = new Bag <int>();
            Bag <int> b2 = new Bag <int>();

            Assert.AreEqual(b1.IsEqual(b2), true);
            Assert.AreEqual(b2.IsEqual(b1), true);

            b2.Add(5);

            Assert.AreEqual(b1.IsEqual(b2), false);
            Assert.AreEqual(b2.IsEqual(b1), false);

            b1.Add(5);

            Assert.AreEqual(b1.IsEqual(b2), true);
            Assert.AreEqual(b2.IsEqual(b1), true);

            b2.Add(6);

            Assert.AreEqual(b1.IsEqual(b2), false);
            Assert.AreEqual(b2.IsEqual(b1), false);

            b1.Add(7);

            Assert.AreEqual(b1.IsEqual(b2), false);
            Assert.AreEqual(b2.IsEqual(b1), false);
        }
コード例 #17
0
ファイル: COOPGameScreen.cs プロジェクト: Bogdan0804/souless
        public void Init(ContentManager content)
        {
            GameManager.Game.Camera = new Camera2D(GameManager.Game.GraphicsDevice);
            GameManager.Game.Player = new Player.Player();
            GameManager.Game.Player.Init(content);
            fpsCounter = new FrameCounter();

            GameManager.Game.Camera.ZoomIn(1);

            ConnectToServer(ip);
            GameManager.Game.NetworkParser    = new NetworkParser(client);
            GameManager.Game.NetworkParser.IP = ip;
            player = new NetworkPlayer();

            GameManager.Game.Inventory = new UI.InventoryUI();
            GameManager.Game.Stats     = new UI.StatsOverlay();
            UI.Add(GameManager.Game.Stats);
            UI.Add(GameManager.Game.Inventory);

            playerHull = new Hull(new Vector2(12, 0), new Vector2(12, 55), new Vector2(14, 58), new Vector2(16, 59), new Vector2(20, 59), new Vector2(26, 56), new Vector2(37, 56), new Vector2(43, 59), new Vector2(47, 59), new Vector2(49, 58), new Vector2(51, 55), new Vector2(51, 0))
            {
                Scale  = new Vector2(1),
                Origin = new Vector2(32)
            };


            mouseLight = new PointLight();
            mouseLight.CastsShadows = true;
            mouseLight.ShadowType   = ShadowType.Solid;
            mouseLight.Scale        = new Vector2(100);
            mouseLight.Intensity    = 0.5f;
            GameManager.Game.Penumbra.Hulls.Add(playerHull);
            GameManager.Game.Penumbra.Lights.Add(mouseLight);
        }
コード例 #18
0
ファイル: Intersection.cs プロジェクト: krs43/ngenerics
        public void Interface()
        {
            var bag1 = new Bag <string>();
            var bag2 = GetTestBag();

            var resultBag = (Bag <string>)((IBag <string>)bag1).Intersection(bag2);

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag <string>();

            resultBag = (Bag <string>)((IBag <string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = (Bag <string>)((IBag <string>)bag1).Intersection(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #19
0
        public void CanRemoveAfterReopen()
        {
            var buffer = new byte[1024];
            var writer = new MemoryStream(buffer);
            var stack  = new Bag(new MemoryStream(buffer), writer, StartMode.Create);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);
            stack.Flush();

            stack = new Bag(new MemoryStream(buffer)
            {
                Position = stack.CurrentPosition.Value
            }, new MemoryStream(buffer)
            {
                Position = writer.Position
            }, StartMode.Open);

            stack.Remove(2);

            Assert.Contains(3, stack);
            Assert.DoesNotContain(2, stack);
            Assert.Contains(1, stack);
        }
コード例 #20
0
        public void Interface()
        {
            var bag1 = new Bag <int> {
                3, 4, 5, 6
            };

            var bag2 = new Bag <int> {
                3, 4, 5
            };

            var shouldBe = new Bag <int> {
                6
            };

            var resultBag = (Bag <int>)((IBag <int>)bag1).Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1.Subtract(bag2);

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
コード例 #21
0
ファイル: Intersection.cs プロジェクト: krs43/ngenerics
        public void Simple()
        {
            var bag1 = new Bag <string>();
            var bag2 = GetTestBag();

            var resultBag = bag1 * bag2;

            Assert.IsTrue(resultBag.Equals(bag1));

            bag1.Add("50", 2);

            var shouldBe = new Bag <string>();

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));

            bag1.Add("2", 2);

            shouldBe.Add("2", 2);

            resultBag = bag1 * bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #22
0
        public void Simple()
        {
            var bag = new Bag <string> {
                "aa"
            };

            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 1);

            bag.Add("bb");
            Assert.IsTrue(bag.Contains("bb"));
            Assert.AreEqual(bag["aa"], 1);
            Assert.AreEqual(bag["bb"], 1);

            bag.Add("aa");
            Assert.IsTrue(bag.Contains("aa"));
            Assert.AreEqual(bag["aa"], 2);
            Assert.AreEqual(bag["bb"], 1);

            bag.Add("cc", 3);
            Assert.IsTrue(bag.Contains("cc"));
            Assert.AreEqual(bag["aa"], 2);
            Assert.AreEqual(bag["bb"], 1);
            Assert.AreEqual(bag["cc"], 3);
        }
コード例 #23
0
        public void Simple()
        {
            var bag1 = new Bag <int>();
            var bag2 = new Bag <int>();

            bag1.Add(2, 2);
            bag1.Add(3, 3);
            bag1.Add(4, 5);

            bag2.Add(3, 2);
            bag2.Add(4, 3);
            bag2.Add(5, 2);
            bag2.Add(6, 2);

            var shouldBe = new Bag <int> {
                { 2, 2 }, { 3, 5 }, { 4, 8 }, { 5, 2 }, { 6, 2 }
            };

            var resultBag = bag1 + bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));

            resultBag = bag2 + bag1;

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: JakubSilny/PostBag
        static void Main(string[] args)
        {
            Bag bag = new Bag();

            bag.Add(new Letter("Alice", "Bob"));
            bag.Add(new Letter("Charles", "Diane", true));
            bag.Add(new Package("Ethan", "Flora", 10));
            bag.Add(new Package("Gwen", "Henry", 10, true));
            bag.Add(new Postcard("Igor", "Jonas"));
            bag.Add(new ValuableLetter("Kate", "Liam", 1000));
            bag.Add(new ValuableLetter("Martin", "Nathan", 1000, true));
            bag.Add(new ValuablePackage("Olivia", "Peter", 10, 1000));
            bag.Add(new ValuablePackage("Quinn", "Ronald", 10, 1000, true));
            bag.Add(new PostalOrder("Simon", 1000));

            Console.WriteLine("Zásilky");
            foreach (var item in bag.Deliveries)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Cennosti");
            foreach (var item in bag.Valuables)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }
コード例 #25
0
        public void CanPushSeveralItemsAndReadFromAnotherThenReadFromAnotherAgain()
        {
            var buffer = new byte[1024];
            var writer = new MemoryStream(buffer);
            var stack  = new Bag(new MemoryStream(buffer), writer, StartMode.Create);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);
            stack.Flush();

            stack = new Bag(new MemoryStream(buffer)
            {
                Position = stack.CurrentPosition.Value
            }, new MemoryStream(buffer)
            {
                Position = writer.Position
            }, StartMode.Open);

            Assert.Contains(3, stack);
            Assert.Contains(2, stack);

            stack.Flush();

            stack = new Bag(new MemoryStream(buffer)
            {
                Position = stack.CurrentPosition.Value
            }, new MemoryStream(buffer)
            {
                Position = writer.Position
            }, StartMode.Open);

            Assert.Contains(1, stack);
        }
コード例 #26
0
        public void Simple()
        {
            var bag1 = new Bag <int> {
                3, 4, 5, 6
            };

            var bag2 = new Bag <int> {
                3, 4, 5
            };

            var shouldBe = new Bag <int> {
                6
            };

            var resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));

            bag1.Clear();
            bag2.Clear();

            bag1.Add(3, 3);
            bag2.Add(3, 2);

            bag1.Add(5, 5);
            bag2.Add(5, 7);

            shouldBe.Clear();
            shouldBe.Add(3, 1);

            resultBag = bag1 - bag2;

            Assert.IsTrue(resultBag.Equals(shouldBe));
        }
コード例 #27
0
        public void TestInventoryGetSum6()
        {
            var  inventory = new Bag();
            Item item1     = new Item();

            item1.Id      = Guid.NewGuid();
            item1.Name    = "a";
            item1.Weight  = 10;
            item1.Count   = 10;
            item1.Effects = new Effect[] { };
            inventory.Add(item1);

            Item item2 = new Item();

            item2.Id      = Guid.NewGuid();
            item2.Name    = "a";
            item2.Weight  = 10;
            item2.Count   = 10;
            item2.Effects = new Effect[] {  };
            inventory.Add(item2);

            inventory.Remove("a", 15);

            var amount = inventory.GetItemAmount("a");

            Assert.AreEqual(5, amount);
        }
コード例 #28
0
        public void Remove()
        {
            Bag <string> bag1 = new Bag <string>(StringComparer.InvariantCultureIgnoreCase);
            bool         b;

            b = bag1.Remove("Eric"); Assert.IsFalse(b);
            bag1.Add("hello");
            bag1.Add("foo");
            bag1.Add(null);
            bag1.Add(null);
            bag1.Add("HELLO");
            bag1.Add("Hello");
            b = bag1.Remove("hello"); Assert.IsTrue(b);
            InterfaceTests.TestCollection(bag1, new string[] { null, null, "foo", "hello", "hello" }, false);
            b = bag1.Remove("Hello"); Assert.IsTrue(b);
            b = bag1.Remove(null); Assert.IsTrue(b);
            b = bag1.Remove(null); Assert.IsTrue(b);
            b = bag1.Remove(null); Assert.IsFalse(b);
            bag1.Add("Hello");
            bag1.Add("Eric");
            bag1.Add(null);
            b = bag1.Remove(null); Assert.IsTrue(b);
            bag1.Add("ERIC");
            b = bag1.Remove("eRic"); Assert.IsTrue(b);
            b = bag1.Remove("eRic"); Assert.IsTrue(b);
            bag1.Clear();
            b = bag1.Remove(""); Assert.IsFalse(b);
        }
コード例 #29
0
    public Bag <Edge> edges()
    {
        Bag <Edge> list = new Bag <Edge>();

        for (int v = 0; v < this.v; v++)
        {
            int selfLoops = 0;
            foreach (Edge e in Adj(v))
            {
                if (e.other(v) > v)
                {
                    list.Add(e);
                }
                // only add one copy of each self loop (self loops will be consecutive)
                else if (e.other(v) == v)
                {
                    if (selfLoops % 2 == 0)
                    {
                        list.Add(e);
                    }
                    selfLoops++;
                }
            }
        }
        return(list);
    }
コード例 #30
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestAdd()
        {
            Bag <string> b = new Bag <string>();

            b.Add("aa");
            Assert.AreEqual(b.Count, 1);
            Assert.AreEqual(b.Contains("aa"), true);
            Assert.AreEqual(b["aa"], 1);

            b.Add("bb");
            Assert.AreEqual(b.Count, 2);
            Assert.AreEqual(b.Contains("bb"), true);
            Assert.AreEqual(b["bb"], 1);

            b.Add("aa");
            Assert.AreEqual(b.Count, 3);
            Assert.AreEqual(b.Contains("aa"), true);
            Assert.AreEqual(b["aa"], 2);

            b.Add("cc", 3);
            Assert.AreEqual(b.Count, 6);
            Assert.AreEqual(b.Contains("cc"), true);
            Assert.AreEqual(b["cc"], 3);

            b.Add("cc", 2);

            Assert.AreEqual(b.Count, 8);
            Assert.AreEqual(b.Contains("cc"), true);
            Assert.AreEqual(b["cc"], 5);
        }
コード例 #31
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestRemoveAll()
        {
            Bag <string> b = new Bag <string>();

            b.Add("aa");
            b.Add("bb");
            b.Add("aa");
            b.Add("cc", 3);

            Assert.AreEqual(b.Count, 6);

            Assert.AreEqual(b.RemoveAll("aa"), true);
            Assert.AreEqual(b.Contains("aa"), false);
            Assert.AreEqual(b["aa"], 0);
            Assert.AreEqual(b.Count, 4);

            Assert.AreEqual(b.RemoveAll("dd"), false);
            Assert.AreEqual(b.Count, 4);


            Assert.AreEqual(b.RemoveAll("cc"), true);
            Assert.AreEqual(b.Contains("cc"), false);
            Assert.AreEqual(b["cc"], 0);
            Assert.AreEqual(b.Count, 1);
        }
コード例 #32
0
ファイル: BagTest.cs プロジェクト: jungs1330/ZProjects
        public void TestCopyTo()
        {
            Bag <int> b = new Bag <int>();

            b.Add(3);
            b.Add(4);
            b.Add(5);
            b.Add(6);

            int[] array = new int[50];

            b.CopyTo(array, 0);

            Assert.AreNotEqual(array[0], 0);
            Assert.AreNotEqual(array[1], 0);
            Assert.AreNotEqual(array[2], 0);
            Assert.AreNotEqual(array[3], 0);
            Assert.AreEqual(array[4], 0);

            List <int> l = new List <int>();

            l.Add(array[0]);
            l.Add(array[1]);
            l.Add(array[2]);
            l.Add(array[3]);

            Assert.AreEqual(l.Contains(3), true);
            Assert.AreEqual(l.Contains(4), true);
            Assert.AreEqual(l.Contains(5), true);
            Assert.AreEqual(l.Contains(6), true);
        }
コード例 #33
0
    static string Append(string name)
    {
        names.Add(name);

        data.Add(name);

        return("OK");
    }
コード例 #34
0
ファイル: BagTest.cs プロジェクト: jordibisbal/Bag
    public void testGetDifferentValue()
    {
        Bag <object> bag = new Bag <object>();

        bag.Add("Item", "ItemValue");
        bag.Add("Item 2", "ItemValue 2");
        Assert.AreEqual("ItemValue", bag.Get("Item"));
        Assert.AreEqual("ItemValue 2", bag.Get("Item 2"));
    }
コード例 #35
0
        public void CantCloneContents()
        {
            Bag <NotCloneable> bag1 = new Bag <NotCloneable>();

            bag1.Add(new NotCloneable());
            bag1.Add(new NotCloneable());

            Bag <NotCloneable> bag2 = bag1.CloneContents();
        }
コード例 #36
0
ファイル: BagExamples.cs プロジェクト: havok/ngenerics
        public void AddExample()
        {
            var bag = new Bag<string>();
            bag.Add("cat");
            bag.Add("dog");
            bag.Add("canary");

            // There should be 3 items in the bag.
            Assert.AreEqual(3, bag.Count);
        }
コード例 #37
0
ファイル: TestBag.cs プロジェクト: Kserol/artemis_csharp-odb
        public void TestAdd()
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            Bag<string> target = new Bag<string>(Capacity);
            // ReSharper restore UseObjectOrCollectionInitializer
            target.Add(TestElement1);
            target.Add(TestElement2);
            target.Add(TestElement3);

            Assert.IsTrue(target.Contains(TestElement1) && target.Contains(TestElement2) && target.Contains(TestElement3));
        }
コード例 #38
0
ファイル: BagTests.cs プロジェクト: markrendle/ravendb
		public void CanPushSeveralItems()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);
			stack.Add(2);
			stack.Add(3);

			Assert.Contains(3, stack);
			Assert.Contains(2, stack);
			Assert.Contains(1, stack);
		}
コード例 #39
0
ファイル: BagTests.cs プロジェクト: markrendle/ravendb
		public void CanRemove()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);
			stack.Add(2);
			stack.Add(3);
			stack.Remove(2);

			Assert.Contains(3, stack);
			Assert.DoesNotContain(2, stack);
			Assert.Contains(1, stack);
		}
コード例 #40
0
ファイル: BagExamples.cs プロジェクト: havok/ngenerics
        public void AddAmountExample()
        {
            var bag = new Bag<string>();
            bag.Add("cat");
            bag.Add("dog", 2);
            bag.Add("canary");

            // There are 4 items in the bag.
            Assert.AreEqual(4, bag.Count);

            // There are 2 "dog"s in the bag.
            Assert.AreEqual(2, bag["dog"]);
        }
コード例 #41
0
ファイル: BagTests.cs プロジェクト: jyunfan2015/forge
        public void Insert() {
            const int length = 30;

            // simple insert of 0 to 29
            {
                Bag<int> b = new Bag<int>();
                for (int i = 0; i < length; ++i) {
                    ((IList<int>)b).Insert(i, i);
                }

                for (int i = 0; i < length; ++i) {
                    Assert.Equal(i, b[i]);
                }
            }

            // more complex insert of 0 to 59
            {
                Bag<int> b = new Bag<int>();

                // insert even numbers
                for (int i = 0; i < length + 1; ++i) {
                    b.Add(i * 2);
                }

                // insert odd numbers
                for (int i = 0; i < length; ++i) {
                    ((IList<int>)b).Insert((i * 2) + 1, (i * 2) + 1);
                }

                // ensure it is equal
                for (int i = 0; i < length * 2; ++i) {
                    Assert.Equal(i, b[i]);
                }
            }
        }
コード例 #42
0
ファイル: BagTests.cs プロジェクト: markrendle/ravendb
		public void CanAddToStack()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(1);

			Assert.Equal(1, stack.First());
		}
コード例 #43
0
ファイル: Overloading.cs プロジェクト: etokrug/CSharpProjects
        private void Overloading_Shown(object sender, EventArgs e)
        {
            string lastName = "Lastname";
            int age = 21;
            float dollaz = 310.12F;
            long centz = 31012L;

            _myBag.Add(age);
            _myBag.Add(lastName);
            _myBag.Add(dollaz);
            _myBag.Add(centz);

            Bag _temporaryBag = new Bag();
            _temporaryBag.Add("Second Bag String");
            _temporaryBag.Add(100);

            _myBag += _temporaryBag;

            foreach (object contents in _myBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            Bag clonedBag;
            int itemsInClone = _myBag.Clone(out clonedBag);

            outputListBox.Items.Add("");
            foreach (object contents in clonedBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            outputListBox.Items.Add("Cloned count: " + itemsInClone);
            _myBag -= _temporaryBag;

            outputListBox.Items.Add("");
            outputListBox.Items.Add("Items in permanent bag after minus operator");
            foreach (object contents in _myBag.Items)
            {
                outputListBox.Items.Add(contents.ToString());
            }

            outputListBox.Items.Add("Count of items after minus operator: " + _myBag.Items.Count());
        }
コード例 #44
0
ファイル: Animation.cs プロジェクト: nikita-sky/SkidiKit
 public Animation(float delay, params string[] frameNames)
 {
     DelayPerUnit = delay;
     Loops = 1;
     Frames = new Bag<AnimationFrame>();
     foreach (var frameName in frameNames)
         Frames.Add(new AnimationFrame(SkidiGame.ResourceManager.GetFrame(frameName), 1f));
     Frames.Seal();
     TotalDelayUnits = Frames.Count;
 }
コード例 #45
0
ファイル: EdgeWeightedGraph.cs プロジェクト: qizl/Algorithms
 /// <summary>
 /// Returns all edges in this edge-weighted graph.
 /// </summary>
 /// <returns></returns>
 public Bag<Edge> Edges()
 {
     Bag<Edge> list = new Bag<Edge>();
     for (int v = 0; v < this._v; v++)
     {
         int selfLoops = 0;
         foreach (Edge e in this.Adj[v])
             if (e.Other(v) > v)
                 list.Add(e);
             else if (e.Other(v) == v)
             {
                 // only add one copy of each self loop (self loops will be consecutive)
                 if (selfLoops % 2 == 0)
                     list.Add(e);
                 selfLoops++;
             }
     }
     return list;
 }
コード例 #46
0
ファイル: Program.cs プロジェクト: bstaykov/Telerik-DSA
        /// <summary>
        /// Bag<T>
        /// A bag (multi-set) based on hash-table (WITH DUPLICATES) 
        /// Unordered collection
        /// Add / Find / Remove work in time O(1)
        /// T should provide Equals() and GetHashCode()
        /// </summary>
        private static void TestBag()
        {
            Bag<int> bagOfInts = new Bag<int>();
            bagOfInts.Add(1);
            bagOfInts.Add(1);
            bagOfInts.AddMany(new int[] { 1, 21 });
            bagOfInts.AddRepresentative(1);
            bagOfInts.ChangeNumberOfCopies(1, 3);
            Console.WriteLine("CountWhere > 2 : " + bagOfInts.CountWhere(x => x > 2));
            Console.WriteLine("Exists < 1 : " + bagOfInts.Exists(x => x < 1));
            Console.WriteLine("Copies of 1 : " + bagOfInts.NumberOfCopies(1));

            foreach (var item in bagOfInts)
            {
                Console.WriteLine(item);
            }

            Bag<Student> bagOfStudents = new Bag<Student>();
        }
コード例 #47
0
ファイル: IsEqual.cs プロジェクト: GTuritto/ngenerics
        public void Simple()
        {
            var bag1 = new Bag<int>();
            var bag2 = new Bag<int>();

            Assert.IsFalse(bag1.Equals(null));

            Assert.IsTrue(bag1.Equals(bag2));
            Assert.IsTrue(bag2.Equals(bag1));

            bag2.Add(5);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Add(5);

            Assert.IsTrue(bag1.Equals(bag2));
            Assert.IsTrue(bag2.Equals(bag1));

            // Add 6 now so that the count is the same
            bag1.Add(5);
            bag2.Add(6);
            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Remove(5, 1);
            bag2.Remove(6);

            Assert.IsTrue(bag1.Equals(bag2));
            Assert.IsTrue(bag2.Equals(bag1));

            bag2.Add(6);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));

            bag1.Add(7);

            Assert.IsFalse(bag1.Equals(bag2));
            Assert.IsFalse(bag2.Equals(bag1));
        }
コード例 #48
0
ファイル: Animation.cs プロジェクト: nikita-sky/SkidiKit
        public Animation(IEnumerable<TextureFrame> frames, float delay, uint loops = 1)
        {
            DelayPerUnit = delay;
            Loops = loops;

            Frames = new Bag<AnimationFrame>();
            foreach (var textureFrame in frames)
                Frames.Add(new AnimationFrame(textureFrame, 1f));
            Frames.Seal();
            TotalDelayUnits = Frames.Count;
        }
コード例 #49
0
 private static IDistribution<string> CreateModel(IFeatureExtractor<string, Tuple<string, int>> featureExtractor, string document)
 {
     var features = featureExtractor.GetFeatures(document);
     var bag = new Bag<string>();
     foreach (var feature in features)
     {
         bag.Add(feature.Item1, feature.Item2);
     }
     var distribution = new Distribution<string>(bag);
     return distribution;
 }
コード例 #50
0
ファイル: BagTest.cs プロジェクト: GTuritto/ngenerics
        internal static Bag<string> GetTestBag()
        {
            var bag = new Bag<string>();

            for (var i = 0; i < 20; i++)
            {
                bag.Add(i.ToString());
            }

            for (var i = 0; i < 10; i++)
            {
                bag.Add(i.ToString());
            }

            for (var i = 0; i < 5; i++)
            {
                bag.Add(i.ToString());
            }

            return bag;
        }
コード例 #51
0
ファイル: Count.cs プロジェクト: havok/ngenerics
        public void Simple()
        {
            var bag = GetTestBag();
            Assert.AreEqual(bag.Count, 35);
            Assert.IsFalse(bag.IsEmpty);

            bag = new Bag<string>();
            Assert.AreEqual(bag.Count, 0);
            Assert.IsTrue(bag.IsEmpty);

            bag.Add("aa");
            Assert.AreEqual(bag.Count, 1);
            Assert.IsFalse(bag.IsEmpty);

            bag.Add("aa");
            Assert.AreEqual(bag.Count, 2);
            Assert.IsFalse(bag.IsEmpty);

            bag.Add("bb");
            Assert.AreEqual(bag.Count, 3);
            Assert.IsFalse(bag.IsEmpty);
        }
コード例 #52
0
ファイル: BagTests.cs プロジェクト: markrendle/ravendb
		public void CanAddToStackAndReadFromAnother()
		{
			var buffer = new byte[1024];
			var stack = new Bag(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			stack.Add(2);
			stack.Flush();

			stack = new Bag(new MemoryStream(buffer)
			{
				Position = stack.CurrentPosition.Value
			}, new MemoryStream(buffer), StartMode.Open);
			Assert.Equal(2, stack.First());
		}
コード例 #53
0
ファイル: Union.cs プロジェクト: havok/ngenerics
        public void Interface()
        {
            var bag1 = new Bag<int>();
            var bag2 = new Bag<int>();

            bag1.Add(2, 2);
            bag1.Add(3, 3);
            bag1.Add(4, 5);

            bag2.Add(3, 2);
            bag2.Add(4, 3);
            bag2.Add(5, 2);

            var shouldBe = new Bag<int> { { 2, 2 }, { 3, 5 }, { 4, 8 }, { 5, 2 } };

            var resultBag = (Bag<int>)((IBag<int>)bag1).Union(bag2);

            Assert.IsTrue(shouldBe.Equals(resultBag));

            resultBag = (Bag<int>)((IBag<int>)bag2).Union(bag1);

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #54
0
 public void BagPerformanceTestA()
 {
     Bag<Int32> bigBag = new Bag<Int32>(16);
     var watch = System.Diagnostics.Stopwatch.StartNew();
     int x = 50;
     for (int i = 0; i <= 1000000; i++)
         // set it to a billion to get a OutOfMemoryException due to Bag Grow method generating too many items
     {
         bigBag.Add(i+x / 2 + 1);
         x++;
     }
     watch.Stop();
     System.Console.WriteLine(watch.Elapsed); // It is fast.
 }
コード例 #55
0
ファイル: Animation.cs プロジェクト: nikita-sky/SkidiKit
        public Animation(IEnumerable<AnimationFrame> frames, float delayPerUnit, uint loops)
        {
            DelayPerUnit = delayPerUnit;
            Loops = loops;

            Frames = new Bag<AnimationFrame>();
            TotalDelayUnits = 0;
            foreach (var animationFrame in frames)
            {
                Frames.Add(animationFrame);
                TotalDelayUnits += animationFrame.DelayUnits;
            }
            Frames.Seal();
        }
コード例 #56
0
ファイル: Union.cs プロジェクト: havok/ngenerics
        public void Simple()
        {
            var bag1 = new Bag<int>();
            var bag2 = new Bag<int>();

            bag1.Add(2, 2);
            bag1.Add(3, 3);
            bag1.Add(4, 5);

            bag2.Add(3, 2);
            bag2.Add(4, 3);
            bag2.Add(5, 2);
            bag2.Add(6, 2);

            var shouldBe = new Bag<int> { { 2, 2 }, { 3, 5 }, { 4, 8 }, { 5, 2 }, { 6, 2 } };

            var resultBag = bag1 + bag2;

            Assert.IsTrue(shouldBe.Equals(resultBag));

            resultBag = bag2 + bag1;

            Assert.IsTrue(shouldBe.Equals(resultBag));
        }
コード例 #57
0
ファイル: BagTests.cs プロジェクト: markrendle/ravendb
		public void CanRemoveAfterReopen()
		{
			var buffer = new byte[1024];
			var writer = new MemoryStream(buffer);
			var stack = new Bag(new MemoryStream(buffer), writer, StartMode.Create);
			stack.Add(1);
			stack.Add(2);
			stack.Add(3);
			stack.Flush();

			stack = new Bag(new MemoryStream(buffer)
			{
				Position = stack.CurrentPosition.Value
			}, new MemoryStream(buffer)
			{
				Position = writer.Position
			}, StartMode.Open);

			stack.Remove(2);

			Assert.Contains(3, stack);
			Assert.DoesNotContain(2, stack);
			Assert.Contains(1, stack);
		}
コード例 #58
0
ファイル: Json.cs プロジェクト: nikita-sky/SkidiKit
        public static Dictionary<string, BodySettings> Read(string input)
        {
            var result = new Dictionary<string, BodySettings>();

            var jsData = JsonObject.Parse(input);
            var jsBodies = jsData["rigidBodies"].GetArray();

            foreach (var body in jsBodies)
            {
                var jsBody = body.GetObject();

                var bodySetting = new BodySettings();
                {
                    var jsOrigin = jsBody["origin"].GetObject();
                    var x = (float)jsOrigin["x"].GetNumber();
                    var y = (float) jsOrigin["y"].GetNumber();
                    bodySetting.Origin = new cpVect(x, y);
                }

                result.Add(jsBody["name"].GetString(), bodySetting);

                var jsShapes = jsBody["shapes"].GetArray();
                var shapes = new Bag<cpVect[]>();
                foreach (var jsShape in jsShapes)
                {
                    var shape = jsShape.GetObject();
                    if (shape["type"].GetString() != "POLYGON")
                        continue;

                    var jsVertices = shape["vertices"].GetArray();
                    var vertices = new Bag<cpVect>();
                    foreach (var jsVertex in jsVertices)
                    {
                        var vertex = jsVertex.GetObject();
                        var x = (float)vertex["x"].GetNumber();
                        var y = (float) vertex["y"].GetNumber();

                        vertices.Add(new cpVect(x, y));
                    }

                    shapes.Add(vertices.ToArray());
                }

                bodySetting.Shapes = shapes.ToArray();
            }

            return result;
        }
コード例 #59
0
ファイル: Animate.cs プロジェクト: nikita-sky/SkidiKit
        public Animate(Animation animation)
            : base(animation.Duration*animation.Loops)
        {
            Animation = animation;
            SplitTimes = new Bag<float>(Animation.Frames.Count);

            var singleDuration = Animation.Duration;
            var accumUnits = 0f;
            var newUnitOfTime = singleDuration/Animation.TotalDelayUnits;

            foreach (var frame in Animation.Frames)
            {
                var value = (accumUnits*newUnitOfTime)/singleDuration;
                accumUnits += frame.DelayUnits;
                SplitTimes.Add(value);
            }
        }
コード例 #60
0
ファイル: BagTests.cs プロジェクト: jyunfan2015/forge
        public void RemoveAt() {
            const int length = 60;

            // add 0 through length and then remove from the front
            {
                Bag<int> b = new Bag<int>();
                for (int i = 0; i < length; ++i) {
                    b.Add(i);
                }

                ((IList<int>)b).RemoveAt(0);
                Assert.Equal(length - 1, b.Length);

                for (int i = 1; i < length; ++i) {
                    Assert.Equal(i, b[i - 1]);
                }
            }
        }