def test_index_too_short_term(self):
        """ValueError on excessively short search terms

        Verifies that using search terms that are shorter than a
        combinatorial unit's r-value (when set) raises a ValueError.
        Setting an r-value should cause the CU to produce results of
        length r only.

        This verification is repeated for different values of n and r.

        """

        # NOTE: For this test, the minimum values for r and n have been 
        # been set to 2, as r <= n and when r=1 the only shorter search
        # term would be an empty sequence. 
        # 
        # Testing for empty search terms is handled by 
        # test_index_empty_term()
        #
        for n in range(2, TEST_MAX_N+1):
            for r in range(2, n+1):
                src = examples.get_latin_upper_alphas(n)
                combu = self.combu_class(src, r)
                with self.subTest(n=n, r=r):
                    with self.assertRaises(ValueError):
                        term = src[0]
                        combu.index(term)
Beispiel #2
0
 def test_out_seq(self):
     for n in range(TEST_MIN_N, TEST_MAX_N + 1):
         for r in range(0, n + 1):
             seq = examples.get_latin_upper_alphas(n)
             ref_iter = itertools.combinations_with_replacement(seq, r)
             cand_seq = CombinationWithRepeats(seq, r=r)
             with self.subTest(r=r):
                 self.verify_output(cand_seq, ref_iter)
Beispiel #3
0
 def test_out_seq(self):
     for n in range(TEST_MIN_N, TEST_MAX_N + 1):
         for r in range(0, n + 1):
             # Prepare reference test data
             seq = examples.get_latin_upper_alphas(n)
             ref_iter = itertools.permutations(seq, r)
             cand_seq = Permutation(seq, r=r)
             with self.subTest(r=r):
                 self.verify_output(cand_seq, ref_iter)
    def test_index_none_term(self):
        """ValueError when None is used as a search term.

        Verifies that using None as a search term raises a TypeError.

        This verification is repeated for different values of n and r.

        """
        for n in range(TEST_MIN_N, TEST_MAX_N+1):
            for r in range(n+1):
                src = examples.get_latin_upper_alphas(n)
                combu = self.combu_class(src, r)
                with self.subTest(n=n, r=r):
                    with self.assertRaises(TypeError):
                        combu.index(None)
    def test_index_no_i_no_j(self):
        """Result of index() with no i and no j.

        Verification is done by requesting every item of the sequence,
        and then checking the index used in requesting the item with the
        result of index().

        This verification is repeated for different values of n and r.
        """
        for n in range(TEST_MIN_N, TEST_MAX_N+1):
            for r in range(n+1):
                src = examples.get_latin_upper_alphas(n)
                combu = self.combu_class(src, r)
                for i in range(len(combu)):
                    out = combu[i]
                    with self.subTest(n=n, r=r, i=i, out=out):
                        self.assertEqual(i, combu.index(out))
    def test_index_empty_term(self):
        """ValueError when an the default value is used as search term
        
        Verifies that using the default value as a search term on a valid
        combinatorial unit raises a ValueError.

        This verification is repeated for different values of n and r.
        """
        for n in range(TEST_MIN_N, TEST_MAX_N+1):
            for r in range(1,n+1):
                # Skip r=0, because CUs with a zero r-value are
                # not valid and will not raise ValueError when
                # an attempt is made to find the index of the
                # default value
                src = examples.get_latin_upper_alphas(n)
                combu = self.combu_class(src, r)
                with self.subTest(n=n, r=r):
                    with self.assertRaises(ValueError):
                        combu.index(combu._default)
    def test_index_too_long_term(self):
        """ValueError on excessively long search terms
        
        Verifies that using search terms that are longer than a
        combinatorial unit's r-value (when set) raises a ValueError.
        Setting an r-value should cause the CU to produce results of
        length r only.

        This verification is repeated for different values of n and r.

        """
        for n in range(TEST_MIN_N, TEST_MAX_N+1):
            for r in range(n+1):
                src = examples.get_latin_upper_alphas(n)
                combu = self.combu_class(src, r)
                with self.subTest(n=n, r=r):
                    with self.assertRaises(ValueError):
                        term = src*10
                        combu.index(term)