public void DotReferencingUnitTest() { try { DotReferencing dotReferencing = new DotReferencing(new SymReferencing("led"), new SymReferencing("pinPower")); TypeChecker typeChecker = new TypeChecker(); AST.SymbolTable = new Dictionary <Tuple <string, string>, int>() { { new Tuple <string, string>("1", "led"), AST.STRUCT } }; typeChecker.StructDic.Add("led", new List <Tuple <string, int> >() { new Tuple <string, int>("pinPower", AST.INTTYPE) }); dotReferencing.accept(typeChecker); int actual = dotReferencing.type; int expected = AST.INTTYPE; Assert.IsTrue(actual == expected, "DotReferencing faild"); } finally { AST.SymbolTable.Clear(); } }
public void DotReferencingUnitTest() { try { AST.SymbolTable = new Dictionary <Tuple <string, string>, int>(); Dictionary <string, List <Tuple <string, int> > > structDic = new Dictionary <string, List <Tuple <string, int> > >() { { "led", new List <Tuple <string, int> >() { new Tuple <string, int>("pinPower", AST.INTTYPE), new Tuple <string, int>("Power", AST.VOID) } } }; InitiationChecker initiationChecker = new InitiationChecker(structDic); var assign = new Assigning(new DotReferencing(new SymReferencing("led"), new SymReferencing("pinPower")), new IntConst("50")); assign.accept(initiationChecker); DotReferencing dotReferencing = new DotReferencing(new SymReferencing("led"), new SymReferencing("pinPower")); dotReferencing.accept(initiationChecker); Dictionary <Tuple <string, string>, int> actualSym = initiationChecker.getInitiationTable; Dictionary <string, List <Tuple <string, int> > > actualStruct = initiationChecker.getStructDic; Dictionary <Tuple <string, string>, int> expectedSym = new Dictionary <Tuple <string, string>, int>(); Dictionary <string, List <Tuple <string, int> > > expectedStruct = new Dictionary <string, List <Tuple <string, int> > >() { { "led", new List <Tuple <string, int> >() { new Tuple <string, int>("Power", 0), new Tuple <string, int>("pinPower", 1) } } }; Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "DotReferencing faild"); } finally { AST.SymbolTable.Clear(); } }