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))
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))
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_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())
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))