コード例 #1
0
class TestReservation(unittest.TestCase):
    def setUp(self):
        Reservation._ids = count(0)
        self.res1 = Reservation(20, 25, "First", "Richard")

    def test_init(self):
        self.assertEqual(self.res1._id, 0)
        self.assertEqual(self.res1._from, 20)
        self.assertEqual(self.res1._to, 25)
        self.assertEqual(self.res1._book, "First")
        self.assertEqual(self.res1._for, "Richard")
        self.assertEqual(self.res1._changes, 0)

    def test_overlapping(self):
        self.assertTrue(
            self.res1.overlapping(Reservation(15, 22, "First", "tmp")))
        self.assertTrue(
            self.res1.overlapping(Reservation(15, 20, "First", "tmp")))
        self.assertTrue(
            self.res1.overlapping(Reservation(25, 30, "First", "tmp")))
        self.assertFalse(
            self.res1.overlapping(Reservation(5, 10, "First", "tmp")))
        self.assertFalse(
            self.res1.overlapping(Reservation(15, 22, "Second", "tmp")))

    def test_includes(self):
        self.assertTrue(self.res1.includes(20))
        self.assertTrue(self.res1.includes(25))
        self.assertTrue(self.res1.includes(22))
        self.assertFalse(self.res1.includes(26))

    def test_identify(self):
        self.assertEqual(self.res1.identify(20, "First", "Richard"),
                         (True, ""))
        self.assertEqual(self.res1.identify(20, "Second", "Richard"),
                         (False, "book"))
        self.assertEqual(self.res1.identify(20, "First", "Fero"),
                         (False, "for"))
        self.assertEqual(self.res1.identify(19, "First", "Richard"),
                         (False, "date"))

    def test_change_for(self):
        self.res1.change_for("Peto")
        self.assertEqual(self.res1._for, "Peto")
        self.assertEqual(self.res1._changes, 1)

        self.res1.change_for("Fero")
        self.assertEqual(self.res1._for, "Fero")
        self.assertEqual(self.res1._changes, 2)
コード例 #2
0
class TestReservation(unittest.TestCase):

    def setUp(self):
        self.res1 = Reservation("2", "4", "book1", "User1")

    def test___init__(self):      
        self.assertEquals(self.res1._from, "2")
        self.assertEquals(self.res1._to, "4")
        self.assertEquals(self.res1._book, "book1")
        self.assertEquals(self.res1._for, "User1")

    def test_overlapping(self):
        self.assertTrue(self.res1.overlapping(Reservation("4", "6", "book1", "User1")))
        self.assertTrue(self.res1.overlapping(Reservation("1", "2", "book1", "User2")))
        self.assertTrue(self.res1.overlapping(Reservation("3", "3", "book1", "User3")))
        self.assertFalse(self.res1.overlapping(Reservation("1", "1", "book1", "User1")))
        self.assertFalse(self.res1.overlapping(Reservation("5", "7", "book1", "User1")))
        self.assertFalse(self.res1.overlapping(Reservation("2", "4", "book2", "User1")))

    def test_includes(self):
        self.assertTrue(self.res1.includes("2"))
        self.assertTrue(self.res1.includes("4"))
        self.assertFalse(self.res1.includes("1"))
        self.assertFalse(self.res1.includes("5"))

    def test_identify(self):
        self.assertTrue(self.res1.identify("2", "book1", "User1"))
        self.assertFalse(self.res1.identify("2", "book2", "User1"))
        self.assertFalse(self.res1.identify("2", "book2", "User2"))
        self.assertFalse(self.res1.identify("1", "book2", "User1"))
        self.assertFalse(self.res1.identify("5", "book2", "User1"))

    def test_change_for(self):
        self.res1.change_for("new_user")
        self.assertEquals(self.res1._for, "new_user")
        self.assertTrue(self.res1.identify("2", "book1", "new_user"))
        self.assertFalse(self.res1.identify("2", "book1", "User1"))