BehaviorTreeFactoryTest.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using BehaviorTree;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. namespace BehaviorTreeTest
  5. {
  6. [TestClass]
  7. public class BehaviorTreeFactoryTest
  8. {
  9. [TestMethod]
  10. public void TestCreateTree()
  11. {
  12. var config = new Config
  13. {
  14. Name = "selector",
  15. Id = 1,
  16. Args = new List<string> { "11" },
  17. SubConfigs =
  18. new List<Config>
  19. {
  20. new Config
  21. {
  22. Name = "sequence",
  23. Id = 2,
  24. Args = new List<string> { "12" },
  25. SubConfigs =
  26. new List<Config>
  27. {
  28. new Config
  29. {
  30. Name = "selector",
  31. Id = 4,
  32. Args = new List<string> { "14" },
  33. },
  34. new Config
  35. {
  36. Name = "selector",
  37. Id = 5,
  38. Args = new List<string> { "15", "17" },
  39. }
  40. }
  41. },
  42. new Config
  43. {
  44. Name = "not",
  45. Id = 3,
  46. Args = new List<string> { "13" },
  47. SubConfigs =
  48. new List<Config>
  49. {
  50. new Config
  51. {
  52. Name = "selector",
  53. Id = 6,
  54. Args = new List<string> { "16" },
  55. }
  56. }
  57. }
  58. }
  59. };
  60. var behaviorTreeFactory = new BehaviorTreeFactory();
  61. BehaviorTree.BehaviorTree behaviorTree = behaviorTreeFactory.CreateTree(config);
  62. var blackBoard = new BlackBoard();
  63. Assert.IsTrue(behaviorTree.Run(blackBoard));
  64. }
  65. }
  66. }