52 namespace rcp = MemMngPack;
56 typedef std::vector<int> T;
75 if(out) out->precision(prec);
76 if(out) *out << std::boolalpha;
83 *out <<
"\n********************************************\n"
84 <<
"*** Testing IterQuantityAccessContiguous ***\n"
85 <<
"********************************************\n";
91 *out <<
"\n *** Test single storage ***\n"
92 <<
" IterQuantityAccessContiguous<int> x_cont(1,\"x\");\n"
93 <<
" IterQuantityAccess<int>& x = x_cont;\n";
104 *out<<
"\n** Check state\n"
105 <<
"x.has_storage_k(-300) == true : ";
108 *out<< result << endl;
111 *out<<
"x.has_storage_k(400) == true : ";
114 *out<< result << endl;
117 *out<<
"!x.updated_k(-45) == true : ";
120 *out<< result << endl;
123 *out<<
"!x.updated_k(60) == true : ";
126 *out<< result << endl;
129 *out<<
"\n** Perform an update and check state\n"
130 <<
"x.set_k(0) = 5;\n\n";
134 *out<<
"x.get_k(0) == 5 : ";
138 *out<< r <<
" : " << result << endl;
141 *out<<
"!x.updated_k(-1) == true : ";
144 *out<< result << endl;
147 *out<<
"!x.updated_k(1) == true : ";
150 *out<< result << endl;
153 *out<<
"!x.has_storage_k(-1) == true : ";
156 *out<< result << endl;
159 *out<<
"x.has_storage_k(1) == true : ";
162 *out<< result << endl;
165 *out<<
"\n** Do illegal set_k(), should throw NoStorageAvailable: x.set_k(-1) = 4 : ";
174 *out<<
"As expected! Caught IterQuantity::NoStorageAvailable: " << excpt.what() <<
" : true\n" << endl;
178 *out<<
"\n** Do illegal get_k(), should throw QuanityNotSet: x.get_k(1) : ";
186 if(out) *out <<
"As expected! Caught IterQuantity::QuanityNotSet: " << excpt.what() <<
" : true\n" << endl;
189 if(out) *out <<
"\nx.next_iteration();\n";
192 if(out) *out<<
"x.get_k(-1) == 5 : ";
196 *out<<
" : " << result << endl;
199 *out<<
"!x.updated_k(-2) == true : ";
202 *out<< result << endl;
205 *out<<
"x.updated_k(0) == true : ";
208 *out<< result << endl;
211 *out<<
"!x.has_storage_k(-2) == true : ";
214 *out<< result << endl;
217 *out<<
"x.has_storage_k(0) == true : ";
220 *out<< result << endl;
222 if(out) *out <<
"\nx.set_k(0,-1);\n\n";
227 if(out) *out <<
"x.get_k(0) == 5 : ";
231 *out<< r <<
" : " << result << endl;
234 *out<<
"x.will_loose_mem(0,1) == true : ";
237 *out<< result << endl;
239 if(out) *out <<
"\nx.set_k(1) = -4;\n\n";
243 *out<<
"x.get_k(1) == -4 : ";
247 *out<< r <<
" : " << result << endl;
250 *out<<
"\nx.next_iteration();\n\n";
254 *out<<
"x.get_k(0) == -4 : ";
258 *out<< r <<
" : " << result << endl;
266 *out<<
"\n*** Test dual storage ***\n"
267 <<
"IterQuantityAccessContiguous<int> x_cont(2,\"x\");\n"
268 <<
"IterQuantityAccess<int>& x = x_cont;\n";
279 *out<<
"\n** Check state\n"
280 <<
"x.has_storage_k(-300) == true : ";
283 *out<< result << endl;
286 *out<<
"x.has_storage_k(400) == true : ";
289 *out<< result << endl;
292 *out<<
"!x.updated_k(-45) == true : ";
295 *out<< result << endl;
298 *out<<
"!x.updated_k(60) == true : ";
301 *out<< result << endl;
304 *out<<
"\n** Perform an update and check state\n"
305 <<
"x.set_k(0) = 5;\n\n";
309 *out<<
"x.get_k(0) == 5 : ";
313 *out<< r <<
" : " << result << endl;
316 *out<<
"!x.updated_k(-1) == true : ";
319 *out<< result << endl;
322 *out<<
"!x.updated_k(1) == true : ";
325 *out<< result << endl;
328 *out<<
"!x.has_storage_k(-2) == true : ";
331 *out<< result << endl;
334 *out<<
"x.has_storage_k(-1) == true : ";
337 *out<< result << endl;
340 *out<<
"x.has_storage_k(1) == true : ";
343 *out<< result << endl;
346 *out<<
"\nx.set_k(-1) = 4;\n\n";
350 *out<<
"x.get_k(-1) == 4 : ";
354 *out<< r <<
" : " << result << endl;
357 *out<<
"\n** Do illegal set_k(), should throw NoStorageAvailable: x.set_k(-2) = 4 : ";
366 *out<<
"As expected! Caught IterQuantity::NoStorageAvailable: " << excpt.what() <<
" : true\n" << endl;
370 *out<<
"\n** Do illegal get_k(), should throw QuanityNotSet: x.get_k(1) : ";
379 *out<<
"As expected! Caught IterQuantity::QuanityNotSet: " << excpt.what() <<
" : true\n" << endl;
383 *out<<
"\nx.next_iteration();\n\n";
387 *out<<
"x.get_k(-2) == 4 : ";
391 *out<< r <<
" : " << result << endl;
394 *out<<
"x.get_k(-1) == 5 : ";
398 *out<< r <<
" : " << result << endl;
401 *out<<
"!x.updated_k(-3) == true : ";
404 *out<< result << endl;
407 *out<<
"!x.updated_k(0) == true : ";
410 *out<< result << endl;
413 *out<<
"!x.has_storage_k(-3) == true : ";
416 *out<< result << endl;
419 *out<<
"!x.has_storage_k(0) == true : ";
422 *out<< result << endl;
425 *out<<
"x.set_k(0,-1);\n\n";
431 *out<<
"x.get_k(0) == 5 : ";
435 *out<< r <<
" : " << result << endl;
438 *out<<
"x.get_k(-1) == 5 : ";
442 *out<< r <<
" : " << result << endl;
445 *out<<
"!x.updated_k(-2) == true : ";
448 *out<< result << endl;
451 *out<<
"!x.will_loose_mem(0,1) == true : ";
454 *out<< result << endl;
457 *out<<
"x.will_loose_mem(-1,1) == true : ";
460 *out<< result << endl;
463 *out<<
"\nx.set_k(1) = -4;\n\n";
467 *out<<
"x.get_k(1) == -4 : ";
471 *out<< r <<
" : " << result << endl;
474 *out<<
"x.get_k(0) == 5 : ";
478 *out<< r <<
" : " << result << endl;
481 *out<<
"\nx.next_iteration();\n\n";
485 *out<<
"x.get_k(0) == -4 : ";
489 *out<< r <<
" : " << result << endl;
496 *out<<
"\n*** Test 4 storage ***\n"
497 <<
"IterQuantityAccessContiguous<int> x_cont(4,\"x\");\n"
498 <<
"IterQuantityAccess<int>& x = x_cont;\n";
509 *out<<
"\n** Check state\n";
512 *out<<
"x.has_storage_k(-300) == true : ";
515 *out<< result << endl;
518 *out<<
"x.has_storage_k(400) == true : ";
521 *out<< result << endl;
524 *out<<
"!x.updated_k(-45) == true : ";
527 *out<< result << endl;
530 *out<<
"!x.updated_k(60) == true : ";
533 *out<< result << endl;
536 *out<<
"\n** Perform an update and check state\n"
537 <<
"x.set_k(0) = 1;\n\n";
541 *out<<
"x.get_k(0) == 1 : ";
545 *out<< r <<
" : " << result << endl;
548 *out<<
"!x.updated_k(-4) == true : ";
551 *out<< result << endl;
554 *out<<
"!x.updated_k(-3) == true : ";
557 *out<< result << endl;
560 *out<<
"!x.updated_k(-2) == true : ";
563 *out<< result << endl;
566 *out<<
"!x.updated_k(-1) == true : ";
569 *out<< result << endl;
572 *out<<
"x.updated_k(0) == true : ";
575 *out<< result << endl;
578 *out<<
"!x.updated_k(1) == true : ";
581 *out<< result << endl;
584 *out<<
"!x.has_storage_k(-4) == true : ";
587 *out<< result << endl;
590 *out<<
"x.has_storage_k(-3) == true : ";
593 *out<< result << endl;
596 *out<<
"x.has_storage_k(-2) == true : ";
599 *out<< result << endl;
602 *out<<
"x.has_storage_k(-1) == true : ";
605 *out<< result << endl;
608 *out<<
"x.has_storage_k(0) == true : ";
611 *out<< result << endl;
614 *out<<
"x.has_storage_k(1) == true : ";
617 *out<< result << endl;
620 *out<<
"\nx.set_k(-1) = 2;\n\n";
624 *out<<
"x.get_k(-1) == 2 : ";
628 *out<< r <<
" : " << result << endl;
631 *out<<
"\nx.set_k(-2) = 3;\n"
632 <<
"x.set_k(-3) = 4;\n\n";
637 *out<<
"x.get_k(-2) == 3 : ";
641 *out<< r <<
" : " << result << endl;
644 *out<<
"x.get_k(-3) == 4 : ";
648 *out<< r <<
" : " << result << endl;
652 *out<<
"\n** Do illegal set_k(), should throw NoStorageAvailable: x.set_k(-4) = 4 : ";
661 *out<<
"As expected! Caught IterQuantity::NoStorageAvailable: " << excpt.what() <<
" : true\n" << endl;
665 *out<<
"\n** Do illegal get_k(), should throw QuanityNotSet: x.get_k(1) : ";
674 *out<<
"As expected! Caught IterQuantity::QuanityNotSet: " << excpt.what() <<
" : true" << endl;
678 *out<<
"\nx.next_iteration();\n\n";
682 *out<<
"x.get_k(-4) == 4 : ";
686 *out<< r <<
" : " << result << endl;
689 *out<<
"x.get_k(-3) == 3 : ";
693 *out<< r <<
" : " << result << endl;
696 *out<<
"x.get_k(-2) == 2 : ";
700 *out<< r <<
" : " << result << endl;
703 *out<<
"x.get_k(-1) == 1 : ";
707 *out<< r <<
" : " << result << endl;
710 *out<<
"!x.updated_k(-5) == true : ";
713 *out<< result << endl;
716 *out<<
"!x.updated_k(0) == true : ";
719 *out<< result << endl;
722 *out<<
"!x.has_storage_k(-5) == true : ";
725 *out<< result << endl;
728 *out<<
"x.has_storage_k(0) == true : ";
731 *out<< result << endl;
734 *out<<
"\nx.set_k(0,-1);\n\n";
740 *out<<
"x.get_k(-3) == 3 : ";
744 *out<< r <<
" : " << result << endl;
747 *out<<
"x.get_k(-2) == 2 : ";
751 *out<< r <<
" : " << result << endl;
754 *out<<
"x.get_k(-1) == 1 : ";
758 *out<< r <<
" : " << result << endl;
761 *out<<
"x.get_k(0) == 1 : ";
765 *out<< r <<
" : " << result << endl;
768 *out<<
"!x.updated_k(-4) == true : ";
771 *out<< result << endl;
774 *out<<
"!x.will_loose_mem(-2,1) == true : ";
777 *out<< result << endl;
780 *out<<
"x.will_loose_mem(-3,1) == true : ";
783 *out<< result << endl;
786 *out<<
"\nx.set_k(1) = -4;\n\n";
790 *out<<
"x.get_k(-2) == 2 : ";
794 *out<< r <<
" : " << result << endl;
797 *out<<
"x.get_k(-1) == 1 : ";
801 *out<< r <<
" : " << result << endl;
804 *out<<
"x.get_k(0) == 1 : ";
808 *out<< r <<
" : " << result << endl;
811 *out<<
"x.get_k(1) == -4 : ";
815 *out<< r <<
" : " << result << endl;
818 *out<<
"\nx.next_iteration();\n\n";
822 *out<<
"x.get_k(-2) == 1 : ";
826 *out<< r <<
" : " << result << endl;
829 *out<<
"x.get_k(-1) == 1 : ";
833 *out<< r <<
" : " << result << endl;
836 *out<<
"x.get_k(0) == -4 : ";
840 *out<< r <<
" : " << result << endl;
845 *out<<
"\n*** Congradulations, all of the tests returned the expected results ***\n";
849 *out<<
"\n*** Oops, at least one of the above tests did not return the expected results ***\n";
855 catch(
const std::exception& excpt) {
857 *out<<
"\nCaught a std::exception: " << excpt.what() << endl;
861 *out<<
"\nCaught and unknown exception\n";
Interface to typed iteration quantities.
virtual T_info & get_k(int offset)=0
Return a reference for the k + offset iteration quanity.
Thrown when memory access is attempted when it has not yet been updated.
virtual bool has_storage_k(int offset) const =0
Determine if there is storage advailable for the k offset iteration quanity.
Thrown memory if attempted to be set that storage can not be allocated to.
virtual void next_iteration()=0
Shift the reference point from the k to the k+1 iteration.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool updated_k(int offset) const =0
Determine if the quanity for the k offset iteration has been accessed by a call to set_k() (see IterQ...
virtual T_info & set_k(int offset)=0
Return a reference to the storage location for the k + offset iteration quanity.
virtual bool will_loose_mem(int offset, int set_offset) const =0
Determine if the memory for the k + offset quantityy will be lost if set_k(set_offset) is called (see...
Iteration Quanities subclass for contiguous iterations.
bool update_success(bool result_check, bool *success)
Helper function for updating a flag for if an operation returned false.
bool TestIterQuantityAccessContiguous(std::ostream *out)