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))
def test_index_method_bounds(self): c = Change(6) self.assertRaises(IndexError, 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(IndexError, 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(IndexError, 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))
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_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_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_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_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())