public static List <List <int> > DivideNodesIntoSubTrees( Dictionary <int, List <DstEdge> > _treeAdjMap, int _rootId, DivideRule _divideRule, out int[] _parentMap) { m_treeAdjMap = _treeAdjMap; // Reset to record wether a node has been divided into a subtree m_vis = new bool[m_treeAdjMap.Keys.Count]; m_divideRule = _divideRule; m_subtrees = new List <List <int> >(); m_nodesInDepth = new List <int> [m_treeAdjMap.Keys.Count]; m_childrenCount = new int[m_treeAdjMap.Keys.Count]; m_parentMap = new int[m_treeAdjMap.Keys.Count]; for (int i = 0; i < m_treeAdjMap.Keys.Count; ++i) { m_childrenCount[i] = -1; m_parentMap[i] = -1; m_vis[i] = false; } DfsNodeInfo(_rootId, _rootId, 0); DivideNodeFromBottom(); _parentMap = m_parentMap; return(m_subtrees); }
public void DivideNumbersReturnsSum() { var rule = new DivideRule(4, 5); var actual = rule.Apply(); JsonAssert.AreEquivalent(.8, actual); }
public static List <List <int> > DivideNodesIntoSubTrees( List <UndirectedEdge> _edges, int _rootId, DivideRule _divideRule, out int[] _parentMap) { m_treeAdjMap = ConvertUndirectedEdgesToAdjacencyMap(_edges); return(DivideNodesIntoSubTrees(m_treeAdjMap, _rootId, _divideRule, out _parentMap)); }
public void DivideByZeroThrowsError() { var rule = new DivideRule(4, 0); Assert.Throws <JsonLogicException>(() => rule.Apply()); }
public void DivideNonNumberThrowsError() { var rule = new DivideRule("test", 5); Assert.Throws <JsonLogicException>(() => rule.Apply()); }