/[escript]/trunk/esys2/escript/test/DataConstant/DataConstantTestCase.cpp
ViewVC logotype

Diff of /trunk/esys2/escript/test/DataConstant/DataConstantTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 99 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC
# Line 28  using namespace esysUtils; Line 28  using namespace esysUtils;
28  void DataConstantTestCase::setUp() {  void DataConstantTestCase::setUp() {
29    //    //
30    // This is called before each test is run    // This is called before each test is run
31    
32  }  }
33    
34  void DataConstantTestCase::tearDown() {  void DataConstantTestCase::tearDown() {
35    //    //
36    // This is called after each test has been run    // This is called after each test has been run
37    
38  }  }
39    
40  void DataConstantTestCase::testAll() {  void DataConstantTestCase::testAll() {
# Line 44  void DataConstantTestCase::testAll() { Line 46  void DataConstantTestCase::testAll() {
46    DataArrayView::ShapeType shape;    DataArrayView::ShapeType shape;
47    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
48    DataArrayView pointData(data,shape);    DataArrayView pointData(data,shape);
49      DataArrayView::RegionType region;
50    
51    //    //
52    // assign an arbitrary value    // assign an arbitrary value
# Line 54  void DataConstantTestCase::testAll() { Line 57  void DataConstantTestCase::testAll() {
57    cout << "\tTesting default constructor." << endl;    cout << "\tTesting default constructor." << endl;
58    DataConstant testData(pointData, FunctionSpace());    DataConstant testData(pointData, FunctionSpace());
59    
   cout << "\tTest getLength." << endl;  
   assert(testData.getLength()==1);  
   
60    cout << "\tTest reshape." << endl;    cout << "\tTest reshape." << endl;
61    shape.push_back(2);    shape.push_back(2);
62    shape.push_back(3);    shape.push_back(3);
# Line 65  void DataConstantTestCase::testAll() { Line 65  void DataConstantTestCase::testAll() {
65    assert(testData.getPointDataView().getRank()==shape.size());    assert(testData.getPointDataView().getRank()==shape.size());
66    
67    cout << "\tTest getPointDataView." << endl;    cout << "\tTest getPointDataView." << endl;
68    for (int k=0;k<shape[2];k++) {    for (int k=0;k<shape[1];++k) {
69      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];++j) {
70        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];++i) {
71      assert(testData.getPointDataView()(i,j,k)==pointData());      assert(testData.getPointDataView()(i,j,k)==pointData());
72        }        }
73      }      }
# Line 83  void DataConstantTestCase::testAll() { Line 83  void DataConstantTestCase::testAll() {
83      assert(true);      assert(true);
84    }    }
85    
   cout << "\tVerify data point attributes." << endl;  
   DataArrayView dataView=testData.getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==126);  
   assert(dataView.getShape()[0]==2);  
   assert(dataView.getShape()[1]==3);  
   assert(dataView.getShape()[2]==21);  
   
86    cout << "\tTesting copy constructor." << endl;    cout << "\tTesting copy constructor." << endl;
87    DataConstant testData2(testData);    DataConstant testData2(testData);
88    
   for (int k=0;k<shape[2];k++) {  
     for (int j=0;j<shape[1];j++) {  
       for (int i=0;i<shape[0];i++) {  
     assert(testData2.getPointDataView()(i,j,k)==pointData());  
       }  
     }  
   }  
   
89    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
90    assert(testData2.getLength()==126);    assert(testData2.getLength() == 126);
   
   cout << "\tVerify data point attributes." << endl;  
   dataView=testData2.getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==126);  
   assert(dataView.getShape()[0]==2);  
   assert(dataView.getShape()[1]==3);  
   assert(dataView.getShape()[2]==21);  
   
   cout << "\tTest slicing (whole object)." << endl;  
   
   DataArrayView::RegionType region;  
   region.push_back(DataArrayView::RegionType::value_type(0,shape[0]));  
   region.push_back(DataArrayView::RegionType::value_type(0,shape[1]));  
   region.push_back(DataArrayView::RegionType::value_type(0,shape[2]));  
   
   DataAbstract* testData3=testData2.getSlice(region);  
   
   for (int k=0;k<shape[2];k++) {  
     for (int j=0;j<shape[1];j++) {  
       for (int i=0;i<shape[0];i++) {  
     assert(testData3->getPointDataView()(i,j,k)==pointData());  
       }  
     }  
   }  
   
   assert(testData3->getLength()==126);  
   
   cout << "\tVerify data point attributes." << endl;  
   dataView=testData3->getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==126);  
   assert(dataView.getShape()[0]==2);  
   assert(dataView.getShape()[1]==3);  
   assert(dataView.getShape()[2]==21);  
   
   cout << "\tTest slicing (part object)." << endl;  
   
   DataArrayView::RegionType region2;  
   region2.push_back(DataArrayView::RegionType::value_type(0,2));  
   region2.push_back(DataArrayView::RegionType::value_type(0,2));  
   region2.push_back(DataArrayView::RegionType::value_type(0,2));  
   
   DataAbstract* testData4=testData3->getSlice(region2);  
   
   for (int k=0;k<2;k++) {  
     for (int j=0;j<2;j++) {  
       for (int i=0;i<2;i++) {  
     assert(testData4->getPointDataView()(i,j,k)==pointData());  
       }  
     }  
   }  
   
   assert(testData4->getLength()==8);  
   
   cout << "\tVerify data point attributes." << endl;  
   dataView=testData4->getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==8);  
   assert(dataView.getShape()[0]==2);  
   assert(dataView.getShape()[1]==2);  
   assert(dataView.getShape()[2]==2);  
   
   cout << "\tTest slicing (part object)." << endl;  
   
   DataArrayView::RegionType region3;  
   region3.push_back(DataArrayView::RegionType::value_type(1,2));  
   region3.push_back(DataArrayView::RegionType::value_type(1,3));  
   region3.push_back(DataArrayView::RegionType::value_type(5,9));  
   
   DataAbstract* testData5=testData3->getSlice(region3);  
   
   for (int k=0;k<4;k++) {  
     for (int j=0;j<2;j++) {  
       for (int i=0;i<1;i++) {  
     assert(testData5->getPointDataView()(i,j,k)==pointData());  
       }  
     }  
   }  
   
   assert(testData5->getLength()==8);  
   
   cout << "\tVerify data point attributes." << endl;  
   dataView=testData5->getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==8);  
   assert(dataView.getShape()[0]==1);  
   assert(dataView.getShape()[1]==2);  
   assert(dataView.getShape()[2]==4);  
   
   cout << "\tTest slice setting (1)." << endl;  
   
   DataArrayView::RegionType region4;  
   region4.push_back(DataArrayView::RegionType::value_type(0,1));  
   region4.push_back(DataArrayView::RegionType::value_type(0,2));  
   region4.push_back(DataArrayView::RegionType::value_type(0,4));  
   
   DataAbstract* testData6=testData3->getSlice(region3);  
   
   testData5->setSlice(testData6,region4);  
   
   for (int k=0;k<4;k++) {  
     for (int j=0;j<2;j++) {  
       for (int i=0;i<1;i++) {  
     assert(testData5->getPointDataView()(i,j,k)==pointData());  
       }  
     }  
   }  
   
   assert(testData5->getLength()==8);  
   
   cout << "\tVerify data point attributes." << endl;  
   dataView=testData5->getPointDataView();  
   assert(dataView.getRank()==3);  
   assert(dataView.noValues()==8);  
   assert(dataView.getShape()[0]==1);  
   assert(dataView.getShape()[1]==2);  
   assert(dataView.getShape()[2]==4);  
   
   //cout << "\tTest slice setting (2)." << endl;  
   
   //DataArrayView::RegionType region5;  
   //region5.push_back(DataArrayView::RegionType::value_type(1,2));  
   //region5.push_back(DataArrayView::RegionType::value_type(1,3));  
   //region5.push_back(DataArrayView::RegionType::value_type(14,18));  
   
   //DataAbstract* testData7=testData3->getSlice(region);  
   
   //testData5->setSlice(testData7,region5);  
   
   //for (int k=0;k<4;k++) {  
   //  for (int j=0;j<2;j++) {  
   //    for (int i=0;i<1;i++) {  
   //      assert(testData5->getPointDataView()(i,j,k)==pointData());  
   //    }  
   //  }  
   // }  
   
   //assert(testData5->getLength()==8);  
   
   //cout << "\tVerify data point attributes." << endl;  
   //dataView=testData5->getPointDataView();  
   //assert(dataView.getRank()==3);  
   //assert(dataView.noValues()==8);  
   //assert(dataView.getShape()[0]==1);  
   //assert(dataView.getShape()[1]==2);  
   //assert(dataView.getShape()[2]==4);  
91    
92  }  }
93    

Legend:
Removed from v.99  
changed lines
  Added in v.100

  ViewVC Help
Powered by ViewVC 1.1.26