Exemplo n.º 1
0
 def test_random(self):
     # Make sure the returned filter is a valid one
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertTrue(pfilter.system in Passband.ALL_SYSTEMS)
         # Neither custom nor H-alpha filters have letter
         if pfilter.system not in [CUSTOM, HALPHA]:
             self.assertTrue(pfilter.letter in Passband.SYSTEM_LETTERS[pfilter.system])
Exemplo n.º 2
0
 def test_random(self):
     # Make sure the returned filter is a valid one
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertTrue(pfilter.system in Passband.ALL_SYSTEMS)
         # Neither custom nor H-alpha filters have letter
         if pfilter.system not in [CUSTOM, HALPHA]:
             self.assertTrue(
                 pfilter.letter in Passband.SYSTEM_LETTERS[pfilter.system])
Exemplo n.º 3
0
    def test_cmp(self):
        def assert_max(index, *names):
            """ Make sure that Passband(names[index]) is the largest item """
            pfilters = [Passband(x) for x in names]
            self.assertEqual(max(pfilters), pfilters[index])

        assert_max(1, "Johnson B", "Cousins R")
        assert_max(0, "SDSS Z", "Gunn U")
        assert_max(1, "Johnson V", "SDSS I")
        assert_max(0, "2MASS KS", "Johnson R")
        assert_max(1, "Cousins I", "2MASS J")
        assert_max(0, "Gunn G", "Stromgren B")

        def letter_index(letter):
            """ Return the position of a letter in Passband.LETTERS_ORDER """
            return Passband.LETTERS_ORDER.index(letter)

        # Now sort a series of lists of random Passband objects
        for _ in xrange(NITERS):

            pfilters = [Passband.random() for x in xrange(NPASSBANDS)]
            pfilters.sort()

            for index in xrange(0, len(pfilters) - 1):
                first = pfilters[index]
                second = pfilters[index + 1]
                ncustoms = sum(1 for p in [first, second]
                               if p.system == CUSTOM)
                nhalphas = sum(1 for p in [first, second]
                               if p.system == HALPHA)

                if not nhalphas and not ncustoms:
                    first_index = letter_index(first.letter)
                    second_index = letter_index(second.letter)
                    self.assertTrue(first_index <= second_index)
                    # If letters are equal, sort lexicographically by the system
                    if first.letter == second.letter:
                        self.assertTrue(first.system <= second.system)

                # Custom filters are smaller than others system
                elif ncustoms == 1:
                    first.system == CUSTOM
                    second.system != CUSTOM

                elif ncustoms == 2:
                    # Two custom filters are compared lexicographically
                    self.assertTrue(first.letter <= second.letter)

                # H-alpha filters are greater than other systems
                elif nhalphas == 1:
                    first.system != HALPHA
                    second.system == HALPHA

                else:
                    assert nhalphas == 2
                    self.assertTrue(int(first.letter) <= int(second.letter))
Exemplo n.º 4
0
    def test_cmp(self):

        def assert_max(index, *names):
            """ Make sure that Passband(names[index]) is the largest item """
            pfilters = [Passband(x) for x in names]
            self.assertEqual(max(pfilters), pfilters[index])

        assert_max(1, "Johnson B", "Cousins R")
        assert_max(0, "SDSS Z", "Gunn U")
        assert_max(1, "Johnson V", "SDSS I")
        assert_max(0, "2MASS KS", "Johnson R")
        assert_max(1, "Cousins I", "2MASS J")
        assert_max(0, "Gunn G", "Stromgren B")

        def letter_index(letter):
            """ Return the position of a letter in Passband.LETTERS_ORDER """
            return Passband.LETTERS_ORDER.index(letter)

        # Now sort a series of lists of random Passband objects
        for _ in xrange(NITERS):

            pfilters = [Passband.random() for x in xrange(NPASSBANDS)]
            pfilters.sort()

            for index in xrange(0, len(pfilters) - 1):
                first  = pfilters[index]
                second = pfilters[index + 1]
                ncustoms = sum(1 for p in [first, second] if p.system == CUSTOM)
                nhalphas = sum(1 for p in [first, second] if p.system == HALPHA)

                if not nhalphas and not ncustoms:
                    first_index  = letter_index(first.letter)
                    second_index = letter_index(second.letter)
                    self.assertTrue(first_index <= second_index)
                    # If letters are equal, sort lexicographically by the system
                    if first.letter == second.letter:
                        self.assertTrue(first.system <= second.system)

                # Custom filters are smaller than others system
                elif ncustoms == 1:
                    first.system  == CUSTOM
                    second.system != CUSTOM

                elif ncustoms == 2:
                    # Two custom filters are compared lexicographically
                    self.assertTrue(first.letter <= second.letter)

                # H-alpha filters are greater than other systems
                elif nhalphas == 1:
                    first.system  != HALPHA
                    second.system == HALPHA

                else:
                    assert nhalphas == 2
                    self.assertTrue(int(first.letter) <= int(second.letter))
Exemplo n.º 5
0
 def test_different(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertNotEqual(pfilter, pfilter.different())
Exemplo n.º 6
0
 def test_hash(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertEqual(hash(pfilter), hash(eval( ` pfilter `)))
         self.assertNotEqual(hash(pfilter), hash(pfilter.different()))
Exemplo n.º 7
0
 def test_repr(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertEqual(pfilter, eval( ` pfilter `))
Exemplo n.º 8
0
 def test_different(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertNotEqual(pfilter, pfilter.different())
Exemplo n.º 9
0
 def test_hash(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertEqual(hash(pfilter), hash(eval(`pfilter`)))
         self.assertNotEqual(hash(pfilter), hash(pfilter.different()))
Exemplo n.º 10
0
 def test_repr(self):
     for _ in xrange(NITERS):
         pfilter = Passband.random()
         self.assertEqual(pfilter, eval(`pfilter`))