SyFi  0.3
compare_archives.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 using namespace std;
00004 
00005 #include <tools.h>
00006 #include <ginac_tools.h>
00007 using namespace GiNaC;
00008 using SyFi::initSyFi;
00009 using SyFi::compare_archives;
00010 
00011 
00012 int main(int argc, char **argv)
00013 {
00014   // symbols from symbol factory
00015         initSyFi(3);
00016         using SyFi::x;
00017         using SyFi::y;
00018         using SyFi::z;
00019         
00020         // some different symbols with same names
00021         ex xl = symbol("x");
00022         ex yl = symbol("y");
00023         ex zl = symbol("z");
00024         
00025         ex e1 = xl*xl + yl*yl*yl + sin(zl);
00026         ex e2 = x *x  + y *y *y  + sin(z );
00027         
00028         string exname1 = "testexpression1";
00029         string exname2 = "testexpression2";
00030         string exname3 = "testexpression3";
00031         
00032         archive a1;
00033         a1.archive_ex(e1,    exname1.c_str());
00034         a1.archive_ex(e1*e1, exname2.c_str());
00035         
00036         archive a2;
00037         a2.archive_ex(e2,    exname1.c_str());
00038         a2.archive_ex(e2*e2, exname2.c_str());
00039         
00040         string filename1 = "compare_archives1.gar";
00041         string filename2 = "compare_archives2.gar";
00042         
00043         ofstream ofile1(filename1.c_str());
00044         ofile1 << a1;
00045         ofile1.close();
00046         
00047         ofstream ofile2(filename2.c_str());
00048         ofile2 << a2;
00049         ofile2.close();
00050         
00051         bool success;
00052         success = compare_archives(filename1, filename2);
00053         if(!success)
00054         {
00055                 cout << "Failure!" << endl;
00056                 return -1;
00057         }
00058         
00059         // now test that we get failure when we should
00060         a1.archive_ex(e1,    exname3.c_str());
00061         a2.archive_ex(e2+1,  exname3.c_str());
00062         
00063         ofstream fofile1(filename1.c_str());
00064         fofile1 << a1;
00065         fofile1.close();
00066         
00067         ofstream fofile2(filename2.c_str());
00068         fofile2 << a2;
00069         fofile2.close();
00070         
00071         success = compare_archives(filename1, filename2);
00072         if(success)
00073         {
00074                 cout << "Failure! Different expressions compare as equal." << endl;
00075                 return -1;
00076         }
00077 
00078         return 0;
00079 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator