public void TestConnectTheNodeToOtherNode_Test2_RootTest() { //K //| //A B //|\ \ //C D E // / \ / \ // F G H I // \/ // J SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >(); AddNodeWholeTreeTestHelper(ref tree); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEB", tree, "after initialization"); Assert.AreEqual(2, tree.GetRoots().Count, "there should be 2 roots"); tree.AddNode(L); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBL", tree, "after L adding"); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); tree.AddNode(M); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBLM", tree, "after M adding"); Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots"); tree.ConnectTheNodeToOtherNode(L, 0, M, 0); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBML", tree, "after connecting L and M"); tree.AddNode(N); Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots"); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBMLN", tree, "after N adding"); tree.ConnectTheNodeToOtherNode(J, 0, L, 0); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); AreEqualGetFroeachRepresentationHelper("CFMLJGDAKHIEBN", tree, "after connecting J and L"); }
public void TestConnectTheNodeToOtherNode_Test2_RootTest3() { //K L //|/ //A //| //C SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >(); tree.AddNode(C); tree.AddNode(K); tree.AddNode(L); tree.AddNode(A); tree.ConnectTheNodeToOtherNode(A, 0, C, 0); tree.ConnectTheNodeToOtherNode(L, 0, A, 0); tree.ConnectTheNodeToOtherNode(K, 0, A, 1); AreEqualGetFroeachRepresentationHelper("CAKL", tree, "after all (after splitter adding)"); }
public void TestConnectTheNodeToOtherNode_Test2_RootTest2() { //K //| //A B //|\ \ //C D E // / \ / \ // F G H I // \/ // J SortedTree <ClassAsTreeValue <string> > tree = new SortedTree <ClassAsTreeValue <string> >(); AddNodeWholeTreeTestHelper(ref tree); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEB", tree, "after initialization"); Assert.AreEqual(2, tree.GetRoots().Count, "there should be 2 roots"); tree.AddNode(L); AreEqualGetFroeachRepresentationHelper("CFJGDAKHIEBL", tree, "after L adding"); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); tree.RemoveConnectionBetweeenParentAndChildAndMoveElementToRoots(K, A); Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots"); tree.AddNode(M); Assert.AreEqual(5, tree.GetRoots().Count, "there should be 5 roots"); //do tego dazymy: //K M //|/ //L (to jest splitter) //| //A B //|\ \ //C D E // / \ / \ // F G H I // \/ // J tree.ConnectTheNodeToOtherNode(L, 0, A, 0); Assert.AreEqual(4, tree.GetRoots().Count, "there should be 4 roots"); tree.ConnectTheNodeToOtherNode(M, 0, L, 1); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); tree.ConnectTheNodeToOtherNode(K, 0, L, 0); Assert.AreEqual(3, tree.GetRoots().Count, "there should be 3 roots"); AreEqualGetFroeachRepresentationHelper("CFJGDALKHIEBM", tree, "after all (after splitter adding)"); }
/// <summary> /// Initializes a new instance of the <see cref="OPCClientTransaction"/> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="ParentDataQueue">The parent data queue.</param> internal OPCClientTransaction( OPCCliConfiguration.TransactionsRow configuration, OPCDataQueue ParentDataQueue ) : base( ParentDataQueue, new TimeSpan( 0, 0, 0, 0, configuration.TransactionRate == 0 ? 1 : configuration.TransactionRate ) ) { bool canBeAdded = true; if ( !configuration.IsBadQualityValueNull() ) m_BadQualityValue = configuration.BadQualityValue; m_StopIfBadQuality = configuration.StopIfBadQuality; OPCCliConfiguration.OperationsRow[] operations = configuration.GetOperationsRows(); // stworzymy tablice operacji do wykonania; SortedList<long, Operation> operationList = new SortedList<long, Operation>( configuration.GetOperationsRows().Length ); SortedList<long, OPCCliConfiguration.OperationsRow> operationRowList = new SortedList<long, OPCCliConfiguration.OperationsRow>( configuration.GetOperationsRows().Length ); SortedTree<Operation> myOperationTree = new SortedTree<Operation>(); try { //najpierw dodajemy wszystkie operacje foreach ( OPCCliConfiguration.OperationsRow row in configuration.GetOperationsRows() ) { try { Operation operrowOperation = OperationFactory.GetOperation( row, m_StopIfBadQuality, m_BadQualityValue ); operationRowList.Add( (long)operrowOperation.Statistics.Identifier, row ); operationList.Add( (long)operrowOperation.Statistics.Identifier, operrowOperation ); myOperationTree.AddNode( operrowOperation ); //najpiewr dodajemy wszystykie jako rooty } catch ( Exception ex ) { Exception newExcetion = new Exception( String.Format( Resources.tx_OPCDataQueue_Operation_CannotBeAdded, row.Name ), ex ); throw newExcetion; } } //teraz dodajemy wszystkie linki: foreach ( Operation node in myOperationTree ) foreach ( OPCCliConfiguration.OperationLinksRow OpLinksRow in operationRowList[ node.Statistics.Identifier ].GetOperationLinksRowsByFK_OPERATION_OperationLinks() ) { myOperationTree.ConnectTheNodeToOtherNode( operationList[ OpLinksRow.ID_Operation ], OpLinksRow.Input_number, operationList[ OpLinksRow.IDChild_Operation ], OpLinksRow.ChildOutput_number ); } } catch ( Exception ex ) { Main.MainComponent.SystemExceptionHandler( ex, 158, this.ToString() ); canBeAdded = false; } if ( canBeAdded ) { m_Transaction = new Transaction( configuration, myOperationTree ); m_AllTransactions.Add( this ); } else { Main.MainComponent.Tracer.TraceWarning( 194, this.GetType().ToString(), String.Format( Resources.tx_OPCDataQueue_Transaction_CannotBeAdded, configuration.Name ) ); } }
/// <summary> /// Helper that create the example tree. /// </summary> /// <param name="tree">The tree.</param> private void AddNodeWholeTreeTestHelper(ref SortedTree <ClassAsTreeValue <string> > tree) { //K //| //A B //|\ \ //C D E // / \ / \ // F G H I // \/ // J SortedTree <ClassAsTreeValue <string> > .SortedTreeNode node; SortedTree <ClassAsTreeValue <string> > .SortedTreeNode parentnode; SortedTree <ClassAsTreeValue <string> > .SortedTreeNode parentnode2; node = tree.AddNode(K); Assert.AreEqual(node.Value, K, "Element that is added must be equal to oryginal element"); Assert.AreEqual(0, node.ParentNodesCount, "Parrent Node for root element must be null"); parentnode = node; node = tree.AddNode(K, 0, A, 0); Assert.AreEqual(node.Value, A, "Element that is added must be equal to original element"); Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(K)), parentnode, "Parent Node for A element must be K"); parentnode = node; node = tree.AddNode(A, 0, C, 0); Assert.AreEqual(node.Value, C, "Element that is added must be equal to original element"); Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(A)), parentnode, "Parent Node for C element must be A"); node = tree.AddNode(A, 1, D, 0); Assert.AreEqual(node.Value, D, "Element that is added must be equal to original element"); Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(A)), parentnode, "Parent Node for D element must be A"); parentnode2 = node; //D is saved here parentnode = null; node = tree.AddNode(null, 0, B, 0); Assert.AreEqual(B, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(0, node.ParentNodesCount, "Parent Node for root element must be null"); parentnode = node; node = tree.AddNode(B, 0, E, 0); Assert.AreEqual(node.Value, E, "Element that is added must be equal to original element"); Assert.AreEqual(node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(B)), parentnode, "Parent Node for E element must be B"); parentnode = node;// save E; node = tree.AddNode(D, 0, F, 0); Assert.AreEqual(F, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(D)), "Parent Node for F element must be D"); node = tree.AddNode(D, 1, G, 1); Assert.AreEqual(G, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(D)), "Parent Node for G element must be D"); parentnode2 = node; //save G node = tree.AddNode(E, 1, I, 0); Assert.AreEqual(I, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(E)), "Parent Node for I element must be E"); node = tree.AddNode(E, 0, H, 0); Assert.AreEqual(H, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(E)), "Parent Node for H element must be E"); parentnode = node;//save H node = tree.AddNode(G, 0, J, 0); Assert.AreEqual(J, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode2, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(G)), "Parent Node for J element must be G"); node = tree.AddNode(H, 0, J, 1); Assert.AreEqual(J, node.Value, "Element that is added must be equal to original element"); Assert.AreEqual(parentnode, node.GetParentNodeByParentNodeNumber(node.GetParentConnectorNumber(H)), "Parent Node for J element must be H"); }
/// <summary> ///A test for AddNode ///</summary> public void AddNodeTestHelper(ref SortedTree <ClassAsTreeValue <string> > tree) { SortedTree <ClassAsTreeValue <string> > .SortedTreeNode node = tree.AddNode(A); Assert.AreEqual(node.Value, A, "values should be equal"); }