Commit 7ddd1bc2ff7b335aacd843c01ca4c9af4ddab11c

Authored by Andreas Specovius
Committed by Jürgen Knödlseder
1 parent 354c133b

Implemented tests: Added test_GSkyRegionRect_construct() and test_GSkyRegionRect…

…_logic() methods. (Following circle region implementation, extended). Extended test_GSkyRegions_io() and test_GSkyRegionMap_logic() methods. Obviously lots of tabs have been automatically replaced by spaces.
include/GammaLib.hpp
... ... @@ -152,6 +152,7 @@
152 152 #include "GSkyRegions.hpp"
153 153 #include "GSkyRegion.hpp"
154 154 #include "GSkyRegionCircle.hpp"
  155 +#include "GSkyRegionRect.hpp"
155 156 #include "GSkyRegionMap.hpp"
156 157 #include "GSkyProjection.hpp"
157 158 #include "GHealpix.hpp"
... ...
test/data/test_rect_region.reg 0 → 100644
  1 +# Region file format: DS9 version 4.1
  2 +global color=green dashlist=8 3 width=1
  3 +fk5;box(250,-46,0.8,0.2,45)
... ...
test/test_GSky.cpp
... ... @@ -44,15 +44,16 @@
44 44 #define G_WCS_COPY_DEBUG
45 45  
46 46 /* __ Constants __________________________________________________________ */
47   -const std::string datadir = std::getenv("TEST_DATA");
48   -const std::string sky_region = datadir + "/test_circle_region.reg";
49   -const std::string sky_region_map = datadir + "/test_map_region.fits";
50   -const std::string sky_map = datadir + "/cena_lobes_parkes.fits";
  47 +const std::string datadir = std::getenv("TEST_DATA");
  48 +const std::string sky_region = datadir + "/test_circle_region.reg";
  49 +const std::string sky_region_rect = datadir + "/test_rect_region.reg";
  50 +const std::string sky_region_map = datadir + "/test_map_region.fits";
  51 +const std::string sky_map = datadir + "/cena_lobes_parkes.fits";
51 52  
52 53  
53 54 /***********************************************************************//**
54 55 * @brief Set parameters and tests
55   - ***************************************************************************/
  56 + ***************************************************************************/
56 57 void TestGSky::set(void){
57 58  
58 59 // Test name
... ... @@ -83,6 +84,8 @@ void TestGSky::set(void){
83 84 "Test GSkyRegions");
84 85 append(static_cast<pfunction>(&TestGSky::test_GSkyRegionCircle),
85 86 "Test GSkyRegionCircle");
  87 + append(static_cast<pfunction>(&TestGSky::test_GSkyRegionRect),
  88 + "Test GSkyRegionRect");
86 89 append(static_cast<pfunction>(&TestGSky::test_GSkyRegionMap),
87 90 "Test GSkyRegionMap");
88 91 append(static_cast<pfunction>(&TestGSky::test_GHorizDir),
... ... @@ -539,7 +542,7 @@ void TestGSky::test_GWcs(void)
539 542  
540 543 // Throw an error if allocation failed
541 544 if (cel == NULL || gal == NULL) {
542   - std::cout << std::endl
  545 + std::cout << std::endl
543 546 << "TEST ERROR: Could not allocate "+test_class+"."
544 547 << std::endl;
545 548 throw exception_error("Could not allocate"+test_class);
... ... @@ -565,7 +568,7 @@ void TestGSky::test_GWcs(void)
565 568 " tolerance 1.0e-10 exceeded: "+
566 569 gammalib::str(tol));
567 570 }
568   - test_try_success();
  571 + test_try_success();
569 572 }
570 573 catch (std::exception &e) {
571 574 test_try_failure(e);
... ... @@ -640,166 +643,166 @@ void TestGSky::test_GSkyMap_healpix_construct(void)
640 643  
641 644 // Test void constructor
642 645 GSkyMap empty_map;
643   - test_assert(empty_map.is_empty(), "Check for empty sky map");
644   - test_value(empty_map.npix(), 0, "Check for no sky map pixels");
645   - test_value(empty_map.nx(), 0, "Check for no X-direction map pixels");
646   - test_value(empty_map.ny(), 0, "Check for no Y-direction map pixels");
647   - test_value(empty_map.nmaps(), 0, "Check for no sky maps");
  646 + test_assert(empty_map.is_empty(), "Check for empty sky map");
  647 + test_value(empty_map.npix(), 0, "Check for no sky map pixels");
  648 + test_value(empty_map.nx(), 0, "Check for no X-direction map pixels");
  649 + test_value(empty_map.ny(), 0, "Check for no Y-direction map pixels");
  650 + test_value(empty_map.nmaps(), 0, "Check for no sky maps");
648 651  
649 652 // Test Healpix constructors
650 653 GSkyMap ring1("GAL", 1, "RING", 1);
651   - test_assert(!ring1.is_empty(), "Check for non-empty sky map");
652   - test_value(ring1.npix(), 12, "Check for 12 sky map pixels");
653   - test_value(ring1.nx(), 0, "Check for no X-direction map pixels");
654   - test_value(ring1.ny(), 0, "Check for no Y-direction map pixels");
655   - test_value(ring1.nmaps(), 1, "Check for one sky map");
  654 + test_assert(!ring1.is_empty(), "Check for non-empty sky map");
  655 + test_value(ring1.npix(), 12, "Check for 12 sky map pixels");
  656 + test_value(ring1.nx(), 0, "Check for no X-direction map pixels");
  657 + test_value(ring1.ny(), 0, "Check for no Y-direction map pixels");
  658 + test_value(ring1.nmaps(), 1, "Check for one sky map");
656 659 //
657 660 GSkyMap ring2("GAL", 2, "RING", 1);
658   - test_assert(!ring2.is_empty(), "Check for non-empty sky map");
659   - test_value(ring2.npix(), 48, "Check for 48 sky map pixels");
660   - test_value(ring2.nx(), 0, "Check for no X-direction map pixels");
661   - test_value(ring2.ny(), 0, "Check for no Y-direction map pixels");
662   - test_value(ring2.nmaps(), 1, "Check for one sky map");
  661 + test_assert(!ring2.is_empty(), "Check for non-empty sky map");
  662 + test_value(ring2.npix(), 48, "Check for 48 sky map pixels");
  663 + test_value(ring2.nx(), 0, "Check for no X-direction map pixels");
  664 + test_value(ring2.ny(), 0, "Check for no Y-direction map pixels");
  665 + test_value(ring2.nmaps(), 1, "Check for one sky map");
663 666 //
664 667 GSkyMap ring4("GAL", 4, "RING", 1);
665   - test_assert(!ring4.is_empty(), "Check for non-empty sky map");
666   - test_value(ring4.npix(), 192, "Check for 192 sky map pixels");
667   - test_value(ring4.nx(), 0, "Check for no X-direction map pixels");
668   - test_value(ring4.ny(), 0, "Check for no Y-direction map pixels");
669   - test_value(ring4.nmaps(), 1, "Check for one sky map");
  668 + test_assert(!ring4.is_empty(), "Check for non-empty sky map");
  669 + test_value(ring4.npix(), 192, "Check for 192 sky map pixels");
  670 + test_value(ring4.nx(), 0, "Check for no X-direction map pixels");
  671 + test_value(ring4.ny(), 0, "Check for no Y-direction map pixels");
  672 + test_value(ring4.nmaps(), 1, "Check for one sky map");
670 673 //
671 674 GSkyMap ring8("GAL", 8, "RING", 1);
672   - test_assert(!ring8.is_empty(), "Check for non-empty sky map");
673   - test_value(ring8.npix(), 768, "Check for 768 sky map pixels");
674   - test_value(ring8.nx(), 0, "Check for no X-direction map pixels");
675   - test_value(ring8.ny(), 0, "Check for no Y-direction map pixels");
676   - test_value(ring8.nmaps(), 1, "Check for one sky map");
  675 + test_assert(!ring8.is_empty(), "Check for non-empty sky map");
  676 + test_value(ring8.npix(), 768, "Check for 768 sky map pixels");
  677 + test_value(ring8.nx(), 0, "Check for no X-direction map pixels");
  678 + test_value(ring8.ny(), 0, "Check for no Y-direction map pixels");
  679 + test_value(ring8.nmaps(), 1, "Check for one sky map");
677 680 //
678 681 GSkyMap ring16("GAL", 16, "RING", 1);
679   - test_assert(!ring16.is_empty(), "Check for non-empty sky map");
680   - test_value(ring16.npix(), 3072, "Check for 3072 sky map pixels");
681   - test_value(ring16.nx(), 0, "Check for no X-direction map pixels");
682   - test_value(ring16.ny(), 0, "Check for no Y-direction map pixels");
683   - test_value(ring16.nmaps(), 1, "Check for one sky map");
  682 + test_assert(!ring16.is_empty(), "Check for non-empty sky map");
  683 + test_value(ring16.npix(), 3072, "Check for 3072 sky map pixels");
  684 + test_value(ring16.nx(), 0, "Check for no X-direction map pixels");
  685 + test_value(ring16.ny(), 0, "Check for no Y-direction map pixels");
  686 + test_value(ring16.nmaps(), 1, "Check for one sky map");
684 687 //
685 688 GSkyMap ring32("GAL", 32, "RING", 1);
686   - test_assert(!ring32.is_empty(), "Check for non-empty sky map");
687   - test_value(ring32.npix(), 12288, "Check for 12288 sky map pixels");
688   - test_value(ring32.nx(), 0, "Check for no X-direction map pixels");
689   - test_value(ring32.ny(), 0, "Check for no Y-direction map pixels");
690   - test_value(ring32.nmaps(), 1, "Check for one sky map");
  689 + test_assert(!ring32.is_empty(), "Check for non-empty sky map");
  690 + test_value(ring32.npix(), 12288, "Check for 12288 sky map pixels");
  691 + test_value(ring32.nx(), 0, "Check for no X-direction map pixels");
  692 + test_value(ring32.ny(), 0, "Check for no Y-direction map pixels");
  693 + test_value(ring32.nmaps(), 1, "Check for one sky map");
691 694 //
692 695 GSkyMap ring64("GAL", 64, "RING", 1);
693   - test_assert(!ring64.is_empty(), "Check for non-empty sky map");
694   - test_value(ring64.npix(), 49152, "Check for 49152 sky map pixels");
695   - test_value(ring64.nx(), 0, "Check for no X-direction map pixels");
696   - test_value(ring64.ny(), 0, "Check for no Y-direction map pixels");
697   - test_value(ring64.nmaps(), 1, "Check for one sky map");
  696 + test_assert(!ring64.is_empty(), "Check for non-empty sky map");
  697 + test_value(ring64.npix(), 49152, "Check for 49152 sky map pixels");
  698 + test_value(ring64.nx(), 0, "Check for no X-direction map pixels");
  699 + test_value(ring64.ny(), 0, "Check for no Y-direction map pixels");
  700 + test_value(ring64.nmaps(), 1, "Check for one sky map");
698 701 //
699 702 GSkyMap ring128("GAL", 128, "RING", 1);
700   - test_assert(!ring128.is_empty(), "Check for non-empty sky map");
701   - test_value(ring128.npix(), 196608, "Check for 196608 sky map pixels");
702   - test_value(ring128.nx(), 0, "Check for no X-direction map pixels");
703   - test_value(ring128.ny(), 0, "Check for no Y-direction map pixels");
704   - test_value(ring128.nmaps(), 1, "Check for one sky map");
  703 + test_assert(!ring128.is_empty(), "Check for non-empty sky map");
  704 + test_value(ring128.npix(), 196608, "Check for 196608 sky map pixels");
  705 + test_value(ring128.nx(), 0, "Check for no X-direction map pixels");
  706 + test_value(ring128.ny(), 0, "Check for no Y-direction map pixels");
  707 + test_value(ring128.nmaps(), 1, "Check for one sky map");
705 708 //
706 709 GSkyMap ring256("GAL", 256, "RING", 1);
707   - test_assert(!ring256.is_empty(), "Check for non-empty sky map");
708   - test_value(ring256.npix(), 786432, "Check 786432 XX sky map pixels");
709   - test_value(ring256.nx(), 0, "Check for no X-direction map pixels");
710   - test_value(ring256.ny(), 0, "Check for no Y-direction map pixels");
711   - test_value(ring256.nmaps(), 1, "Check for one sky map");
  710 + test_assert(!ring256.is_empty(), "Check for non-empty sky map");
  711 + test_value(ring256.npix(), 786432, "Check 786432 XX sky map pixels");
  712 + test_value(ring256.nx(), 0, "Check for no X-direction map pixels");
  713 + test_value(ring256.ny(), 0, "Check for no Y-direction map pixels");
  714 + test_value(ring256.nmaps(), 1, "Check for one sky map");
712 715 //
713 716 GSkyMap ring512("GAL", 512, "RING", 1);
714   - test_assert(!ring512.is_empty(), "Check for non-empty sky map");
715   - test_value(ring512.npix(), 3145728, "Check for 3145728 sky map pixels");
716   - test_value(ring512.nx(), 0, "Check for no X-direction map pixels");
717   - test_value(ring512.ny(), 0, "Check for no Y-direction map pixels");
718   - test_value(ring512.nmaps(), 1, "Check for one sky map");
  717 + test_assert(!ring512.is_empty(), "Check for non-empty sky map");
  718 + test_value(ring512.npix(), 3145728, "Check for 3145728 sky map pixels");
  719 + test_value(ring512.nx(), 0, "Check for no X-direction map pixels");
  720 + test_value(ring512.ny(), 0, "Check for no Y-direction map pixels");
  721 + test_value(ring512.nmaps(), 1, "Check for one sky map");
719 722 //
720 723 GSkyMap nest1("GAL", 1, "NEST", 1);
721   - test_assert(!nest1.is_empty(), "Check for non-empty sky map");
722   - test_value(nest1.npix(), 12, "Check for 12 sky map pixels");
723   - test_value(nest1.nx(), 0, "Check for no X-direction map pixels");
724   - test_value(nest1.ny(), 0, "Check for no Y-direction map pixels");
725   - test_value(nest1.nmaps(), 1, "Check for one sky map");
  724 + test_assert(!nest1.is_empty(), "Check for non-empty sky map");
  725 + test_value(nest1.npix(), 12, "Check for 12 sky map pixels");
  726 + test_value(nest1.nx(), 0, "Check for no X-direction map pixels");
  727 + test_value(nest1.ny(), 0, "Check for no Y-direction map pixels");
  728 + test_value(nest1.nmaps(), 1, "Check for one sky map");
726 729 //
727 730 GSkyMap nest2("GAL", 2, "NEST", 1);
728   - test_assert(!nest2.is_empty(), "Check for non-empty sky map");
729   - test_value(nest2.npix(), 48, "Check for 48 sky map pixels");
730   - test_value(nest2.nx(), 0, "Check for no X-direction map pixels");
731   - test_value(nest2.ny(), 0, "Check for no Y-direction map pixels");
732   - test_value(nest2.nmaps(), 1, "Check for one sky map");
  731 + test_assert(!nest2.is_empty(), "Check for non-empty sky map");
  732 + test_value(nest2.npix(), 48, "Check for 48 sky map pixels");
  733 + test_value(nest2.nx(), 0, "Check for no X-direction map pixels");
  734 + test_value(nest2.ny(), 0, "Check for no Y-direction map pixels");
  735 + test_value(nest2.nmaps(), 1, "Check for one sky map");
733 736 //
734 737 GSkyMap nest4("GAL", 4, "NEST", 1);
735   - test_assert(!nest4.is_empty(), "Check for non-empty sky map");
736   - test_value(nest4.npix(), 192, "Check for 192 sky map pixels");
737   - test_value(nest4.nx(), 0, "Check for no X-direction map pixels");
738   - test_value(nest4.ny(), 0, "Check for no Y-direction map pixels");
739   - test_value(nest4.nmaps(), 1, "Check for one sky map");
  738 + test_assert(!nest4.is_empty(), "Check for non-empty sky map");
  739 + test_value(nest4.npix(), 192, "Check for 192 sky map pixels");
  740 + test_value(nest4.nx(), 0, "Check for no X-direction map pixels");
  741 + test_value(nest4.ny(), 0, "Check for no Y-direction map pixels");
  742 + test_value(nest4.nmaps(), 1, "Check for one sky map");
740 743 //
741 744 GSkyMap nest8("GAL", 8, "NEST", 1);
742   - test_assert(!nest8.is_empty(), "Check for non-empty sky map");
743   - test_value(nest8.npix(), 768, "Check for 768 sky map pixels");
744   - test_value(nest8.nx(), 0, "Check for no X-direction map pixels");
745   - test_value(nest8.ny(), 0, "Check for no Y-direction map pixels");
746   - test_value(nest8.nmaps(), 1, "Check for one sky map");
  745 + test_assert(!nest8.is_empty(), "Check for non-empty sky map");
  746 + test_value(nest8.npix(), 768, "Check for 768 sky map pixels");
  747 + test_value(nest8.nx(), 0, "Check for no X-direction map pixels");
  748 + test_value(nest8.ny(), 0, "Check for no Y-direction map pixels");
  749 + test_value(nest8.nmaps(), 1, "Check for one sky map");
747 750 //
748 751 GSkyMap nest16("GAL", 16, "NEST", 1);
749   - test_assert(!nest16.is_empty(), "Check for non-empty sky map");
750   - test_value(nest16.npix(), 3072, "Check for 3072 sky map pixels");
751   - test_value(nest16.nx(), 0, "Check for no X-direction map pixels");
752   - test_value(nest16.ny(), 0, "Check for no Y-direction map pixels");
753   - test_value(nest16.nmaps(), 1, "Check for one sky map");
  752 + test_assert(!nest16.is_empty(), "Check for non-empty sky map");
  753 + test_value(nest16.npix(), 3072, "Check for 3072 sky map pixels");
  754 + test_value(nest16.nx(), 0, "Check for no X-direction map pixels");
  755 + test_value(nest16.ny(), 0, "Check for no Y-direction map pixels");
  756 + test_value(nest16.nmaps(), 1, "Check for one sky map");
754 757 //
755 758 GSkyMap nest32("GAL", 32, "NEST", 1);
756   - test_assert(!nest32.is_empty(), "Check for non-empty sky map");
757   - test_value(nest32.npix(), 12288, "Check for 12288 sky map pixels");
758   - test_value(nest32.nx(), 0, "Check for no X-direction map pixels");
759   - test_value(nest32.ny(), 0, "Check for no Y-direction map pixels");
760   - test_value(nest32.nmaps(), 1, "Check for one sky map");
  759 + test_assert(!nest32.is_empty(), "Check for non-empty sky map");
  760 + test_value(nest32.npix(), 12288, "Check for 12288 sky map pixels");
  761 + test_value(nest32.nx(), 0, "Check for no X-direction map pixels");
  762 + test_value(nest32.ny(), 0, "Check for no Y-direction map pixels");
  763 + test_value(nest32.nmaps(), 1, "Check for one sky map");
761 764 //
762 765 GSkyMap nest64("GAL", 64, "NEST", 1);
763   - test_assert(!nest64.is_empty(), "Check for non-empty sky map");
764   - test_value(nest64.npix(), 49152, "Check for 49152 sky map pixels");
765   - test_value(nest64.nx(), 0, "Check for no X-direction map pixels");
766   - test_value(nest64.ny(), 0, "Check for no Y-direction map pixels");
767   - test_value(nest64.nmaps(), 1, "Check for one sky map");
  766 + test_assert(!nest64.is_empty(), "Check for non-empty sky map");
  767 + test_value(nest64.npix(), 49152, "Check for 49152 sky map pixels");
  768 + test_value(nest64.nx(), 0, "Check for no X-direction map pixels");
  769 + test_value(nest64.ny(), 0, "Check for no Y-direction map pixels");
  770 + test_value(nest64.nmaps(), 1, "Check for one sky map");
768 771 //
769 772 GSkyMap nest128("GAL", 128, "NEST", 1);
770   - test_assert(!nest128.is_empty(), "Check for non-empty sky map");
771   - test_value(nest128.npix(), 196608, "Check for 196608 sky map pixels");
772   - test_value(nest128.nx(), 0, "Check for no X-direction map pixels");
773   - test_value(nest128.ny(), 0, "Check for no Y-direction map pixels");
774   - test_value(nest128.nmaps(), 1, "Check for one sky map");
  773 + test_assert(!nest128.is_empty(), "Check for non-empty sky map");
  774 + test_value(nest128.npix(), 196608, "Check for 196608 sky map pixels");
  775 + test_value(nest128.nx(), 0, "Check for no X-direction map pixels");
  776 + test_value(nest128.ny(), 0, "Check for no Y-direction map pixels");
  777 + test_value(nest128.nmaps(), 1, "Check for one sky map");
775 778 //
776 779 GSkyMap nest256("GAL", 256, "NEST", 1);
777   - test_assert(!nest256.is_empty(), "Check for non-empty sky map");
778   - test_value(nest256.npix(), 786432, "Check for 786432 sky map pixels");
779   - test_value(nest256.nx(), 0, "Check for no X-direction map pixels");
780   - test_value(nest256.ny(), 0, "Check for no Y-direction map pixels");
781   - test_value(nest256.nmaps(), 1, "Check for one sky map");
  780 + test_assert(!nest256.is_empty(), "Check for non-empty sky map");
  781 + test_value(nest256.npix(), 786432, "Check for 786432 sky map pixels");
  782 + test_value(nest256.nx(), 0, "Check for no X-direction map pixels");
  783 + test_value(nest256.ny(), 0, "Check for no Y-direction map pixels");
  784 + test_value(nest256.nmaps(), 1, "Check for one sky map");
782 785 //
783 786 GSkyMap nest512("GAL", 512, "NEST", 1);
784   - test_assert(!nest512.is_empty(), "Check for non-empty sky map");
785   - test_value(nest512.npix(), 3145728, "Check for 3145728 sky map pixels");
786   - test_value(nest512.nx(), 0, "Check for no X-direction map pixels");
787   - test_value(nest512.ny(), 0, "Check for no Y-direction map pixels");
788   - test_value(nest512.nmaps(), 1, "Check for one sky map");
  787 + test_assert(!nest512.is_empty(), "Check for non-empty sky map");
  788 + test_value(nest512.npix(), 3145728, "Check for 3145728 sky map pixels");
  789 + test_value(nest512.nx(), 0, "Check for no X-direction map pixels");
  790 + test_value(nest512.ny(), 0, "Check for no Y-direction map pixels");
  791 + test_value(nest512.nmaps(), 1, "Check for one sky map");
789 792 //
790 793 GSkyMap map1("CEL", 1, "RING", 1);
791   - test_assert(!map1.is_empty(), "Check for non-empty sky map");
792   - test_value(map1.npix(), 12, "Check for 12 sky map pixels");
793   - test_value(map1.nx(), 0, "Check for no X-direction map pixels");
794   - test_value(map1.ny(), 0, "Check for no Y-direction map pixels");
795   - test_value(map1.nmaps(), 1, "Check for one sky map");
  794 + test_assert(!map1.is_empty(), "Check for non-empty sky map");
  795 + test_value(map1.npix(), 12, "Check for 12 sky map pixels");
  796 + test_value(map1.nx(), 0, "Check for no X-direction map pixels");
  797 + test_value(map1.ny(), 0, "Check for no Y-direction map pixels");
  798 + test_value(map1.nmaps(), 1, "Check for one sky map");
796 799 //
797 800 GSkyMap map2("CEL", 1, "NESTED", 2);
798   - test_assert(!map2.is_empty(), "Check for non-empty sky map");
799   - test_value(map2.npix(), 12, "Check for 12 sky map pixels");
800   - test_value(map2.nx(), 0, "Check for no X-direction map pixels");
801   - test_value(map2.ny(), 0, "Check for no Y-direction map pixels");
802   - test_value(map2.nmaps(), 2, "Check for one sky map");
  801 + test_assert(!map2.is_empty(), "Check for non-empty sky map");
  802 + test_value(map2.npix(), 12, "Check for 12 sky map pixels");
  803 + test_value(map2.nx(), 0, "Check for no X-direction map pixels");
  804 + test_value(map2.ny(), 0, "Check for no Y-direction map pixels");
  805 + test_value(map2.nmaps(), 2, "Check for one sky map");
803 806  
804 807 // Test Healpix copy constructor
805 808 GSkyMap ring1cpy = ring1;
... ... @@ -892,7 +895,7 @@ void TestGSky::test_GSkyMap_healpix_io(void)
892 895 refmap(pix) = pix+1;
893 896 refmap.save(file1, true);
894 897  
895   - test_try_success();
  898 + test_try_success();
896 899 }
897 900 catch (std::exception &e) {
898 901 test_try_failure(e);
... ... @@ -912,7 +915,7 @@ void TestGSky::test_GSkyMap_healpix_io(void)
912 915 throw exception_error("Loaded file differs from saved file.");
913 916 }
914 917  
915   - test_try_success();
  918 + test_try_success();
916 919 }
917 920 catch (std::exception &e) {
918 921 test_try_failure(e);
... ... @@ -930,7 +933,7 @@ void TestGSky::test_GSkyMap_healpix_io(void)
930 933 if (diff > 0) {
931 934 throw exception_error("Loaded file differs from saved file.");
932 935 }
933   - test_try_success();
  936 + test_try_success();
934 937 }
935 938 catch (std::exception &e) {
936 939 test_try_failure(e);
... ... @@ -1291,7 +1294,7 @@ void TestGSky::test_GSkyMap(void)
1291 1294 }
1292 1295 }
1293 1296 test_value(total_more, total_src, 1.0e-3, "Test nmaps() method with more maps");
1294   - test_value(map_more.nmaps(), 4, "Test nmaps() method with more maps");
  1297 + test_value(map_more.nmaps(), 4, "Test nmaps() method with more maps");
1295 1298 GSkyMap map_less = map_src;
1296 1299 map_less.nmaps(1);
1297 1300 double total_less = 0.0;
... ... @@ -1301,7 +1304,7 @@ void TestGSky::test_GSkyMap(void)
1301 1304 }
1302 1305 }
1303 1306 test_value(total_less, 0.5*total_src, 1.0e-3, "Test nmaps() method with less maps");
1304   - test_value(map_less.nmaps(), 1, "Test nmaps() method with less maps");
  1307 + test_value(map_less.nmaps(), 1, "Test nmaps() method with less maps");
1305 1308  
1306 1309 // Test map extraction
1307 1310 GSkyMap map_extract = map_src.extract(0);
... ... @@ -1312,7 +1315,7 @@ void TestGSky::test_GSkyMap(void)
1312 1315 }
1313 1316 }
1314 1317 test_value(total_extract, 0.5*total_src, 1.0e-3, "Test extract() method with 1 map");
1315   - test_value(map_extract.nmaps(), 1, "Test extract() method with 1 map");
  1318 + test_value(map_extract.nmaps(), 1, "Test extract() method with 1 map");
1316 1319 map_extract = map_src.extract(0,2);
1317 1320 total_extract = 0.0;
1318 1321 for (int k = 0; k < map_extract.nmaps(); ++k) {
... ... @@ -1321,7 +1324,7 @@ void TestGSky::test_GSkyMap(void)
1321 1324 }
1322 1325 }
1323 1326 test_value(total_extract, total_src, 1.0e-3, "Test extract() method with 2 maps");
1324   - test_value(map_extract.nmaps(), 2, "Test extract() method with 2 maps");
  1327 + test_value(map_extract.nmaps(), 2, "Test extract() method with 2 maps");
1325 1328  
1326 1329 // Define one more map for shaping manipulation
1327 1330 GSkyMap map_shape0("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10);
... ... @@ -1596,25 +1599,25 @@ void TestGSky::test_GSkyMap_io(void)
1596 1599  
1597 1600 // Load HEALPix map and check content
1598 1601 GSkyMap map1(filename+"[HEALPIX1]");
1599   - test_value(map1.npix(), healpix1.npix(), "Check number of HEALPix pixels");
  1602 + test_value(map1.npix(), healpix1.npix(), "Check number of HEALPix pixels");
1600 1603 int failures1(0);
1601 1604 for (int i = 0; i < map1.npix(); ++i) {
1602 1605 if (std::abs(map1(i)-double(i+1)) > 1.0e-6) {
1603 1606 failures1++;
1604 1607 }
1605 1608 }
1606   - test_value(failures1, 0, "Check number of invalid HEALPix pixel values");
  1609 + test_value(failures1, 0, "Check number of invalid HEALPix pixel values");
1607 1610  
1608 1611 // Load WCS1 map and check content
1609 1612 GSkyMap map2(filename+"[WCS1]");
1610   - test_value(map2.npix(), wcs1.npix(), "Check number of WCS pixels");
  1613 + test_value(map2.npix(), wcs1.npix(), "Check number of WCS pixels");
1611 1614 int failures2(0);
1612 1615 for (int i = 0; i < map2.npix(); ++i) {
1613 1616 if (std::abs(map2(i)-double(i+1)) > 1.0e-6) {
1614 1617 failures2++;
1615 1618 }
1616 1619 }
1617   - test_value(failures2, 0, "Check number of invalid WCS pixel values");
  1620 + test_value(failures2, 0, "Check number of invalid WCS pixel values");
1618 1621  
1619 1622 // Load WCS3 map and check content
1620 1623 GSkyMap map3(filename+"[WCS3]");
... ... @@ -1644,15 +1647,15 @@ void TestGSky::test_GSkyMap_io(void)
1644 1647 // Allocate regions
1645 1648 GSkyRegions regions;
1646 1649  
1647   - // Test regions loading
1648   - test_try("Test regions loading");
1649   - try {
1650   - regions.load(sky_region);
1651   - test_try_success();
1652   - }
1653   - catch (std::exception &e) {
1654   - test_try_failure(e);
1655   - }
  1650 + // Test regions loading
  1651 + test_try("Test regions loading");
  1652 + try {
  1653 + regions.load(sky_region);
  1654 + test_try_success();
  1655 + }
  1656 + catch (std::exception &e) {
  1657 + test_try_failure(e);
  1658 + }
1656 1659  
1657 1660 // Check if region was loaded correctly
1658 1661 test_value(regions.size(), 5, "5 sky regions expected");
... ... @@ -1667,25 +1670,25 @@ void TestGSky::test_GSkyMap_io(void)
1667 1670 test_value(regions[3]->name(), "Test 2", "Name \"Test 2\" for fourth sky region");
1668 1671 test_value(regions[4]->name(), "Test 3", "Name \"Test 3\" for fifth sky region");
1669 1672  
1670   - // Test regions saving
1671   - test_try("Test regions saving");
1672   - try {
1673   - regions.save("region.reg");
1674   - test_try_success();
1675   - }
1676   - catch (std::exception &e) {
1677   - test_try_failure(e);
1678   - }
  1673 + // Test regions saving
  1674 + test_try("Test regions saving");
  1675 + try {
  1676 + regions.save("region.reg");
  1677 + test_try_success();
  1678 + }
  1679 + catch (std::exception &e) {
  1680 + test_try_failure(e);
  1681 + }
1679 1682  
1680   - // Test regions reloading
1681   - test_try("Test regions reloading");
1682   - try {
1683   - regions.load("region.reg");
1684   - test_try_success();
1685   - }
1686   - catch (std::exception &e) {
1687   - test_try_failure(e);
1688   - }
  1683 + // Test regions reloading
  1684 + test_try("Test regions reloading");
  1685 + try {
  1686 + regions.load("region.reg");
  1687 + test_try_success();
  1688 + }
  1689 + catch (std::exception &e) {
  1690 + test_try_failure(e);
  1691 + }
1689 1692  
1690 1693 // Check if region was loaded correctly
1691 1694 test_value(regions.size(), 5, "5 sky regions expected");
... ... @@ -1818,7 +1821,243 @@ void TestGSky::test_GSkyRegionCircle(void)
1818 1821  
1819 1822  
1820 1823 /***************************************************************************
1821   - * @brief Test GSkyRegionMap
  1824 + * @brief GSkyRegionRect
  1825 + ***************************************************************************/
  1826 +void TestGSky::test_GSkyRegionRect(void)
  1827 +{
  1828 + // Define region for comparison
  1829 + GSkyDir refdir_radeczerozero = GSkyDir();
  1830 + refdir_radeczerozero.radec_deg(0,0);
  1831 + double ref_width = 1.;
  1832 + double ref_height = 1.;
  1833 + double ref_pa_deg = 0.;
  1834 +
  1835 + // Test constructing
  1836 + test_try("Test constructor");
  1837 + try {
  1838 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1839 + test_try_success();
  1840 + }
  1841 + catch (std::exception &e) {
  1842 + test_try_failure(e);
  1843 + }
  1844 +
  1845 + // Test constructing with negative width (should be forbidden)
  1846 + test_try("Test constructor2");
  1847 + try {
  1848 + GSkyRegionRect rect(refdir_radeczerozero, -1, ref_height, ref_pa_deg);
  1849 + test_try_failure();
  1850 + }
  1851 + catch (GException::invalid_argument &e) {
  1852 + test_try_success();
  1853 + }
  1854 + catch (std::exception &e) {
  1855 + test_try_failure(e);
  1856 + }
  1857 +
  1858 + // Test constructing with negative height (should be forbidden)
  1859 + test_try("Test constructor3");
  1860 + try {
  1861 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, -1, ref_pa_deg);
  1862 + test_try_failure();
  1863 + }
  1864 + catch (GException::invalid_argument &e) {
  1865 + test_try_success();
  1866 + }
  1867 + catch (std::exception &e) {
  1868 + test_try_failure(e);
  1869 + }
  1870 +
  1871 + // Test constructing with negative posang (should be allowed)
  1872 + test_try("Test constructor4");
  1873 + try {
  1874 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, -1);
  1875 + test_try_success();
  1876 + }
  1877 + catch (GException::invalid_argument &e) {
  1878 + test_try_failure();
  1879 + }
  1880 + catch (std::exception &e) {
  1881 + test_try_failure(e);
  1882 + }
  1883 +
  1884 + // Test assignment of neg width after construction
  1885 + test_try("Test width assignment after");
  1886 + try {
  1887 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1888 + rect.width(-1.0);
  1889 + test_try_failure();
  1890 + }
  1891 + catch (GException::invalid_argument &e) {
  1892 + test_try_success();
  1893 + }
  1894 + catch (std::exception &e) {
  1895 + test_try_failure(e);
  1896 + }
  1897 +
  1898 + // Test assignment of neg height after construction
  1899 + test_try("Test height assignment after");
  1900 + try {
  1901 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1902 + rect.height(-1.0);
  1903 + test_try_failure();
  1904 + }
  1905 + catch (GException::invalid_argument &e) {
  1906 + test_try_success();
  1907 + }
  1908 + catch (std::exception &e) {
  1909 + test_try_failure(e);
  1910 + }
  1911 +
  1912 + // Test assignment of neg posang after construction
  1913 + test_try("Test posang assignment after");
  1914 + try {
  1915 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1916 + rect.posang_deg(-1.0);
  1917 + test_try_success();
  1918 + }
  1919 + catch (GException::invalid_argument &e) {
  1920 + test_try_failure();
  1921 + }
  1922 + catch (std::exception &e) {
  1923 + test_try_failure(e);
  1924 + }
  1925 +
  1926 + // Check radius assignment
  1927 + GSkyRegionRect rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1928 +
  1929 + double check_width = rect.width();
  1930 + test_value(ref_width, check_width, 1.0e-10, "Test width assignment");
  1931 +
  1932 + double check_height = rect.width();
  1933 + test_value(ref_height, check_height, 1.0e-10, "Test height assignment");
  1934 +
  1935 + double check_pa_deg = rect.posang_deg();
  1936 + test_value(ref_pa_deg, check_pa_deg, 1.0e-10, "Test posang assignment");
  1937 +
  1938 + // Check solid angle assignment
  1939 + double solidangle_check = rect.solidangle();
  1940 + double solidangle = ref_width*gammalib::deg2rad * ref_height*gammalib::deg2rad;
  1941 + test_value(solidangle_check, solidangle, 1.0e-10, "Test solid angle");
  1942 +
  1943 + // Initialise objects
  1944 + GSkyDir refdir_radeczerozero = GSkyDir();
  1945 + GSkyDir test_dir_0 = GSkyDir();
  1946 + GSkyDir test_dir_1 = GSkyDir();
  1947 + GSkyDir test_dir_2 = GSkyDir();
  1948 +
  1949 + refdir_radeczerozero.radec_deg(0,0);
  1950 + GSkyRegionRect refregion(refdir_radeczerozero, 10, 6, 0);
  1951 +
  1952 + // Check GSkyDir containment
  1953 + // Upper right
  1954 + test_dir_0.radec_deg(6, 2);
  1955 + test_dir_1.radec_deg(4, 2);
  1956 + test_dir_2.radec_deg(4, 4);
  1957 + test_assert(!refregion.contains(test_dir_0),"test for containment");
  1958 + test_assert(refregion.contains(test_dir_1),"test for containment");
  1959 + test_assert(!refregion.contains(test_dir_2),"test for containment");
  1960 +
  1961 + // Upper left
  1962 + test_dir_0.radec_deg(-6, 2);
  1963 + test_dir_1.radec_deg(-4, 2);
  1964 + test_dir_2.radec_deg(-4, 4);
  1965 + test_assert(!refregion.contains(test_dir_0),"test for containment");
  1966 + test_assert(refregion.contains(test_dir_1),"test for containment");
  1967 + test_assert(!refregion.contains(test_dir_2),"test for containment");
  1968 +
  1969 + // Lower left
  1970 + test_dir_0.radec_deg(-6, -2);
  1971 + test_dir_1.radec_deg(-4, -2);
  1972 + test_dir_2.radec_deg(-4, -4);
  1973 + test_assert(!refregion.contains(test_dir_0),"test for containment");
  1974 + test_assert(refregion.contains(test_dir_1),"test for containment");
  1975 + test_assert(!refregion.contains(test_dir_2),"test for containment");
  1976 +
  1977 + // Lower right
  1978 + test_dir_0.radec_deg(6, -2);
  1979 + test_dir_1.radec_deg(4, -2);
  1980 + test_dir_2.radec_deg(4, -4);
  1981 + test_assert(!refregion.contains(test_dir_0),"test for containment");
  1982 + test_assert(refregion.contains(test_dir_1),"test for containment");
  1983 + test_assert(!refregion.contains(test_dir_2),"test for containment");
  1984 +
  1985 + // Corners
  1986 + test_assert(refregion.contains(refregion.get_corner(0)),"test for corner containment");
  1987 + test_assert(refregion.contains(refregion.get_corner(1)),"test for corner containment");
  1988 + test_assert(refregion.contains(refregion.get_corner(2)),"test for corner containment");
  1989 + test_assert(refregion.contains(refregion.get_corner(3)),"test for corner containment");
  1990 +
  1991 +
  1992 + // Check GSkyDir containment for rotated rectangle
  1993 + GSkyRegionRect refregion_rot(refdir_radeczerozero, 10, 10, 45);
  1994 +
  1995 + // Check corner containment
  1996 + test_assert(refregion_rot.contains(refregion_rot.get_corner(0)),"test for corner containment");
  1997 + test_assert(refregion_rot.contains(refregion_rot.get_corner(1)),"test for corner containment");
  1998 + test_assert(refregion_rot.contains(refregion_rot.get_corner(2)),"test for corner containment");
  1999 + test_assert(refregion_rot.contains(refregion_rot.get_corner(3)),"test for corner containment");
  2000 +
  2001 + // Check GSkyDir containment
  2002 + test_dir_0.radec_deg(refregion_rot.get_corner(0).ra_deg()+1, 0);
  2003 + test_dir_1.radec_deg(refregion_rot.get_corner(0).ra_deg() , 0);
  2004 + test_dir_2.radec_deg(refregion_rot.get_corner(0).ra_deg()-1, 0);
  2005 + test_assert(!refregion_rot.contains(test_dir_0),"test for containment");
  2006 + test_assert(refregion_rot.contains(test_dir_1),"test for containment");
  2007 + test_assert(refregion_rot.contains(test_dir_2),"test for containment");
  2008 +
  2009 + // Check local<->global coordinate transformations
  2010 + test_dir_0.radec_deg(50,50);
  2011 + test_dir_1 = refregion_rot.transform_to_local(test_dir_0);
  2012 + test_dir_2 = refregion_rot.transform_to_global(test_dir_1);
  2013 + test_value(test_dir_0.ra(), test_dir_2.ra(), 1.0e-10, "Test coord trafo");
  2014 + test_value(test_dir_0.dec(), test_dir_2.dec(), 1.0e-10, "Test coord trafo");
  2015 +
  2016 + // Check other rects containment
  2017 + GSkyDir refdir_raoffset = GSkyDir();
  2018 + refdir_raoffset.radec_deg(5,0);
  2019 +
  2020 + GSkyDir refdir_rapole = GSkyDir();
  2021 + refdir_rapole.radec_deg(359,0);
  2022 +
  2023 + GSkyDir refdir_decpole = GSkyDir();
  2024 + refdir_decpole.radec_deg(0,89);
  2025 +
  2026 + GSkyDir refdir_ndecpole = GSkyDir();
  2027 + refdir_ndecpole.radec_deg(100,89);
  2028 +
  2029 + GSkyRegionRect refregion_smaller(refdir_radeczerozero, 5, 3, 0);
  2030 + GSkyRegionRect refregion_larger(refdir_radeczerozero, 20, 12, 0);
  2031 + GSkyRegionRect refregion_raoffset(refdir_raoffset, 10, 6, 0);
  2032 + GSkyRegionRect refregion_rapole(refdir_rapole, 3, 3, 0);
  2033 + GSkyRegionRect refregion_decpole(refdir_decpole, 3, 3, 0);
  2034 +
  2035 + // Test contain dirs (same from circle)
  2036 + test_assert(refregion.contains(refdir_radeczerozero),"test for containment");
  2037 + test_assert(refregion.contains(refregion.centre()), "test if centre in rectangle");
  2038 +
  2039 + // Test contain regions (same from circle)
  2040 + test_assert(refregion.contains(refregion_smaller),"test for containment region");
  2041 + test_assert(!refregion.contains(refregion_larger), "test for containment region2 ");
  2042 + test_assert(refregion.contains(refregion), "test3 for containment region");
  2043 +
  2044 + test_assert(refregion.contains(refdir_rapole), "rapole for containment region");
  2045 + test_assert(refregion_decpole.contains(refdir_ndecpole), "rapole for containment region");
  2046 +
  2047 + // Test overlaps (same from circle)
  2048 + test_assert(refregion.overlaps(refregion_smaller),"test for overlap");
  2049 + test_assert(refregion.overlaps(refregion_larger),"test2 for overlap");
  2050 + test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap");
  2051 + test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap");
  2052 +
  2053 +
  2054 + // Exit test
  2055 + return;
  2056 +}
  2057 +
  2058 +
  2059 +/***************************************************************************
  2060 + * @brief GSkyRegionMap_construct
1822 2061 ***************************************************************************/
1823 2062 void TestGSky::test_GSkyRegionMap(void)
1824 2063 {
... ... @@ -1853,14 +2092,17 @@ void TestGSky::test_GSkyRegionMap(void)
1853 2092 refdir_radeczerozero.radec_deg(0.0,0.0);
1854 2093 refdir_radeclargeshift.radec_deg(2.0,0.0);
1855 2094 refdir_radecsmallshift.radec_deg(0.3,0.0);
1856   - GSkyRegionCircle inregion(refdir_radeczerozero,0.2);
1857   - GSkyRegionCircle outregion(refdir_radeclargeshift,0.2);
1858   - GSkyRegionCircle overregion(refdir_radecsmallshift,0.3);
1859 2095  
1860 2096 // Test contains dirs
1861 2097 test_assert(regmap.contains(refdir_radeczerozero),"test for direction containment");
1862 2098 test_assert(!regmap.contains(refdir_radeclargeshift),"test2 for direction containment");
1863 2099  
  2100 +
  2101 + // Test circles
  2102 + GSkyRegionCircle inregion(refdir_radeczerozero,0.2);
  2103 + GSkyRegionCircle outregion(refdir_radeclargeshift,0.2);
  2104 + GSkyRegionCircle overregion(refdir_radecsmallshift,0.3);
  2105 +
1864 2106 // Test contains regions
1865 2107 test_assert(regmap.contains(inregion),"test for region containment");
1866 2108 test_assert(!regmap.contains(outregion),"test2 for region containment");
... ... @@ -1869,6 +2111,21 @@ void TestGSky::test_GSkyRegionMap(void)
1869 2111 test_assert(regmap.overlaps(inregion),"test for region overlap");
1870 2112 test_assert(regmap.overlaps(overregion),"test2 for region overlap");
1871 2113  
  2114 +
  2115 + // Test rectangles
  2116 + GSkyRegionRect inrect(refdir_radeczerozero, 0.3, 0.3, 0);
  2117 + GSkyRegionRect outrect(refdir_radeclargeshift, 0.3, 0.3, 0);
  2118 + GSkyRegionRect overrect(refdir_radecsmallshift, 0.3, 0.3, 0);
  2119 +
  2120 + // Test contains regions
  2121 + test_assert(regmap.contains(inrect),"test for region containment");
  2122 + test_assert(!regmap.contains(outrect),"test2 for region containment");
  2123 +
  2124 + // Test overlaps regions
  2125 + test_assert(regmap.overlaps(inrect),"test for region overlap");
  2126 + test_assert(regmap.overlaps(overrect),"test2 for region overlap");
  2127 +
  2128 +
1872 2129 // Exit test
1873 2130 return;
1874 2131 }
... ...
test/test_GSky.hpp
... ... @@ -53,6 +53,7 @@ public:
53 53 void test_GSkyMap_io(void);
54 54 void test_GSkyRegions(void);
55 55 void test_GSkyRegionCircle(void);
  56 + void test_GSkyRegionRect(void);
56 57 void test_GSkyRegionMap(void);
57 58 void test_GHorizDir(void);
58 59  
... ...