#include "Sundance.h"


int main(int argc, void** argv)
{
  try
    {
      PMachine::init(&argc, &argv);

      int nx = 10;
      int ny = 10;
      Mesh mesh = rectMesh(0.0, 1.0, nx, 0.0, 1.0, ny, false);

      Expr x = new CoordExpr(0, "x");
      Expr g = new DiscreteFunction(mesh, x, Lagrange(1), "g");
      Expr f = List(1.0, x, g);

      CellSet maxCells = new MaximalCellSet();
			
      ExprValue f0 = f.average(mesh, maxCells);
			
      cerr << f0 << endl;

      double errorNorm = fabs(f0[0].value() - 1.0) 
        + fabs(f0[1].value() - 0.5)
        + fabs(f0[2].value() - 0.5);
      double tolerance = 1.0e-14;

      Testing::passFailCheck(__FILE__, errorNorm, tolerance);
      Testing::timeStamp(__FILE__, __DATE__, __TIME__);
    }
  catch(exception& e)
    {
      e.print();
      Testing::crash(__FILE__);
      Testing::timeStamp(__FILE__, __DATE__, __TIME__);
    }

}

