CraftingRecipeTest.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using MineCase.Algorithm;
  9. using MineCase.Block;
  10. using Xunit;
  11. namespace MineCase.UnitTest
  12. {
  13. public class CraftingRecipeTest
  14. {
  15. public readonly string RootDir;
  16. public CraftingRecipeTest()
  17. {
  18. RootDir = SetRootDir();
  19. }
  20. private static string SetRootDir([CallerFilePath]string fileName = null) =>
  21. Path.Combine(Path.GetDirectoryName(fileName), @"../../data");
  22. [Fact]
  23. public Task TestCraftingRecipeLoader()
  24. {
  25. // Wait for api update
  26. /*
  27. var loader = new CraftingRecipeLoader();
  28. using (var sr = new StreamReader(File.OpenRead(Path.Combine(RootDir, "crafting_test.txt"))))
  29. {
  30. await loader.LoadRecipes(sr);
  31. }
  32. var recipes = loader.Recipes;
  33. // count test
  34. Assert.Equal(13, recipes.Count);
  35. */
  36. return Task.CompletedTask;
  37. }
  38. [Fact]
  39. public Task TestCraftingRecipeMatcher()
  40. {
  41. // Wait for api update
  42. /*
  43. var loader = new CraftingRecipeLoader();
  44. using (var sr = new StreamReader(File.OpenRead(Path.Combine(RootDir, "crafting.txt"))))
  45. {
  46. await loader.LoadRecipes(sr);
  47. }
  48. var matcher = new CraftingRecipeMatcher(loader.Recipes);
  49. var recipe = matcher.FindRecipe(new Slot[,]
  50. {
  51. { Slot.Empty, Slot.Empty, Slot.Empty },
  52. { new Slot { BlockId = (short)BlockStates.Wood().Id, ItemCount = 1 }, Slot.Empty, Slot.Empty },
  53. { Slot.Empty, Slot.Empty, Slot.Empty },
  54. });
  55. Assert.NotNull(recipe);
  56. Assert.Equal((short)BlockStates.WoodPlanks().Id, recipe.Result.BlockId);
  57. Assert.True(recipe.AfterTake.Cast<Slot>().All(o => o.IsEmpty));
  58. */
  59. return Task.CompletedTask;
  60. }
  61. }
  62. }