コード例 #1
0
                    print("DONE")

#TESTING THE BEFORE() METHOD
print("Testing the before() method...")
if testDate1.before(testDate2) == False:
    if testDate2.before(testDate3) == False:
        if testDate3.before(testDate4) == False:
            if testDate3.before(testDate2) == True:
                if testDate5.before(testDate6) == True:
                    assert testDate6.before(testDate1) == True
                    beforeMethod = 1
                    print("DONE")

#TESTING THE AFTER() METHOD
print("Testing the after() method...")
if testDate2.after(testDate1) == False:
    if testDate3.after(testDate2) == False:
        if testDate4.after(testDate3) == False:
            if testDate2.after(testDate3) == True:
                if testDate6.after(testDate5) == True:
                    assert testDate1.after(testDate6) == True
                    afterMethod = 1
                    print("DONE")

#TESTING THE EQUAL() METHOD
print("Testing the equal() method...")
if testDate2.equal(testDate1) == False:
    if testDate3.equal(testDate2) == False:
        if testDate4.equal(testDate3) == False:
            if testDate2.equal(testDate2) == True:
                if testDate6.equal(testDate6) == True:
コード例 #2
0
def test_date_adt():
    #testing date_adt.py

    #2020 is a leap year!
    start = time.time()
    test = DateT(1, 1, 2020)

    #test getter
    compare("testing getter method for day", 1, test.day())
    compare("testing getter method for month", 1, test.month())
    compare("testing getter method for year", 2020, test.year())

    #test next function
    #ideally for a functions like this the number of tests to run should be equal to or greater than the number of execution paths
    #there are 6 cases
    # i) simply the next day within current month and year
    # ii) Transition into The next month where the current month has 30 days
    # iii) Transition into The next month where the current month has 31 days
    # iv) Transition into The next year
    # v) Transition into the next month when the current month is february and it a leap year
    # vi) Transition into the next month when current month is february and it is not a leap year

    compare("testing next method, it should return January 2nd 2020 and pass",
            DateT(2, 1, 2020), test.next())

    test = DateT(31, 1, 2020)
    compare(
        "test for transitioning into next month with current month having 31 days. It should return february 1st 2020",
        DateT(1, 2, 2020), test.next())

    test = DateT(30, 4, 2020)  #April 30th, 2020
    compare(
        "test for transitioning into next month with current month having 30 days. It should return May 1st 2020",
        DateT(1, 5, 2020), test.next())

    test = DateT(28, 2, 2020)
    compare(
        "test for transitioning into next month with current month being february and the year is a leap year. It should return Feb 29th 2020",
        DateT(29, 2, 2020), test.next())

    test = DateT(28, 2, 2021)
    compare(
        "test for transitioning into next month with current month being february and the year is NOT leap year. It should return March 1st 2021",
        DateT(1, 3, 2021), test.next())

    test = DateT(31, 12, 2020)
    compare(
        "test for transitioning into next year. It should return Jan 1st 2021 and pass",
        DateT(1, 1, 2021), test.next())

    #test prev method
    test = DateT(2, 1, 2020)
    compare("test for prev method, it should return January 1st 2020 and pass",
            DateT(1, 1, 2020), test.prev())

    test = DateT(1, 5, 2020)
    compare(
        "test for transitioning into previous month with current month having 31 days. It should return April 30th 2020",
        DateT(30, 4, 2020), test.prev())

    test = DateT(1, 6, 2020)
    compare(
        "test for transitioning into previous month with current month having 30 days. It should return May 31st 2020",
        DateT(31, 5, 2020), test.prev())

    test = DateT(1, 3, 2020)
    compare(
        "test for transitioning back into february and the year is a leap year. It should return Feb 29th 2020",
        DateT(29, 2, 2020), test.prev())

    test = DateT(1, 3, 2021)
    compare(
        "test for transitioning back into february and the year is NOT leap year. It should return Feb 28th 2021",
        DateT(28, 2, 2021), test.prev())

    test = DateT(1, 1, 2020)
    compare(
        "test for transitioning into previous year. It should return Dec 31st 2019 and pass",
        DateT(31, 12, 2019), test.prev())

    #test for before method
    test = DateT(1, 1, 2020)
    test2 = DateT(1, 5, 2020)
    compare("test for before method , it should return True and pass", True,
            test.before(test2))
    compare("test for before method , it should return False and pass", False,
            test2.before(test))

    #test for after method
    compare("test for after method , it should return True and pass", True,
            test2.after(test))
    compare("test for after method , it should return False and pass", False,
            test.after(test2))

    #test equals method
    test = DateT(1, 1, 2020)
    test2 = DateT(1, 1, 2020)
    test3 = DateT(1, 2, 2020)
    compare("test for equals method, it should return True and pass", True,
            test.equal(test2))
    compare("test for equals method, it should return False and pass", False,
            test.equal(test3))

    #test add_days method
    test = DateT(31, 1, 2020)
    compare("test add days method, it should return Feb 1st 2020 and pass",
            DateT(1, 2, 2020), test.add_days(1))
    compare("test add days method, it should return Feb 29, 2020",
            DateT(29, 2, 2020), test.add_days(29))

    test = DateT(31, 1, 2021)
    compare("test add days method, it should return March 1st, 2021",
            DateT(1, 3, 2021), test.add_days(29))

    test = DateT(1, 1, 2021)
    compare(
        "test add days method, add 365 days when current year is NOT leap year, it should return january 1st 2022",
        DateT(1, 1, 2022), test.add_days(365))

    test = DateT(1, 1, 2020)
    compare(
        "test add days method, add 365 days when current year IS LEAP YEAR. it should return Dec 31st, 2020",
        DateT(31, 12, 2020), test.add_days(365))

    test = DateT(1, 1, 2020)
    compare(
        "test add days method, add 366 days when current year IS LEAP YEAR. it should return Jan 1st, 2021",
        DateT(1, 1, 2021), test.add_days(366))

    #test days_between method
    test = DateT(31, 1, 2020)
    test2 = DateT(1, 3, 2020)

    compare(
        "test days_between method with March and January when current year is leap year, it should return 30 days",
        30, test2.days_between(test))

    test = DateT(31, 1, 2021)
    test2 = DateT(1, 3, 2021)
    compare(
        "test days_between method with March and January when current year is NOT leap year, it should return 29 days",
        29, test2.days_between(test))