Ejemplo n.º 1
0
        public void TestSplit()
        {
            ItemStack stack1 = new ItemStack(ItemRegistry.ItemRadioactive, 13);
            ItemStack stack2 = stack1.Split(14);

            Assert.AreEqual(0, stack1.stackSize);
            Assert.AreEqual(13, stack2.stackSize);

            stack1 = new ItemStack(ItemRegistry.ItemRadioactive, 13);
            stack2 = stack1.Split(0);
            Assert.IsNull(stack2);

            stack1 = new ItemStack(ItemRegistry.ItemRadioactive, 13);
            ItemInfoTree tree = stack1.infoTree;

            stack2 = stack1.Split(5);

            Assert.AreEqual(tree, stack1.infoTree);
            Assert.AreEqual(8, stack1.stackSize);
            Assert.AreEqual(5, stack2.stackSize);
            Assert.IsTrue(stack1.mergeable(stack2));

            stack2.Update(0.4f);
            Assert.IsFalse(stack1.mergeable(stack2));
        }
Ejemplo n.º 2
0
        public void TestBasic()
        {
            ItemInfoTree tree    = new ItemInfoTree();
            ItemInfoTree subtree = new ItemInfoTree();

            subtree.WriteDouble("DOUBLE", 2.0);

            tree.WriteInt("INT", 1);
            tree.WriteDouble("DOUBLE", 1.0);
            tree.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree.WriteString("STRING", "XX");
            tree.WriteTree("TREE", subtree);

            StringBuilder builder = new StringBuilder();

            XmlWriter writer = XmlWriter.Create(builder);

            tree.WriteXml(writer);

            System.IO.StringReader stream = new System.IO.StringReader(builder.ToString());
            XmlReader reader = XmlReader.Create(stream);

            ItemInfoTree tree2 = new ItemInfoTree();

            tree2.ReadXml(reader);

            Assert.AreEqual(tree, tree2);
        }
Ejemplo n.º 3
0
        public void TestReadWriteTree()
        {
            ItemInfoTree tree = new ItemInfoTree();

            tree.WriteInt("INT", 1);
            ItemInfoTree subtree = new ItemInfoTree();

            subtree.WriteInt("INT", 2);

            ItemInfoTree subtreecopy = new ItemInfoTree();

            subtreecopy.WriteInt("INT", 2);

            tree.WriteTree("TREE", subtree);

            Assert.AreEqual(tree.ReadTree("TREE"), subtreecopy);
        }
Ejemplo n.º 4
0
        public void TestClone()
        {
            ItemInfoTree tree    = new ItemInfoTree();
            ItemInfoTree subtree = new ItemInfoTree();

            subtree.WriteDouble("DOUBLE", 2.0);

            tree.WriteInt("INT", 1);
            tree.WriteDouble("DOUBLE", 1.0);
            tree.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree.WriteString("STRING", "XX");
            tree.WriteTree("TREE", subtree);

            ItemInfoTree tree2 = new ItemInfoTree(tree);

            Assert.IsTrue(tree.Equals(tree2));
            Assert.AreNotSame(tree.ReadIntArray("INTARRAY"), tree2.ReadIntArray("INTARRAY"));
            Assert.AreNotSame(tree.ReadTree("TREE"), tree2.ReadTree("TREE"));
        }
Ejemplo n.º 5
0
        public void TestReadWrite()
        {
            ItemInfoTree tree = new ItemInfoTree();

            tree.WriteString("key", "value");
            Assert.AreEqual(tree.ReadString("key"), "value");

            tree.WriteInt("key", 5);
            Assert.AreEqual(tree.ReadInt("key"), 5);

            tree.WriteDouble("key", 1.0);
            Assert.AreEqual(tree.ReadDouble("key"), 1.0);

            tree.WriteIntArray("key", new int[] { 1, 2, 3 });
            Assert.AreEqual(tree.ReadIntArray("key"), new int[] { 1, 2, 3 });

            Assert.IsNull(tree.ReadString("not key")); // not really a key!
            Assert.IsNull(tree.ReadString("key"));     // wrong type!
        }
Ejemplo n.º 6
0
        public void TestTreeEqual()
        {
            // tree 1
            ItemInfoTree tree    = new ItemInfoTree();
            ItemInfoTree subtree = new ItemInfoTree();

            subtree.WriteDouble("DOUBLE", 2.0);

            tree.WriteInt("INT", 1);
            tree.WriteDouble("DOUBLE", 1.0);
            tree.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree.WriteString("STRING", "XX");
            tree.WriteTree("TREE", subtree);

            // tree 2
            ItemInfoTree tree2    = new ItemInfoTree();
            ItemInfoTree subtree2 = new ItemInfoTree();

            subtree2.WriteDouble("DOUBLE", 2.0);

            tree2.WriteInt("INT", 1);
            tree2.WriteDouble("DOUBLE", 1.0);
            tree2.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree2.WriteString("STRING", "XX");
            tree2.WriteTree("TREE", subtree2);

            Assert.IsTrue(tree.Equals(tree2));

            tree2.WriteIntArray("INTARRAY", new int[] { 1, 2, 2 });
            Assert.IsFalse(tree.Equals(tree2));

            tree2.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            Assert.IsTrue(tree.Equals(tree2));

            subtree2.WriteInt("stuff", 2);
            Assert.IsFalse(tree.Equals(tree2));
        }
Ejemplo n.º 7
0
        public void TestMergeable()
        {
            ItemInfoTree tree    = new ItemInfoTree();
            ItemInfoTree subtree = new ItemInfoTree();

            subtree.WriteDouble("DOUBLE", 2.0);

            tree.WriteInt("INT", 1);
            tree.WriteDouble("DOUBLE", 1.0);
            tree.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree.WriteString("STRING", "XX");
            tree.WriteTree("TREE", subtree);

            // tree 2
            ItemInfoTree tree2    = new ItemInfoTree();
            ItemInfoTree subtree2 = new ItemInfoTree();

            subtree2.WriteDouble("DOUBLE", 2.0);

            tree2.WriteInt("INT", 1);
            tree2.WriteDouble("DOUBLE", 1.0);
            tree2.WriteIntArray("INTARRAY", new int[] { 1, 2, 3 });
            tree2.WriteString("STRING", "XX");
            tree2.WriteTree("TREE", subtree2);

            ItemStack stack1 = new ItemStack(ItemRegistry.ItemRadioactive, 13);
            ItemStack stack2 = new ItemStack(ItemRegistry.ItemRadioactive, 1);
            ItemStack stack3 = new ItemStack(ItemRegistry.ItemRadioactive, 1);
            ItemStack stack4 = new ItemStack(ItemRegistry.ItemDebug, 1);

            stack3.Update(0.3f);
            Assert.IsTrue(stack1.mergeable(stack2));
            Assert.IsTrue(stack2.mergeable(stack1));
            Assert.IsFalse(stack1.mergeable(stack3));
            Assert.IsFalse(stack4.mergeable(stack1));
        }