コード例 #1
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_year():
    assert DateT(23, 2, 200).year() == 200
    assert DateT(1, 12, 2031).year() == 2031
    assert DateT(1, 12, 10).year() == 10

    assert DateT(31, 1, 2012).year() != -2012
    assert DateT(14, 2, 2012).year() != 0
    assert DateT(14, 2, 2012).year() != 20120
コード例 #2
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_init():
    with pytest.raises(ValueError):
        DateT(-1, 1, 2000)
    with pytest.raises(ValueError):
        DateT(0, 1, 2000)
    with pytest.raises(ValueError):
        DateT(100, 1, 2000)
    with pytest.raises(ValueError):
        DateT(10, -1, 2000)
    with pytest.raises(ValueError):
        DateT(10, 0, 2000)
    with pytest.raises(ValueError):
        DateT(-1, 13, 2000)
    with pytest.raises(ValueError):
        DateT(1, 1, 10000)
    with pytest.raises(ValueError):
        DateT(1, 1, 0)
コード例 #3
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_add_days():
    assert DateT(13, 12, 2021).add_days(12).equal(DateT(25, 12, 2021))
    assert DateT(29, 1, 1600).add_days(-100).equal(DateT(21, 10, 1599)) # month + year change
コード例 #4
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_after():
    assert DateT(13, 12, 2021).after(DateT(12, 12, 2021)) # days after
    assert DateT(29, 3, 1600).after(DateT(29, 1, 1600)) # months after
    assert DateT(1, 3, 1701).after(DateT(28, 2, 1700)) # years after
コード例 #5
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_before():
    assert DateT(30, 12, 2021).before(DateT(31, 12, 2021)) # days before
    assert DateT(1, 2, 1600).before(DateT(1, 3, 1600)) # months before
    assert DateT(1, 3, 1).before(DateT(1, 3, 1700)) # years before
コード例 #6
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_prev():
    assert DateT(31, 12, 2021).prev().equal(DateT(30, 12, 2021))
    assert DateT(1, 3, 1600).prev().equal(DateT(29, 2, 1600)) # 400 divisible leap year
    assert DateT(1, 3, 1700).prev().equal(DateT(28, 2, 1700)) # 100 divisible non leap year
    assert DateT(1, 2, 2012).prev().equal(DateT(31, 1, 2012)) #  month change
コード例 #7
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_next():
    assert DateT(1, 2, 2012).next().equal(DateT(2, 2, 2012))
    assert DateT(28, 2, 2020).next().equal(DateT(29, 2, 2020)) # leap year
    assert DateT(28, 2, 2021).next().equal(DateT(1, 3, 2021)) # non leap year
    assert DateT(31, 12, 2021).next().equal(DateT(1, 1, 2022)) # month + year change
コード例 #8
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_equal():
    assert DateT(31, 12, 2021).equal(DateT(31, 12, 2021))
    assert DateT(1, 1, 1).equal(DateT(1, 1, 1))

    assert not DateT(1, 1, 1).equal(DateT(2, 1, 1))
    assert not DateT(31, 12, 2021).equal(DateT(30, 12, 2020))
コード例 #9
0
        self.lati = lati2
        self.long = math.degrees(self.long)
        self.lati = math.degrees(self.lati)

    def distance(self, p):
        R = 6371
        lati1 = math.radians(self.lati)
        long1 = math.radians(self.long)
        latip = math.radians(p.lati)
        longp = math.radians(p.long)
        a = (math.sin(abs(latip - lati1) /
                      2))**2 + math.cos(latip) * math.cos(lati1) * (math.sin(
                          abs(longp - long1) / 2))
        d = R * 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
        return d

    def arrival_date(self, p, d, s):
        dis = self.distance(p)

        days = int(dis / s)
        return d.add_days(days)


pos = GPosT(20, 60)
dest = GPosT(30, 60)
date = DateT(1, 1, 2000)
speed = 0.5
endDate = pos.arrival_date(dest, date, speed)

print(endDate.d, endDate.m, endDate.y)
コード例 #10
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_month():
    assert DateT(23, 2, 2012).month() == 2
    assert DateT(1, 12, 2012).month() == 12

    assert DateT(31, 1, 2012).month() != 2
    assert DateT(14, 2, 2012).month() != -2
コード例 #11
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_day():
    assert DateT(23, 2, 2012).day() == 23
    assert DateT(1, 2, 2012).day() == 1

    assert DateT(31, 1, 2012).day() != 30
    assert DateT(14, 2, 2012).day() != -14
コード例 #12
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_GPosT_arrival_date():
    start_date = DateT(1, 1, 2000)
    start_pos = GPosT(0, 0)
    target_pos = GPosT(25, 25)

    assert start_pos.arrival_date(target_pos, start_date, 100).equal(DateT(8, 2, 2000))
コード例 #13
0
ファイル: test_driver.py プロジェクト: madhi-naga/SE-2AA4
## @file test_driver.py
#  @author ?
#  @brief ?
#  @date ?

import unittest
from date_adt import DateT
from pos_adt import GPosT

d1 = DateT(1, 1, 2020)
d11 = DateT(1, 1, 2021)
d2 = DateT(31, 12, 1500)
d22 = DateT(1, 2, 1501)
d3 = DateT(25, 4, 1764)
d4 = DateT(6, 10, 787)
d44 = DateT(6, 10, 787)
d5 = DateT(29, 11, 1999)
d6 = DateT(28, 2, 2220)

p1 = GPosT(43.5, 79.1)
p2 = GPosT(-12.357, -169.599)
p22 = GPosT(-12.357, -169.599)
p3 = GPosT(83.3, -12.47)
p4 = GPosT(23.77, 99.521)


class TestT(unittest.TestCase):
    def main(self):
        self.test_days()
        self.test_months()
        self.test_years()
コード例 #14
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))
コード例 #15
0
def test_post_adt():
    test = GPosT(45, 45)
    compare("test getter method for latitude", 45, test.lat())
    compare("test getter method for longitude", 45, test.long())

    test = GPosT(43.580605, -79.625668)
    test2 = GPosT(40.723606, -73.860514)
    compare(
        "test distance method , it should return 571.44 km rounded to the 2 decimal places",
        571.44, test2.distance(test))

    test = GPosT(43.261897, -79.921433)
    test2 = GPosT(43.262545, -79.922549)
    compare("test equal method for distance < 1 km, it should return True",
            True, test2.equal(test))

    test2 = GPosT(43.250880, -79.920292)
    compare("test equal method for distance > 1km, it should return False",
            False, test2.equal(test))

    test = GPosT(45, 45)
    test2 = GPosT(45, -45)
    compare("test west_of method , it should return True", True,
            test2.west_of(test))

    compare("test west_of method, it should return False", False,
            test.west_of(test2))

    test = GPosT(45, 45)
    test2 = GPosT(50, -45)
    compare("test north_of method, it should return True", True,
            test2.north_of(test))
    compare("test north_of method, it should return False", False,
            test.north_of(test2))

    test = GPosT(43, -75)
    test2 = GPosT(44.078061, -73.170068)

    test.move(45, 100)
    #    compare("test move method",GPosT(43.63, -74.12),test)

    date = DateT(18, 1, 2020)
    test = GPosT(43, -75)
    val = test.arrival_date(
        test2, date, 180
    )  #starting from 43,-75 travel to test2 at 180km/day starting on date
    compare(
        "test arrival date while travelling at speed that allowed to reach within the same (i.e days required < 1), it should return Jan 19th, 2020",
        DateT(19, 1, 2020), val)

    test_distance = test.distance(test2)
    val = test.arrival_date(test2, date, test_distance)
    compare(
        "test arrival date with travelling speed that takes exactly 1 day in total, it should return Jan 19th 2020",
        DateT(19, 1, 2020), val)

    val = test.arrival_date(test2, date, 14.62)
    compare(
        "test arrival date with travelling speed that takes until the 31st of the month, it should return Jan 31st 2020",
        DateT(31, 1, 2020), val)

    date = DateT(1, 2, 2020)
    val = test.arrival_date(test2, date, 6.55)
    compare(
        "test arrival date that takes 29 days to travel in feb, it should return March 1st 2020",
        DateT(1, 3, 2020), val)

    val = test.arrival_date(test2, date, 0)
    compare("test arrival date with 0 speed it should return the current date",
            DateT(1, 2, 2020), val)
コード例 #16
0
ファイル: test_driver.py プロジェクト: jaymody/2aa4
def test_DateT_days_between():
    assert DateT(10, 12, 2000).days_between(DateT(20, 12, 2000)) == 10 # between years
    assert DateT(29, 3, 2014).days_between(DateT(29, 3, 2013)) == -365 # 365 (year) negative days between
コード例 #17
0
## @file test_driver.py
#  @author Yousam Asham
#  @brief Driver to test out date_adt.py and pos_adt.py classes
#  @date 11-01-2020
from date_adt import DateT
from pos_adt import GPosT
import math

#testing for DateT
testDate1 = DateT(11,1,2020)
testDate2 = DateT(28,2,2008)
testDate3 = DateT(1,3,2004)
testDate4 = DateT(1,3,2001)
testDate5 = DateT(1,1,2000)
testDate6 = DateT(31,12,2005)
#Flags (could also be bools)
dayMethod = 0
monthMethod = 0
yearMethod = 0
prevMethod = 0
nextMethod = 0
beforeMethod = 0
afterMethod = 0
equalMethod = 0
days_betweenMethod = 0
add_daysMethod = 0

#TESTING THE DAY() METHOD
print("Testing the day() method...")
if testDate1.day() == 11:
    if testDate2.day() == 28:
コード例 #18
0
 def arrival_date(self, p, d, s):
     dist = GPosT.distance(self, p)
     days = round(dist / s)
     d2 = DateT.add_days(d, days)
     return d2