void TestPetscExceptions() { /* * Note we could test with TS_ASSERT_THROWS_THIS() but PetscException * includes line numbers so it isn't very robust. */ int err = 0; TS_ASSERT_THROWS_NOTHING(PETSCEXCEPT(err)); Vec v; err = VecCreateMPI(PETSC_COMM_WORLD, 2, 1, &v); PetscTools::Destroy(v); //#define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong */ //#define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ TS_ASSERT_EQUALS(err, PETSC_ERR_ARG_INCOMP); TS_ASSERT_THROWS(PETSCEXCEPT(err), Exception); err=PETSC_ERR_FILE_OPEN; //#define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ TS_ASSERT_EQUALS(err, PETSC_ERR_FILE_OPEN); TS_ASSERT_THROWS(PETSCEXCEPT(err), Exception); // See if we can do it without a temporary TS_ASSERT_THROWS( PETSCEXCEPT(VecCreateMPI(PETSC_COMM_WORLD, 2, 1, &v)), Exception); PetscTools::Destroy(v); // This test give back an "unknown error" message TS_ASSERT_THROWS( PETSCEXCEPT(-3), Exception); }
/** * Test going out-of-bounds. */ void test_index_except() { Vector<unsigned int> a(5); const Vector<unsigned int> b(1); TS_ASSERT_THROWS(a[5] = 1, std::out_of_range); TS_ASSERT_THROWS(b[2], std::out_of_range); }
void TestAirplaneConstruction() { // 100 - number of seats; 500.0 fuel tank capacity Airplane airplane(201, 500.0); TS_ASSERT_EQUALS(airplane.getFuel(), 0); TS_ASSERT_EQUALS(airplane.getNumberOfPassengers(), 0); TS_ASSERT_EQUALS(airplane.getNumberOfSeats(), 100); TS_ASSERT_EQUALS(airplane.getNumberOfPilots(), 0); TS_ASSERT_EQUALS(airplane.getNumberOfStewardess(), 0); TS_ASSERT_EQUALS(airplane.getFuelTankCapacity(), 500.0); for (size_t seats = 0; seats <= 300; ++seats) { if ((seats >= 10) && (seats <= 200)) { TS_ASSERT_THROWS_NOTHING(Airplane plane(seats, 500)); } else { TS_ASSERT_THROWS(Airplane plane(seats, 500), std::invalid_argument); } } // 50 - number of seats Airplane airplane1(50, 100.0); TS_ASSERT_EQUALS(airplane1.getNumberOfSeats(), 50); TS_ASSERT_EQUALS(airplane1.getFuelTankCapacity(), 100.0); }
void test_write_hidden_single_worksheet() { xlnt::workbook wb; auto ws = wb.get_active_sheet(); ws.set_sheet_state(xlnt::page_setup::sheet_state::hidden); TS_ASSERT_THROWS(xlnt::write_workbook(wb), xlnt::value_error); }
void testBadAddArgs( void ) { TEST_HEADER; ArgParse argParse("intro", "outro"); TS_ASSERT_THROWS( argParse.addArgument("s", "no dash"), std::logic_error); TS_ASSERT_THROWS( argParse.addArgument("-i", "bad range", ArgParse::INT, ArgParse::OPTIONAL, ArgParse::OPTIONAL, "", "12..forever"), std::logic_error); TS_ASSERT_THROWS( argParse.addArgument("-i", "bad range", ArgParse::FLOAT, ArgParse::OPTIONAL, ArgParse::OPTIONAL, "", "12.34..forever"), std::logic_error); }
void test_as() { Object* obj = util_new_object(); Fixnum* fix = Fixnum::from(1); Object* nil = Qnil; // OK TS_ASSERT_EQUALS(as<Object>(obj), obj); TS_ASSERT_EQUALS(as<Integer>(fix), fix); TS_ASSERT_EQUALS(as<Fixnum>(fix), fix); TS_ASSERT_EQUALS(as<Object>(fix), fix); // Fail TS_ASSERT_THROWS(as<String>(nil), TypeError); TS_ASSERT_THROWS(as<String>(obj), TypeError); TS_ASSERT_THROWS(as<String>(fix), TypeError); }
void test_write_hidden_single_worksheet() { xlnt::workbook wb; auto ws = wb.get_active_sheet(); ws.set_sheet_state(xlnt::sheet_state::hidden); xlnt::workbook_serializer serializer(wb); TS_ASSERT_THROWS(serializer.write_workbook(), xlnt::value_error); }
void TestKspExceptionsForCoverage() { TS_ASSERT_THROWS_NOTHING( KSPEXCEPT(2)); /* * These next few lines are designed to force the coverage test to pass. * Some are hard to throw in normal circumstances -- * "Unknown KSP error code" ought never to be thrown. */ TS_ASSERT_THROWS_CONTAINS( KSPEXCEPT(KSP_DIVERGED_ITS), "DIVERGED_ITS in function \'User provided function\' on line"); // The next one is deliberately fragile because it contains the line number in this test suite (to check that the line number is output correctly). TS_ASSERT_THROWS_THIS( KSPEXCEPT(KSP_DIVERGED_DTOL), "DIVERGED_DTOL in function \'User provided function\' on line 102 of file ./global/test/TestPetscSetup.hpp"); TS_ASSERT_THROWS( KSPEXCEPT(KSP_DIVERGED_BREAKDOWN), Exception ); TS_ASSERT_THROWS( KSPEXCEPT(KSP_DIVERGED_BREAKDOWN_BICG), Exception ); TS_ASSERT_THROWS( KSPEXCEPT(KSP_DIVERGED_NONSYMMETRIC), Exception ); TS_ASSERT_THROWS( KSPEXCEPT(KSP_DIVERGED_INDEFINITE_PC), Exception ); TS_ASSERT_THROWS( KSPEXCEPT(-735827), Exception ); KSPWARNIFFAILED(KSP_DIVERGED_ITS); TS_ASSERT_EQUALS(Warnings::Instance()->GetNumWarnings(), 1u); Warnings::QuietDestroy(); }
/** * Test copy. */ void test_copy_op() { Vector<unsigned int> a(5); a[2] = (unsigned int) 3; Vector<unsigned int> b(7); b = a; TS_ASSERT_EQUALS(b[2], (unsigned int) 3); TS_ASSERT_EQUALS(a[2], (unsigned int) 3); TS_ASSERT(b.size() == 5); a.push_back(19); TS_ASSERT_THROWS(b[5], std::out_of_range); a[2] = (unsigned int) 4; TS_ASSERT_EQUALS(b[2], (unsigned int) 3); TS_ASSERT_EQUALS(a[2], (unsigned int) 4); b[2] = (unsigned int) 5; TS_ASSERT_EQUALS(b[2], (unsigned int) 5); TS_ASSERT_EQUALS(a[2], (unsigned int) 4); }
/** * Test the push back functionality. */ void test_push_back() { Vector<unsigned int> a(13); a.push_back(5); TS_ASSERT_EQUALS(a[13], (unsigned int) 5); TS_ASSERT_EQUALS(a[10], (unsigned int) 0); Vector<unsigned int> b(a); TS_ASSERT_EQUALS(b[13], (unsigned int) 5); a.push_back(17); TS_ASSERT_EQUALS(a[14], (unsigned int) 17); TS_ASSERT_THROWS(b[14], std::out_of_range); Vector<unsigned int> c(0); c.push_back(1); c.push_back(2); c.push_back(3); TS_ASSERT_EQUALS(c[1], (unsigned int) 2); c[0] = 5; TS_ASSERT_EQUALS(c[0], (unsigned int) 5); }
void TestException() { TS_ASSERT_THROWS(throw DistributedVectorException(), DistributedVectorException); }
void TestWrite() { // WRITE VECTOR // Create a 10 element petsc vector DistributedVectorFactory factory(10); Vec striped = factory.CreateVec(2); Vec chunked = factory.CreateVec(2); Vec petsc_vec = factory.CreateVec(); DistributedVector distributed_vector = factory.CreateDistributedVector(petsc_vec); DistributedVector distributed_vector_striped = factory.CreateDistributedVector(striped); DistributedVector distributed_vector_chunked = factory.CreateDistributedVector(chunked); DistributedVector::Stripe linear(distributed_vector_striped, 0); DistributedVector::Stripe quadratic(distributed_vector_striped, 1); DistributedVector::Chunk linear_chunk(distributed_vector_chunked, 0); DistributedVector::Chunk quadratic_chunk(distributed_vector_chunked, 1); // Write some values for (DistributedVector::Iterator index = distributed_vector.Begin(); index!= distributed_vector.End(); ++index) { distributed_vector[index] = -(double)(index.Local*index.Global); linear[index] = -1; quadratic[index] = index.Local+1; linear_chunk[index] = -1; quadratic_chunk[index] = index.Global+1; } distributed_vector.Restore(); distributed_vector_striped.Restore(); distributed_vector_chunked.Restore(); // READ VECTOR // Calculate my range PetscInt petsc_lo, petsc_hi; VecGetOwnershipRange(petsc_vec,&petsc_lo,&petsc_hi); unsigned lo = (unsigned)petsc_lo; unsigned hi = (unsigned)petsc_hi; // Read some values double* p_striped; VecGetArray(striped, &p_striped); double* p_chunked; VecGetArray(chunked, &p_chunked); double* p_vec; VecGetArray(petsc_vec, &p_vec); for (unsigned global_index=lo; global_index<hi; global_index++) { unsigned local_index = global_index - lo; TS_ASSERT_EQUALS(p_vec[local_index], -(double)local_index*global_index); TS_ASSERT_EQUALS(p_striped[2*local_index], -1.0); TS_ASSERT_EQUALS(p_striped[2*local_index+1], local_index+1); TS_ASSERT_EQUALS(linear[global_index], -1.0); TS_ASSERT_EQUALS(quadratic[global_index], local_index+1); TS_ASSERT_EQUALS(p_chunked[local_index], -1.0); TS_ASSERT_EQUALS(p_chunked[ (hi - lo) + local_index], global_index+1); TS_ASSERT_EQUALS(linear_chunk[global_index], -1.0); TS_ASSERT_EQUALS(quadratic_chunk[global_index], global_index+1); } // Read item 2 from the distributed vectors (for coverage) if (lo<=2 && 2<hi) { TS_ASSERT(distributed_vector.IsGlobalIndexLocal(2)); TS_ASSERT_EQUALS(linear[2], -1.0); TS_ASSERT_EQUALS(quadratic[2], 3.0 - lo); TS_ASSERT_EQUALS(linear_chunk[2], -1.0); TS_ASSERT_EQUALS(quadratic_chunk[2], 3.0); } else { TS_ASSERT(!distributed_vector.IsGlobalIndexLocal(2)); TS_ASSERT_THROWS(linear[2],DistributedVectorException); TS_ASSERT_THROWS(linear_chunk[2],DistributedVectorException); } PetscTools::Destroy(petsc_vec); PetscTools::Destroy(striped); PetscTools::Destroy(chunked); }
void TestRead() { // WRITE VECTOR // create a 10 element petsc vector unsigned vec_size = 10u; Vec vec=PetscTools::CreateVec(vec_size); // calculate the range PetscInt petsc_lo, petsc_hi; VecGetOwnershipRange(vec, &petsc_lo, &petsc_hi); unsigned lo=(unsigned)petsc_lo; unsigned hi=(unsigned)petsc_hi; // create 20 element petsc vector Vec striped; VecCreateMPI(PETSC_COMM_WORLD, 2*(hi-lo) , 2*vec_size, &striped); // write some values double* p_vec; VecGetArray(vec, &p_vec); double* p_striped; VecGetArray(striped, &p_striped); for (unsigned global_index=lo; global_index<hi; global_index++) { unsigned local_index = global_index - lo; p_vec[local_index] = local_index*global_index; p_striped[2*local_index ] = local_index; p_striped[2*local_index+1] = global_index*global_index; } VecRestoreArray(vec, &p_vec); VecAssemblyBegin(vec); VecAssemblyEnd(vec); VecRestoreArray(striped, &p_striped); VecAssemblyBegin(striped); VecAssemblyEnd(striped); // READ VECTOR DistributedVectorFactory factory(vec); DistributedVector distributed_vector = factory.CreateDistributedVector(vec); DistributedVector distributed_vector2 = factory.CreateDistributedVector(striped); DistributedVector::Stripe linear(distributed_vector2,0); DistributedVector::Stripe quadratic(distributed_vector2,1); // check the range TS_ASSERT_EQUALS(factory.GetProblemSize(), vec_size); TS_ASSERT_EQUALS(distributed_vector.Begin().Global,lo); TS_ASSERT_EQUALS(distributed_vector.End().Global,hi); // read some values for (DistributedVector::Iterator index = distributed_vector.Begin(); index!= distributed_vector.End(); ++index) { TS_ASSERT_EQUALS(distributed_vector[index], index.Local*index.Global); TS_ASSERT_EQUALS(linear[index], index.Local); TS_ASSERT_EQUALS(quadratic[index], index.Global * index.Global); } // read the 2nd element of the first vector if (lo<=2 && 2<hi) { TS_ASSERT(distributed_vector.IsGlobalIndexLocal(2)); TS_ASSERT_EQUALS(distributed_vector[2],2*(2-lo)); } else { TS_ASSERT(!distributed_vector.IsGlobalIndexLocal(2)); TS_ASSERT_THROWS(distributed_vector[2],DistributedVectorException); } //read the 3rd element of the other vectors if (lo<=3 && 3<hi) { TS_ASSERT(distributed_vector.IsGlobalIndexLocal(3)); TS_ASSERT_EQUALS(linear[3],(3-lo)); TS_ASSERT_EQUALS(quadratic[3],3*3); } else { TS_ASSERT(!distributed_vector.IsGlobalIndexLocal(3)); TS_ASSERT_THROWS(linear[3],DistributedVectorException); TS_ASSERT_THROWS(quadratic[3],DistributedVectorException); } PetscTools::Destroy(vec); PetscTools::Destroy(striped); }
void testloadFromFile(void){ TS_ASSERT_THROWS(Settings::instance().loadFromFile("does_not_exist.lua"), LuaFileException); }
void test_read_empty_archive() { auto path = PathHelper::GetDataDirectory("/reader/null_archive.xlsx"); TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invalid_file_exception); }
void test_bad_formats_no() { auto path = PathHelper::GetDataDirectory("/genuine/a.no-format"); TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invalid_file_exception); }