Example #1
0
TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, resizeTest){
  TwoDArray<int> simpleArray = getSimpleTestTwoDArray();

  simpleArray.resizeRows(4);
  TEST_EQUALITY_CONST(simpleArray.getNumRows(), 4);
  TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2);
  TEST_EQUALITY_CONST(simpleArray(3,1), 0);
  TEST_EQUALITY_CONST(simpleArray(1,1), 4);

  simpleArray.resizeRows(2);
  TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2);
  TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2);
#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
  TEST_THROW(simpleArray(3,1), RangeError);
#endif
  TEST_EQUALITY_CONST(simpleArray(1,1), 4);

  simpleArray.resizeCols(4);
  TEST_EQUALITY_CONST(simpleArray.getNumCols(), 4);
  TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2);
  TEST_EQUALITY_CONST(simpleArray(1,3), 0);
  TEST_EQUALITY_CONST(simpleArray(1,1), 4);

  simpleArray.resizeCols(2);
  TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2);
  TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2);
#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
  TEST_THROW(simpleArray(1,3), RangeError);
#endif
  TEST_EQUALITY_CONST(simpleArray(1,1), 4);

}
Example #2
0
TEST(TwoDArrayRow, NumRow) {
    TwoDArray<int>* tDInt = new TwoDArray<int>(10, 10, 0);
    TwoDArray<double>* tDDouble = new TwoDArray<double>(11, 11, 0.0);
    TwoDArray<string>* tDString = new TwoDArray<string>(12, 12, "0");

    EXPECT_EQ(10, tDInt->getNumRows());
    delete tDInt;
    EXPECT_EQ(11, tDDouble->getNumRows());
    delete tDDouble;
    EXPECT_EQ(12, tDString->getNumRows());
    delete tDString;
}
Example #3
0
TEST(TwoDArray, GetNumRows) {
	TwoDArray<int>* newArray = new TwoDArray<int>(7,8,0);
	EXPECT_EQ(8, newArray->getNumRows());
	delete newArray;

	TwoDArray<double>* newDouble = new TwoDArray<double>(80,80,0.0);
	EXPECT_EQ(80, newDouble->getNumRows());
	delete newDouble;

	TwoDArray<std::string>* newString = new TwoDArray<std::string>(49,78,"hi");
	EXPECT_EQ(78, newString->getNumRows());
	delete newString;
}
Example #4
0
TEST(numRows, stringTest) {
    int r = 10;
    int c = 5;
    TwoDArray<string>* a = new TwoDArray<string>(r, c);
    EXPECT_EQ(10, a->getNumRows());
    delete a;
}
Example #5
0
TEST(numRows, doubleTest) {
    int r = 10;
    int c = 5;
    TwoDArray<double>* a = new TwoDArray<double>(r, c);
    EXPECT_EQ(10, a->getNumRows());
    delete a;
}
Example #6
0
TEST(numRows, integerTest) {
    int r = 10;
    int c = 5;
    TwoDArray<int>* a = new TwoDArray<int>(r, c);
    EXPECT_EQ(10, a->getNumRows());
    delete a;
}
Example #7
0
TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, emptyTest){
  TwoDArray<int> emptyArray;
  TEST_EQUALITY_CONST(emptyArray.getNumRows(), 0)
  TEST_EQUALITY_CONST(emptyArray.getNumCols(), 0)
  TEST_EQUALITY_CONST(emptyArray.getDataArray().size(), 0)
  TEST_ASSERT(emptyArray.isEmpty());
}
Example #8
0
TEST(arrayTest, getNumRows) {
  TwoDArray<int>* i = new TwoDArray<int>(5, 5, 0);
  TwoDArray<double>* d = new TwoDArray<int>(6, 5, 0);
  TwoDArray<std::string>* s = new TwoDArray<std::string>(10, 5, "o");

  i->insert(2, 2, 7);
  d->insert(4, 4, 3.145);
  s->insert(0, 0, "Hello");

  EXPECT_EQ(5, i->getNumRows());
  EXPECT_EQ(6, d->getNumRows());
  EXPECT_EQ(10, s->getNumRows());

  delete i;
  delete d;
  delete s;
}
Example #9
0
TEST(constructor, stringTest) {
    int r = 10;
    int c = 10;
    TwoDArray<string>* a = new TwoDArray<string>(r, c);
    EXPECT_EQ(r, a->getNumRows());
    EXPECT_EQ(c, a->getNumCols());
    delete a;
}
Example #10
0
TEST(constructor, doubleTest) {
    int r = 10;
    int c = 10;
    TwoDArray<double>* a = new TwoDArray<double>(r, c);
    EXPECT_EQ(r, a->getNumRows());
    EXPECT_EQ(c, a->getNumCols());
    delete a;
}
Example #11
0
TEST(constructor, integerTest) {
    int r = 10;
    int c = 10;
    TwoDArray<int>* a = new TwoDArray<int>(r, c);
    EXPECT_EQ(r, a->getNumRows());
    EXPECT_EQ(c, a->getNumCols());
    delete a;
}
/**
 * Test the TwoDRowDependency.
 */
TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDRowDependency){
	RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList);
	RCP<DependencySheet> depSheet1 =
    RCP<DependencySheet>(new DependencySheet);

	ParameterList
	rowNumDepList = My_deplist->sublist(
    "2D Row Depdency List", false,
    "2D Row Dependecy testing list.");
	rowNumDepList.set("Num rows", 10, "num rows setter");
  TwoDArray<double> variableRowsArray(11,2,16.5);
	RCP<EnhancedNumberValidator<double> >
	varRowArrayVali = RCP<EnhancedNumberValidator<double> >(
  		new EnhancedNumberValidator<double>(10,50,4)
	);
	rowNumDepList.set(
    "Variable Row Array", variableRowsArray, "variable row array",
	  RCP<TwoDArrayNumberValidator<double> >(
      new TwoDArrayNumberValidator<double>(varRowArrayVali)));

	RCP<TwoDRowDependency<int, double> >
	  arrayRowDep = rcp(
  		new TwoDRowDependency<int, double>(
		  rowNumDepList.getEntryRCP("Num rows"),
			rowNumDepList.getEntryRCP("Variable Row Array") ,
      rcp(new AdditionFunction<int>(1))
		)
	);
	depSheet1->addDependency(arrayRowDep);
  TwoDArray<double> curArray =
    rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
	TEST_EQUALITY_CONST(curArray.getNumRows(),11);
	rowNumDepList.set("Num rows", 12);
	arrayRowDep()->evaluate();
  curArray =
    rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
	TEST_EQUALITY_CONST(curArray.getNumRows(),13);
	rowNumDepList.set("Num rows", -2);
	TEST_THROW(arrayRowDep()->evaluate(),
    Exceptions::InvalidParameterValue);
}
std::string TwoDArray<T>::toString(const TwoDArray<T> array){
  std::stringstream numColsStream;
  std::stringstream numRowsStream;
  numColsStream << array.getNumCols();
  numRowsStream << array.getNumRows();
  std::string metaSeperator = TwoDArray<T>::getMetaSeperator();
  return
    numRowsStream.str() +
    TwoDArray<T>::getDimensionsDelimiter() +
    numColsStream.str() +
    metaSeperator +
    (array.isSymmetrical() ? "sym"+metaSeperator : "") +
    array.getDataArray().toString();
}
Example #14
0
int main() {
  TwoDArray<int>* victim = new TwoDArray<int>(5,10,0);
  for(int i = 0; i<victim->getNumRows(); i++) {
    for(int j = 0; j<victim->getNumCols(); j++) {
      victim->insert(i,j,i+j);
    }
  }
  victim->print();
  delete victim;
  TwoDArray<std::string>* victim2 = new TwoDArray<std::string>(3,2,"moo");
  victim2->print();
  delete victim2;
  return 0;
}