public void DFSearchRecursiveWorksCorrectly() { //Arrange var tree = new Tree <int>(); int count = 0; for (int i = 0; i < 10; i++) { var node = new Tree <int> .TreeNode(count); count++; tree.Add(node); for (int j = 0; j < 10; j++) { var child = new Tree <int> .TreeNode(count); count++; tree.Add(child, node); for (int k = 0; k < 10; k++) { var newChild = new Tree <int> .TreeNode(count); count++; tree.Add(newChild, child); for (int f = 0; f < 20; f++) { var lastChild = new Tree <int> .TreeNode(count); count++; tree.Add(lastChild, newChild); } } } } //Act var search = new DFSearch <int>(); var actual = search.DFSearchRecursive(tree.Root); var expected = new List <int>(); foreach (var item in tree) { expected.Add(item); } //Assert CollectionAssert.AreEquivalent(expected, actual); }
private void buttonValidate_Click(object sender, EventArgs e) { var dfsearch = new DFSearch <string>(state => LoadedAsset.GetDialogueActionsByState(state).Select(dto => dto.NextState)); dfsearch.InitializeSearch(IATConsts.INITIAL_DIALOGUE_STATE); dfsearch.FullSearch(); int unreachableStatesCount = 0; int totalStates = 0; string unreachableStatesDescription = "The following Dialogue States are not reachable: \n["; foreach (var dAction in LoadedAsset.GetAllDialogueActions().GroupBy(da => da.CurrentState) .Select(group => group.First())) { totalStates++; if (dfsearch.Closed.SearchInClosed(new NodeRecord <string>() { node = dAction.CurrentState.ToString() }) == null) { unreachableStatesCount++; unreachableStatesDescription += dAction.CurrentState + ", "; } } unreachableStatesDescription = unreachableStatesDescription.Remove(unreachableStatesDescription.Length - 2); unreachableStatesDescription += "]"; string validationMessage; if (unreachableStatesCount > 0) { validationMessage = "Reachability: " + (totalStates - unreachableStatesCount) * 100 / totalStates + "%\n" + unreachableStatesDescription; } else { validationMessage = "All Dialogue States are reachable!"; } //get the dead ends validationMessage += "\n\nEnd States:\n[" + string.Join(",", dfsearch.End.ToArray()) + "]"; MessageBox.Show(validationMessage); }