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_ReservationIncludes(self): # First date Logger.ReservationIncludes(Reservation.includes(self.res1, 1)) self.assertEquals(self.res1.msg, 'Reservation {} includes 1'.format(self.res1._id)) # Last date Logger.ReservationIncludes(Reservation.includes(self.res1, 2)) self.assertEquals(self.res1.msg, 'Reservation {} includes 2'.format(self.res1._id)) # Date before Logger.ReservationIncludes(Reservation.includes(self.res1, 0)) self.assertEquals( self.res1.msg, 'Reservation {} does not include 0'.format(self.res1._id)) # Date after Logger.ReservationIncludes(Reservation.includes(self.res1, 3)) self.assertEquals( self.res1.msg, 'Reservation {} does not include 3'.format(self.res1._id))
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_ReservationOverlapping(self): # Overlap with itself Logger.ReservationOverlapping( Reservation.overlapping(self.res1, self.res1)) self.assertEquals( self.res1.msg, 'Reservations {} and {} do overlap'.format(self.res1._id, self.res1._id)) # Common end-date self.res2 = Reservation(2, 3, "Book1", "User2") Logger.ReservationOverlapping( Reservation.overlapping(self.res1, self.res2)) self.assertEquals( self.res1.msg, 'Reservations {} and {} do overlap'.format(self.res1._id, self.res2._id)) # Common start-date self.res2 = Reservation(1, 1, "Book1", "User2") Logger.ReservationOverlapping( Reservation.overlapping(self.res1, self.res2)) self.assertEquals( self.res1.msg, 'Reservations {} and {} do overlap'.format(self.res1._id, self.res2._id)) # Various books self.res2 = Reservation(2, 2, "Book2", "User2") Logger.ReservationOverlapping( Reservation.overlapping(self.res1, self.res2)) self.assertEquals( self.res1.msg, 'Reservations {} and {} do not overlap'.format( self.res1._id, self.res2._id)) # Various dates self.res2 = Reservation(3, 5, "Book1", "User2") Logger.ReservationOverlapping( Reservation.overlapping(self.res1, self.res2)) self.assertEquals( self.res1.msg, 'Reservations {} and {} do not overlap'.format( self.res1._id, self.res2._id))
def setUp(self): self.res1 = Reservation("2", "4", "book1", "User1")
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"))
def setUp(self): self.res1 = Reservation(1, 2, "Book1", "User1")
def setUp(self): Reservation._ids = count(0) self.res1 = Reservation(20, 25, "First", "Richard")
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)