BehaviorTreeFactoryTest.cs 1.3 KB

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