Ejemplo n.º 1
0
    def setUp(self):
        """
        create basic permutations to call
        """

        self.id = Perm([])
        self.perm1 = Perm(((1, 2, 3), ))
Ejemplo n.º 2
0
 def test_inv(self):
     
     p = Perm((1,2,3))
     pi = p.inv()
     l = ['a', 4, {'tree':3}]
     self.assertEqual((p*pi).list, [0])
     self.assertEqual(l, (p*pi)(l))
Ejemplo n.º 3
0
    def test_inv(self):

        p = Perm((1, 2, 3))
        pi = p.inv()
        l = ['a', 4, {'tree': 3}]
        self.assertEqual((p * pi).list, [0])
        self.assertEqual(l, (p * pi)(l))
Ejemplo n.º 4
0
    def test_init_perm(self):
        """
        test that it just copies the permutation object
        """
        p = Perm(((1, 2, 3), ))
        q = Perm(p)

        self.assertEqual(p.cycles, q.cycles)
        self.assertEqual(q.list, p.list)
        self.assertFalse(p is q)
        self.assertFalse(p.list is q.list)
Ejemplo n.º 5
0
 def test_format_list_identity(self):
     """
     tests that any identity list become [0]
     """
     
     l = [0,1,2,3,4]
     self.assertEqual([0], Perm.format_list(l))
Ejemplo n.º 6
0
 def test_validate_list_negative(self):
     """
     test that a negative entry fails
     """
     
     neg_list = [-2,1]
     self.assertFalse(Perm.validate_list(neg_list))
Ejemplo n.º 7
0
 def test_validate_list_incomplete(self):
     """
     test that an incomplete (lacking 0 or 1) list fails
     """
     
     incomplete_list = [2,3]
     self.assertFalse(Perm.validate_list(incomplete_list))
Ejemplo n.º 8
0
 def test_format_list_decrease(self):
     """
     tests that lists not containing 0 are decreased
     """
     originalList = [1, 3, 2]
     decreasedList = [0, 2, 1]
     self.assertEqual(decreasedList, Perm.format_list(originalList))
Ejemplo n.º 9
0
    def test_validate_list_duplicate_elements(self):
        """
        test that duplicates cause it to fail
        """

        duplicate_list = [1, 3, 2, 1]
        self.assertFalse(Perm.validate_list(duplicate_list))
Ejemplo n.º 10
0
 def test_format_list_decrease(self):
     """
     tests that lists not containing 0 are decreased
     """
     originalList = [1,3,2]
     decreasedList = [0,2,1]
     self.assertEqual(decreasedList, Perm.format_list(originalList))
Ejemplo n.º 11
0
 def test_validate_list_duplicate_elements(self):
     """
     test that duplicates cause it to fail
     """
     
     duplicate_list = [1,3,2,1]
     self.assertFalse(Perm.validate_list(duplicate_list))
Ejemplo n.º 12
0
 def test_validate_list_nonint(self):
     """
     test that a negative entry fails
     """
     
     nonint_list = [2.0,1]
     self.assertFalse(Perm.validate_list(nonint_list))
Ejemplo n.º 13
0
 def test_validate_cycle_nonpositive(self):
     """
     test validate cycle with non-positive cycle elements
     """
     
     cycle = (1, 2, -1)
     self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 14
0
 def test_validate_cycle_repeat(self):
     """
     test validate cycle with a repeated element  of the cycle
     """
     
     cycle = (1, 2, 1)
     self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 15
0
    def test_validate_list_incomplete(self):
        """
        test that an incomplete (lacking 0 or 1) list fails
        """

        incomplete_list = [2, 3]
        self.assertFalse(Perm.validate_list(incomplete_list))
Ejemplo n.º 16
0
    def test_validate_list_nonint(self):
        """
        test that a negative entry fails
        """

        nonint_list = [2.0, 1]
        self.assertFalse(Perm.validate_list(nonint_list))
Ejemplo n.º 17
0
    def test_validate_cycle_repeat(self):
        """
        test validate cycle with a repeated element  of the cycle
        """

        cycle = (1, 2, 1)
        self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 18
0
 def test_validate_list_skip_elements(self):
     """
     test that skipe cause it to fail
     """
     
     skip_list = [1,3,2,5]
     self.assertFalse(Perm.validate_list(skip_list))
Ejemplo n.º 19
0
    def test_validate_list_negative(self):
        """
        test that a negative entry fails
        """

        neg_list = [-2, 1]
        self.assertFalse(Perm.validate_list(neg_list))
Ejemplo n.º 20
0
    def test_validate_cycle_nonpositive(self):
        """
        test validate cycle with non-positive cycle elements
        """

        cycle = (1, 2, -1)
        self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 21
0
    def test_validate_list_skip_elements(self):
        """
        test that skipe cause it to fail
        """

        skip_list = [1, 3, 2, 5]
        self.assertFalse(Perm.validate_list(skip_list))
Ejemplo n.º 22
0
    def test_format_list_identity(self):
        """
        tests that any identity list become [0]
        """

        l = [0, 1, 2, 3, 4]
        self.assertEqual([0], Perm.format_list(l))
Ejemplo n.º 23
0
    def test_validate_cycle_non_int(self):
        """
        test validate_cycle with non integer cycle
        """

        cycle = ('f', 2)
        self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 24
0
 def test_validate_cycle_non_int(self):
     """
     test validate_cycle with non integer cycle
     """
     
     cycle = ('f', 2)
     self.assertFalse(Perm.validate_cycle(cycle))
Ejemplo n.º 25
0
 def test_format_list_minimal(self):
     """
     tests that any extra at the end is left off
     """
     
     l = [1,0,2,3,4]
     l1 = [1,0]
     self.assertEqual(l1, Perm.format_list(l))
Ejemplo n.º 26
0
    def test_make_cycle_unmoved(self):
        """
        test that unmoved elements are dropped
        """
        l = [0,1,3,2]
        cycles = ((3,4),)

        self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 27
0
    def test_format_list_minimal(self):
        """
        tests that any extra at the end is left off
        """

        l = [1, 0, 2, 3, 4]
        l1 = [1, 0]
        self.assertEqual(l1, Perm.format_list(l))
Ejemplo n.º 28
0
 def test_make_cycle_double(self):
     """
     test with multiple cycles
     """
     l = [1,0,3,2]
     cycles = ((1,2),(3,4))
     
     self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 29
0
    def test_make_cycle_unmoved(self):
        """
        test that unmoved elements are dropped
        """
        l = [0, 1, 3, 2]
        cycles = ((3, 4), )

        self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 30
0
    def test_make_cycle_double(self):
        """
        test with multiple cycles
        """
        l = [1, 0, 3, 2]
        cycles = ((1, 2), (3, 4))

        self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 31
0
    def test_make_list_multiple(self):
        """
        test that permutation with multiple cycles is handled properly
        """

        cycle = ((1, 2), (3, 4))
        l = [1, 0, 3, 2]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 32
0
 def test_make_list_incoplete(self):
     """
     test that permutation of only some of the elements is handled properly
     """
     
     cycle = ((4,5),)
     l = [0,1,2,4,3]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 33
0
    def test_make_list_incoplete(self):
        """
        test that permutation of only some of the elements is handled properly
        """

        cycle = ((4, 5), )
        l = [0, 1, 2, 4, 3]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 34
0
    def test_make_list_identity(self):
        """
        test that identity permutation is handled properly
        """

        cycle = ((1, ), )
        l = [0]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 35
0
    def test_make_list(self):
        """
        test making single cycle into permuted list
        """

        cycle = ((1, 2, 3), )
        l = [1, 2, 0]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 36
0
    def test_make_list_multiple2(self):
        """
        this time the cycles overlap
        """
        cycle = ((1, 2), (1, 2, 3))
        #(2,3)
        l = [0, 2, 1]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 37
0
    def test_make_list_multiple3(self):
        """
        this time the cycles overlap, a few more
        """
        cycle = ((1, 2), (1, 2, 3), (1, 2, 3, 4))
        #(1,3,4)
        l = [2, 1, 3, 0]

        self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 38
0
    def test_make_cycle(self):
        """
        test turning a permuted list into its list representation
        """

        cycles = ((1, 2, 3), )
        l = [1, 2, 0]

        self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 39
0
 def test_make_cycle_identity(self):
     """
     test the cycle maker on the identity permutation
     """
     
     l = [0]
     cycles = ((1,),)
     
     self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 40
0
 def test_make_list(self):
     """
     test making single cycle into permuted list
     """
     
     cycle = ((1,2,3),)
     l = [1,2,0]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 41
0
 def test_make_list_multiple2(self):
     """
     this time the cycles overlap
     """
     cycle = ((1,2), (1,2,3))
     #(2,3)
     l = [0,2,1]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 42
0
 def test_make_list_multiple3(self):
     """
     this time the cycles overlap, a few more
     """
     cycle = ((1,2), (1,2,3), (1,2,3,4))
     #(1,3,4)
     l = [2,1,3,0]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 43
0
 def test_make_list_identity(self):
     """
     test that identity permutation is handled properly
     """
     
     cycle = ((1,),)
     l = [0]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 44
0
 def test_make_list_multiple(self):
     """
     test that permutation with multiple cycles is handled properly
     """
     
     cycle = ((1,2), (3,4))
     l = [1,0,3,2]
     
     self.assertEqual(l, Perm.make_list(cycle))
Ejemplo n.º 45
0
    def test_make_cycle_identity(self):
        """
        test the cycle maker on the identity permutation
        """

        l = [0]
        cycles = ((1, ), )

        self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 46
0
 def test_make_cycle(self):
     """
     test turning a permuted list into its list representation
     """
     
     cycles = ((1,2,3),)
     l = [1,2,0]
     
     self.assertEqual(cycles, Perm.make_cycles(l))
Ejemplo n.º 47
0
    def test_init_cycle(self):
        """
        test creating a permutaiton with a cycle
        """
        l = [0, 1, 3, 2]
        cycle = ((3, 4), )
        p = Perm(cycle)

        self.assertEqual(p.list, l)
        self.assertEqual(p.cycles, cycle)
Ejemplo n.º 48
0
 def test_format_list_normal(self):
     """
     test format a already formatted list does not change anything
     """
     l = [2, 1, 0]
     self.assertEqual(l, Perm.format_list(l))
Ejemplo n.º 49
0
 def test_mul_error(self):
     p1 = Perm((1,2))
     
     self.assertEqual(NotImplemented, p1.__mul__('hello'))
Ejemplo n.º 50
0
 def test_validate_list_empty(self):
     """
     tests that the empty lists evaluates as valid
     """
     self.assertTrue(Perm.validate_list([]))
Ejemplo n.º 51
0
 def test_validate_list_normal(self):
     """
     tests that a proper, non-empty, lists evaluates as valid
     """
     normal_list = [5,3,6,1,4,2]
     self.assertTrue(Perm.validate_list(normal_list))
Ejemplo n.º 52
0
    def test_format_list_empty(self):
        """
        test that [] becomes [0]
        """

        self.assertEqual([0], Perm.format_list([]))
Ejemplo n.º 53
0
 def test_validate_list_normal(self):
     """
     tests that a proper, non-empty, lists evaluates as valid
     """
     normal_list = [5, 3, 6, 1, 4, 2]
     self.assertTrue(Perm.validate_list(normal_list))
Ejemplo n.º 54
0
 def test_validate_list_empty(self):
     """
     tests that the empty lists evaluates as valid
     """
     self.assertTrue(Perm.validate_list([]))
Ejemplo n.º 55
0
 def test_power_valid(self):
     p = Perm((1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
     self.assertEqual(p * p * p * p, p**4)
Ejemplo n.º 56
0
 def test_format_list_empty(self):
     """
     test that [] becomes [0]
     """
     
     self.assertEqual([0], Perm.format_list([]))
Ejemplo n.º 57
0
 def test_format_list_normal(self):
     """
     test format a already formatted list does not change anything
     """
     l = [2,1,0]
     self.assertEqual(l, Perm.format_list(l))