소스 검색

add unit test

JasonWang 6 년 전
부모
커밋
816bc12ed8
4개의 변경된 파일133개의 추가작업 그리고 2개의 파일을 삭제
  1. 58 0
      data/crafting_test.txt
  2. 28 0
      tests/UnitTest/BlockStateTest.cs
  3. 4 2
      tests/UnitTest/CraftingRecipeTest.cs
  4. 43 0
      tests/UnitTest/PositionTest.cs

+ 58 - 0
data/crafting_test.txt

@@ -0,0 +1,58 @@
+# This file describes the crafting recipes that Minecase knows.
+# The syntax is as follows:
+#   <Line> = <Recipe>#<Comment>
+#   <Recipe> = <Result> = <Ingredient1> | <Ingredient2> | ... | <IngredientN>
+#   <IngredientN> = <ItemID>, <X1> : <Y1>, <X2> : <Y2>, ..., <Xn> : <Yn>
+#   <ItemID> = <ItemType> [^<DamageValue>]
+#   <Xn>, <Yn> = "1" .. "3", or "*" for any value. "*:*" can be replaced by a single "*".
+#   <Result> = <ItemType> [^<DamageValue>] [, <Count>]
+#
+# The Xn, Yn coordinates are a reference to the crafting grid:
+#   1:1 | 2:1 | 3:1
+#   1:2 | 2:2 | 3:2
+#   1:3 | 2:3 | 3:3
+#
+# <ItemType> can be either a number, or an item name (checked against items.ini)
+#
+# ^<DamageValue> is optional, if not present, the default damage for the given item is used
+#
+# If the DamageValue in the ingredients list is set to -1, the ingredient matches the specified item with any DamageValue.
+# This is used e. g. for "any planks -> sticks", or beds using any color wool etc.
+#
+# Ingredients with an asterisk for a coord will not match already matched crafting grid items. This enables simplifying some of the recipes,
+# e. g. hoe: "Iron, 2:1, *:1"
+#   -- this means "one iron at 2:1, and another one at either 1:1 or 3:1"
+#
+# To require multiple items of the same type in a slot, specify the slot number several times:
+# "Iron, 1:1, 2:2, 2:2"
+#   -- this means "take one iron from slot 1:1 and two irons from slot 2:2"
+# Note that asterisked items cannot require multiple items in a single slot.
+#
+# Note that due to technical problems, it is NOT advised to use asterisked ingredients in crossing directions, such as "*:1, "2:*".
+# The parser may be unable to match such a recipe to the crafting grid!
+#
+# Whitespace is optional. Use it reasonably. You CAN use any whitespaces (including tabs) in the middle of lines!
+
+
+
+
+
+#******************************************************#
+# Basic Crafts For Unit Test
+#
+
+# Need to list each of the four log types, otherwise all logs would get converted into apple planks (^0)
+
+WoodPlanks^Acacia, 4  = Wood2^Acacia, *
+WoodPlanks^Birch, 4   = Wood^Birch, *
+Chest				  = WoodPlanks^-1, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
+WoodPlanks^DarkOak, 4 = Wood2^DarkOak, *
+EnderChest			  = EyeofEnder,  2:2 | Obsidian, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
+Furnace				  = Cobblestone, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
+WoodPlanks^Jungle, 4  = Wood^Jungle, *
+WoodPlanks^Oak, 4	  = Wood^Oak, * 
+WoodPlanks^Spruce, 4  = Wood^Spruce, *
+Stick, 4			  = WoodPlanks^-1, 2:2, 2:3
+Torch, 4			  = Stick, 1:2 | Coal^-1, 1:1
+TrappedChest		  = TripwireHook, * | Chest, *
+CraftingTable		  = WoodPlanks^-1, 1:1, 1:2, 2:1, 2:2

+ 28 - 0
tests/UnitTest/BlockStateTest.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using MineCase.Block;
+using MineCase.Serialization;
+using MineCase.World;
+using Xunit;
+
+namespace MineCase.UnitTest
+{
+    public class BlockStateTest
+    {
+        [Fact]
+        public void IsSameIdTest()
+        {
+            BlockState state1 = BlockStates.Dirt();
+            BlockState state2 = BlockStates.Dirt();
+            BlockState state3 = BlockStates.Wood(WoodType.Birch);
+            BlockState state4 = BlockStates.Wood(WoodType.Oak);
+
+            Assert.True(state1 == state2);
+            Assert.False(state1 == state3);
+            Assert.False(state3.IsSameId(state2));
+            Assert.True(state3.IsSameId(state4));
+        }
+    }
+}

+ 4 - 2
tests/UnitTest/CraftingRecipeTest.cs

@@ -27,13 +27,15 @@ namespace MineCase.UnitTest
         public async Task TestCraftingRecipeLoader()
         {
             var loader = new CraftingRecipeLoader();
-            using (var sr = new StreamReader(File.OpenRead(Path.Combine(RootDir, "crafting.txt"))))
+            using (var sr = new StreamReader(File.OpenRead(Path.Combine(RootDir, "crafting_test.txt"))))
             {
                 await loader.LoadRecipes(sr);
             }
 
             var recipes = loader.Recipes;
-            Assert.Equal(38, recipes.Count);
+
+            // count test
+            Assert.Equal(13, recipes.Count);
         }
 
         [Fact]

+ 43 - 0
tests/UnitTest/PositionTest.cs

@@ -62,6 +62,49 @@ namespace MineCase.UnitTest
             Assert.Equal(_cwPos5, _bwPos5.ToChunkWorldPos());
         }
 
+        [Fact]
+        public void TestBlockWorldPosExtension()
+        {
+            Assert.Equal(_bwPos1.Up(), new BlockWorldPos(0, 1, 0));
+            Assert.Equal(_bwPos1.Down(), new BlockWorldPos(0, -1, 0));
+            Assert.Equal(_bwPos1.East(), new BlockWorldPos(1, 0, 0));
+            Assert.Equal(_bwPos1.West(), new BlockWorldPos(-1, 0, 0));
+            Assert.Equal(_bwPos1.North(), new BlockWorldPos(0, 0, -1));
+            Assert.Equal(_bwPos1.South(), new BlockWorldPos(0, 0, 1));
+
+            Assert.Equal(_bwPos1.Up(2), new BlockWorldPos(0, 2, 0));
+            Assert.Equal(_bwPos1.Down(2), new BlockWorldPos(0, -2, 0));
+            Assert.Equal(_bwPos1.East(2), new BlockWorldPos(2, 0, 0));
+            Assert.Equal(_bwPos1.West(2), new BlockWorldPos(-2, 0, 0));
+            Assert.Equal(_bwPos1.North(2), new BlockWorldPos(0, 0, -2));
+            Assert.Equal(_bwPos1.South(2), new BlockWorldPos(0, 0, 2));
+        }
+
+        [Fact]
+        public void TestBlockVector()
+        {
+            BlockVector bvPos1 = new BlockVector(0, 0, 0);
+            BlockVector bvPos2 = new BlockVector(1, 1, 1);
+            BlockVector bvPos3 = new BlockVector(-1, -1, -1);
+            BlockVector bvPos4 = new BlockVector(6, 7, 8);
+
+            Assert.Equal(0, bvPos1.X);
+            Assert.Equal(0, bvPos1.Y);
+            Assert.Equal(0, bvPos1.Z);
+
+            Assert.Equal(1, bvPos2.X);
+            Assert.Equal(1, bvPos2.Y);
+            Assert.Equal(1, bvPos2.Z);
+
+            Assert.Equal(-1, bvPos3.X);
+            Assert.Equal(-1, bvPos3.Y);
+            Assert.Equal(-1, bvPos3.Z);
+
+            Assert.Equal(6, bvPos4.X);
+            Assert.Equal(7, bvPos4.Y);
+            Assert.Equal(8, bvPos4.Z);
+        }
+
         [Fact]
         public void TestBlockChunkPos()
         {