def test_change_findplace(self):
     c = Change(10, '1230')
     self.assertTrue(c.find_place(0))
     self.assertTrue(c.find_place(1))
     self.assertTrue(c.find_place(2))
     self.assertFalse(c.find_place(3))
     self.assertFalse(c.find_place(8))
     self.assertTrue(c.find_place(9))
Esempio n. 2
0
 def test_change_output(self):
     string = '.'.join(
         map(str, [
             Change(6, '-'),
             Change(6, '3'),
             Change(6, '-'),
             Change(6, '4'),
         ]))
     self.assertEqual(string, 'X.36.X.14')
Esempio n. 3
0
 def test_row_multiply_change(self):
     r = Row()
     r = r * Change(6, 'X')
     self.assertEqual(r, '214365')
     r = r * Change(6, '1')
     self.assertEqual(r, '241635')
     r = r * Change(8, 'X')
     self.assertEqual(r, '42615387')
     r = r * Change(5, '3')
     self.assertEqual(r, '24651387')
Esempio n. 4
0
    def test_row_block_set_changes(self):
        rb = RowBlock(*[Change(5, pn) for pn in ['3', '1', '5']],
                      starting_row='54321')

        new_changes = [Change(5, pn) for pn in ['5', '3']]
        rb.changes = new_changes

        self.assertEqual(rb.changes, new_changes)
        self.assertEqual(rb.size, 3)
        self.assertEqual(list(rb), ['54321', '45231', '54213'])
Esempio n. 5
0
    def test_row_block_set_start(self):
        changes = []
        changes.append(Change(5, '3'))
        changes.append(Change(5, '1'))
        changes.append(Change(5, '5'))

        rb = RowBlock(*changes)
        rb.set_start('54321')
        rb.recalculate()

        self.assertEqual(rb[2], '43521')
Esempio n. 6
0
    def test_change_equals_string_types(self):
        self.assertEqual(Change(6, '16'), '16')

        self.assertEqual(Change(6, b'16'), b'16')
        self.assertEqual(Change(6, u'16'), u'16')

        self.assertEqual(bytes(Change(6, '16')), b'16')

        try:
            self.assertEqual(unicode(Change(6, '16')), u'16')
        except NameError:
            pass
Esempio n. 7
0
 def test_change_count_places(self):
     self.assertEqual(Change(8).count_places(), 8)
     self.assertEqual(Change(8, '3').count_places(), 2)
     self.assertEqual(Change(8, '6').count_places(), 2)
     self.assertEqual(Change(8, '36').count_places(), 2)
     self.assertEqual(Change(8, '18').count_places(), 2)
     self.assertEqual(Change(8, '78').count_places(), 2)
     self.assertEqual(Change(9, '7').count_places(), 1)
     self.assertEqual(Change(9, '1').count_places(), 1)
     self.assertEqual(Change(9, '9').count_places(), 1)
Esempio n. 8
0
 def test_change_sign(self):
     self.assertEqual(Change().sign(), +1)
     self.assertEqual(Change(4).sign(), +1)
     self.assertEqual(Change(9).sign(), +1)
     self.assertEqual(Change(9, '1').sign(), +1)
     self.assertEqual(Change(9, '9').sign(), +1)
     self.assertEqual(Change(9, '129').sign(), -1)
     self.assertEqual(Change(6, '12').sign(), +1)
     self.assertEqual(Change(6, '-').sign(), -1)
     self.assertEqual(Change(8, '-').sign(), +1)
Esempio n. 9
0
    def test_row_block_recalculate(self):
        changes = []
        changes.append(Change(5, '3'))
        changes.append(Change(5, '1'))
        changes.append(Change(5, '5'))

        rb = RowBlock(*changes)
        rb[2] = '54321'
        rb.recalculate(2)

        self.assertEqual(rb.size, 4)
        self.assertEqual(rb[0], '12345')
        self.assertEqual(rb[1], '21354')
        self.assertEqual(rb[2], '54321')
        self.assertEqual(rb[3], '45231')
Esempio n. 10
0
    def test_row_block_constructors(self):
        changes = []
        changes.append(Change(5, '3'))
        changes.append(Change(5, '1'))
        changes.append(Change(5, '5'))

        rb = RowBlock(*changes)
        self.assertEqual(rb.size, 4)
        self.assertEqual(rb[0], '12345')
        self.assertEqual(rb[1], '21354')
        self.assertEqual(rb[2], '23145')
        self.assertEqual(rb[3], '32415')

        rb = RowBlock(*changes, starting_row='54321')
        self.assertEqual(rb[2], '43521')
    def test_change_set_exceptions(self):
        c = Change()

        self.assertRaises(ValueError, lambda: c.set(-1, 'X'))
        c.set(0, 'X')
        c.set(MAX_BELL_NUMBER, 'X')
        self.assertRaises(ValueError, lambda: c.set(MAX_BELL_NUMBER + 1, 'X'))

        self.assertRaises(TypeError, lambda: c.set(self, 'X'))
        self.assertRaises(TypeError, lambda: c.set(1, self))

        self.assertRaises(ValueError, lambda: Change(5, 'XYZ'))
Esempio n. 12
0
    def test_row_block_recalculate_bounds(self):
        rb = RowBlock(*[Change(5, pn) for pn in ['3', '1', '5']])

        self.assertRaises(IndexError, lambda: rb.recalculate(-1))
        rb.recalculate(0)
        rb.recalculate(3)
        self.assertRaises(IndexError, lambda: rb.recalculate(4))
Esempio n. 13
0
    def test_bell_multiply_bounds(self):
        c = Change(6, '14')

        self.assertRaises(ValueError, lambda: c * -1)
        c * 0
        c * MAX_BELL_NUMBER
        self.assertRaises(ValueError, lambda: c * (MAX_BELL_NUMBER + 1))
    def test_index_method_bounds(self):
        c = Change(6)

        self.assertRaises(ValueError, lambda: c.find_swap(-1))
        self.assertFalse(c.find_swap(0))
        self.assertFalse(c.find_swap(4))
        self.assertRaises(IndexError, lambda: c.find_swap(5))

        self.assertRaises(ValueError, lambda: c.find_place(-1))
        self.assertTrue(c.find_place(0))
        self.assertTrue(c.find_place(5))
        self.assertRaises(IndexError, lambda: c.find_place(6))

        self.assertRaises(ValueError, lambda: c.swap_pair(-1))
        self.assertTrue(c.swap_pair(0))
        self.assertTrue(c.swap_pair(4))
        self.assertRaises(IndexError, lambda: c.swap_pair(5))
Esempio n. 15
0
 def test_change_findswap(self):
     c = Change(12, '145T')
     self.assertFalse(c.find_swap(0))  # 1-2
     self.assertTrue(c.find_swap(1))  # 2-3
     self.assertFalse(c.find_swap(2))  # 3-4
     self.assertFalse(c.find_swap(3))  # 4-5
     self.assertTrue(c.find_swap(5))  # 6-7
     self.assertFalse(c.find_swap(10))  # E-T
Esempio n. 16
0
 def test_change_invalid(self):
     self.assertRaises(ValueError, lambda: Change(5, '18'))
     self.assertRaises(ValueError, lambda: Change(5, 'XYZ'))
     self.assertRaises(ValueError, lambda: Change(5, '!$'))
     self.assertRaises(ValueError, lambda: Change(5, ''))
     self.assertRaises(ValueError, lambda: Change(5, '321'))
     self.assertRaises(ValueError, lambda: Change(5, '11'))
     self.assertRaises(ValueError, lambda: Change(5, '12 3'))
Esempio n. 17
0
 def test_change_print(self):
     self.assertEqual(str(Change()), '')
     self.assertEqual(str(Change(8, '-')), 'X')
     self.assertEqual(str(Change(8, '18')), '18')
     self.assertEqual(str(Change(10, '18')), '18')
     self.assertEqual(str(Change(10, '4')), '14')
     self.assertEqual(str(Change(10, '129')), '1290')
     self.assertEqual(str(Change(16, 'E')), 'ED')
Esempio n. 18
0
    def test_row_block_subscript_bounds(self):
        rb = RowBlock(*[Change(5, pn) for pn in ['3', '1', '5']])

        self.assertRaises(IndexError, lambda: rb[-1])
        self.assertEqual(rb[0], '12345')
        self.assertEqual(rb[3], '32415')
        self.assertRaises(IndexError, lambda: rb[4])

        self.assertRaises(IndexError, lambda: rb.__setitem__(-1, Row(5)))
        rb[0] = Row(5)  # Should succeed
        rb[3] = Row(5)
        self.assertRaises(IndexError, lambda: rb.__setitem__(4, Row(5)))
Esempio n. 19
0
    def test_row_block_changes_not_directly_mutable(self):
        changes_in = [Change(5, pn) for pn in ['3', '1', '5']]
        rb = RowBlock(*changes_in)

        # Make a local reference to rb.changes, and modify it...
        changes_out = rb.changes
        changes_out.pop()

        # ... then make sure the original hasn't changed
        self.assertEqual(len(changes_in), 3)
        self.assertEqual(len(rb.changes), 3)
        self.assertEqual(rb.changes, changes_in)
Esempio n. 20
0
    def _process_data(self, file):
        calls = super()._process_data(file)
        for call, place_notation in calls.items():
            try:
                calls[call] = Change(
                    self.config_store.bells,
                    place_notation,
                )
            except ValueError:
                print('Could not parse call {0}'.format(call))
                raise

        return calls
Esempio n. 21
0
    def test_change_constructor_exceptions(self):
        self.assertRaises(ValueError, lambda: Change(-1))
        Change(0)
        Change(MAX_BELL_NUMBER)
        self.assertRaises(ValueError, lambda: Change(MAX_BELL_NUMBER + 1))

        self.assertRaises(TypeError, lambda: Change(self))
        self.assertRaises(TypeError, lambda: Change(1, self))
 def test_change_findswap(self):
     c = Change(12, '145T')
     self.assertFalse(c.find_swap(0))  # 1-2
     self.assertTrue(c.find_swap(1))  # 2-3
     self.assertFalse(c.find_swap(2))  # 3-4
     self.assertFalse(c.find_swap(3))  # 4-5
     self.assertTrue(c.find_swap(5))  # 6-7
     self.assertFalse(c.find_swap(10))  # E-T
Esempio n. 23
0
 def test_change_findplace(self):
     c = Change(10, '1230')
     self.assertTrue(c.find_place(0))
     self.assertTrue(c.find_place(1))
     self.assertTrue(c.find_place(2))
     self.assertFalse(c.find_place(3))
     self.assertFalse(c.find_place(8))
     self.assertTrue(c.find_place(9))
Esempio n. 24
0
    def test_bell_multiply_order(self):
        c = Change(6, '14')

        self.assertEqual(0 * c, 0)
        self.assertEqual(1 * c, 2)
        self.assertEqual(2 * c, 1)
        self.assertEqual(3 * c, 3)
        self.assertEqual(4 * c, 5)

        self.assertEqual(c * 0, 0)
        self.assertEqual(c * 1, 2)
        self.assertEqual(c * 2, 1)
        self.assertEqual(c * 3, 3)
        self.assertEqual(c * 4, 5)
Esempio n. 25
0
 def test_change_bells(self):
     self.assertEqual(Change().bells, 0)
     self.assertEqual(Change(7).bells, 7)
     self.assertEqual(Change(8, '14').bells, 8)
Esempio n. 26
0
 def test_change_equals(self):
     self.assertTrue(Change() == Change(0, ''))
     self.assertTrue(Change(3) == Change(3, '123'))
     self.assertTrue(Change(4) == Change(4, '1234'))
     self.assertTrue(Change(5, '3') == Change(5, '3'))
     self.assertTrue(Change(6, '1') != Change(6, '5'))
     self.assertTrue(Change(8, 'X') == Change(8, '-'))
     self.assertTrue(Change(6, '-') != Change(8, '-'))
     self.assertTrue(Change(6, '-') != Change(8, '78'))
 def test_change_set_returns_none(self):
     c = Change()
     self.assertEqual(c.set(4, 'X'), None)
Esempio n. 28
0
 def test_change_reverse(self):
     self.assertEqual(Change(5, '1').reverse(), Change(5, '5'))
     self.assertEqual(Change(6, '16').reverse(), Change(6, '16'))
     self.assertEqual(Change(8, 'X').reverse(), Change(8, 'X'))
     self.assertEqual(Change(4, '12').reverse(), Change(4, '34'))
Esempio n. 29
0
    def test_change_set(self):
        a = Change()
        self.assertNotEqual(a, Change(6, '16'))

        a.set(6, '16')
        self.assertEqual(a, Change(6, '16'))
Esempio n. 30
0
    def test_change_implicit_places(self):
        self.assertEqual(Change(6, '4'), Change(6, '14'))
        self.assertEqual(Change(5, '-'), Change(5, '5'))
        self.assertEqual(Change(7, '12'), Change(7, '127'))

        self.assertRaises(ValueError, lambda: Change(5, '15'))
Esempio n. 31
0
    def test_change_multiply_bell(self):
        b1 = 3

        b1 = b1 * Change(6, '-')
        self.assertEqual(b1, 2)
        b1 = b1 * Change(6, '3')
        self.assertEqual(b1, 2)
        b1 = b1 * Change(6, '-')
        self.assertEqual(b1, 3)
        b1 = b1 * Change(6, '4')
        self.assertEqual(b1, 3)
        b1 = b1 * Change(6, '-')
        self.assertEqual(b1, 2)

        b2 = 0

        b2 = b2 * Change(6, '-')
        self.assertEqual(b2, 1)
        b2 = b2 * Change(6, '3')
        self.assertEqual(b2, 0)
        b2 = b2 * Change(6, '-')
        self.assertEqual(b2, 1)
        b2 = b2 * Change(6, '4')
        self.assertEqual(b2, 2)
        b2 = b2 * Change(6, '-')
        self.assertEqual(b2, 3)

        self.assertEqual(b2 * Change(6, '16'), 4)
        self.assertEqual(b2, 3)

        self.assertEqual(10 * Change(4, 'X'), 10)
        self.assertEqual(9 * Change(), 9)
    def test_index_method_types(self):
        c = Change(6)

        c.find_swap(Bell(0))
        c.find_swap('1')
        c.find_swap(0)

        c.find_place(Bell(0))
        c.find_place('1')
        c.find_place(0)

        c.swap_pair(Bell(0))
        c.swap_pair('1')
        c.swap_pair(0)

        self.assertRaises(TypeError, lambda: c.find_swap(self))
        self.assertRaises(TypeError, lambda: c.find_place(self))
        self.assertRaises(TypeError, lambda: c.swap_pair(self))
    def test_change_swappair(self):
        c = Change(8, '-')

        self.assertFalse(c.swap_pair(0))
        self.assertEqual(c, '12')
        self.assertTrue(c.swap_pair(1))
        self.assertEqual(c, '14')
        self.assertTrue(c.swap_pair(0))
        self.assertEqual(c, '34')
        self.assertTrue(c.swap_pair(2))
        self.assertEqual(c, 'X')

        self.assertFalse(c.swap_pair(2))
        self.assertEqual(c, '34')
        self.assertFalse(c.swap_pair(0))
        self.assertEqual(c, '1234')
        self.assertTrue(c.swap_pair(1))
        self.assertEqual(c, '14')
        self.assertFalse(c.swap_pair(6))
        self.assertEqual(c, '1478')

        self.assertRaises(IndexError, lambda: c.swap_pair(11))
        self.assertRaises(IndexError, lambda: c.swap_pair(7))
Esempio n. 34
0
 def test_change_copy(self):
     a = Change(6, '12')
     c = Change(a)
     self.assertEqual(a, c)
Esempio n. 35
0
    def test_change_comparison(self):
        self.assertTrue(Change(6, '1234') < Change(8, '56'))
        self.assertTrue(Change(6, '1234') <= Change(8, '56'))
        self.assertFalse(Change(6, '1234') > Change(8, '56'))
        self.assertFalse(Change(6, '1234') >= Change(8, '56'))

        self.assertTrue(Change(6, '1234') > Change(6, '56'))
        self.assertTrue(Change(6, '1234') >= Change(6, '56'))
        self.assertFalse(Change(6, '1234') < Change(6, '56'))
        self.assertFalse(Change(6, '1234') <= Change(6, '56'))

        self.assertFalse(Change(6, 'X') > Change(6, 'X'))
        self.assertTrue(Change(6, 'X') >= Change(6, 'X'))
        self.assertFalse(Change(6, 'X') < Change(6, 'X'))
        self.assertTrue(Change(6, 'X') <= Change(6, 'X'))

        self.assertTrue(Change(6) < Change(6, '3456'))
        self.assertTrue(Change(6, '3456') < Change(6, '56'))
        self.assertTrue(Change(6, '56') < Change(6, '36'))
        self.assertTrue(Change(6, '36') < Change(6, '16'))
Esempio n. 36
0
    def test_change_many_bells(self):
        n = MAX_BELLS + 4

        c = Change(n)

        self.assertFalse(c.find_swap(n - 2))
        self.assertTrue(c.swap_pair(n - 2))

        self.assertFalse(c.find_place(n - 1))
        self.assertFalse(c.find_place(n - 2))
        self.assertTrue(c.find_place(n - 3))

        self.assertTrue(c.find_swap(n - 2))
        self.assertFalse(c.find_swap(n - 3))
        self.assertFalse(c.find_swap(n - 4))

        self.assertEqual(c.count_places(), n - 2)
        self.assertTrue(c.internal())

        self.assertFalse(c.reverse().find_place(0))
        self.assertTrue(c.reverse().find_place(3))
        self.assertTrue(c.reverse().internal())
    def test_change_set(self):
        a = Change()
        self.assertNotEqual(a, Change(6, '16'))

        a.set(6, '16')
        self.assertEqual(a, Change(6, '16'))
Esempio n. 38
0
    def test_change_swappair(self):
        c = Change(8, '-')

        self.assertFalse(c.swap_pair(0))
        self.assertEqual(c, '12')
        self.assertTrue(c.swap_pair(1))
        self.assertEqual(c, '14')
        self.assertTrue(c.swap_pair(0))
        self.assertEqual(c, '34')
        self.assertTrue(c.swap_pair(2))
        self.assertEqual(c, 'X')

        self.assertFalse(c.swap_pair(2))
        self.assertEqual(c, '34')
        self.assertFalse(c.swap_pair(0))
        self.assertEqual(c, '1234')
        self.assertTrue(c.swap_pair(1))
        self.assertEqual(c, '14')
        self.assertFalse(c.swap_pair(6))
        self.assertEqual(c, '1478')

        self.assertRaises(IndexError, lambda: c.swap_pair(11))
        self.assertRaises(IndexError, lambda: c.swap_pair(7))
    def test_change_many_bells(self):
        n = Bell.MAX_BELLS + 4

        c = Change(n)

        self.assertFalse(c.find_swap(n - 2))
        self.assertTrue(c.swap_pair(n - 2))

        self.assertFalse(c.find_place(n - 1))
        self.assertFalse(c.find_place(n - 2))
        self.assertTrue(c.find_place(n - 3))

        self.assertTrue(c.find_swap(n - 2))
        self.assertFalse(c.find_swap(n - 3))
        self.assertFalse(c.find_swap(n - 4))

        self.assertEqual(c.count_places(), n - 2)
        self.assertTrue(c.internal())

        self.assertFalse(c.reverse().find_place(0))
        self.assertTrue(c.reverse().find_place(3))
        self.assertTrue(c.reverse().internal())