Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from eccentricOrange:tests
Browse files Browse the repository at this point in the history
use tuples in testing
  • Loading branch information
eccentricOrange authored May 31, 2022
2 parents 39ed08a + b4ec07e commit c4019e4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
104 changes: 52 additions & 52 deletions test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
def test_get_number_of_each_weekday():
test_function = npbc_core.get_number_of_each_weekday

assert list(test_function(1, 2022)) == [5, 4, 4, 4, 4, 5, 5]
assert list(test_function(2, 2022)) == [4, 4, 4, 4, 4, 4, 4]
assert list(test_function(3, 2022)) == [4, 5, 5 ,5, 4, 4, 4]
assert list(test_function(2, 2020)) == [4, 4, 4, 4, 4, 5, 4]
assert list(test_function(12, 1954)) == [4, 4, 5, 5, 5, 4, 4]
assert tuple(test_function(1, 2022)) == (5, 4, 4, 4, 4, 5, 5)
assert tuple(test_function(2, 2022)) == (4, 4, 4, 4, 4, 4, 4)
assert tuple(test_function(3, 2022)) == (4, 5, 5 ,5, 4, 4, 4)
assert tuple(test_function(2, 2020)) == (4, 4, 4, 4, 4, 5, 4)
assert tuple(test_function(12, 1954)) == (4, 4, 5, 5, 5, 4, 4)


def test_validate_undelivered_string():
Expand Down Expand Up @@ -70,18 +70,18 @@ def test_undelivered_string_parsing():
test_function = npbc_core.parse_undelivered_strings


assert test_function(MONTH, YEAR, '') == set([])
assert test_function(MONTH, YEAR, '') == set(())

assert test_function(MONTH, YEAR, '1') == set([
date(year=YEAR, month=MONTH, day=1)
])
assert test_function(MONTH, YEAR, '1') == set((
date(year=YEAR, month=MONTH, day=1),
))

assert test_function(MONTH, YEAR, '1-2') == set([
assert test_function(MONTH, YEAR, '1-2') == set((
date(year=YEAR, month=MONTH, day=1),
date(year=YEAR, month=MONTH, day=2)
])
))

assert test_function(MONTH, YEAR, '5-17') == set([
assert test_function(MONTH, YEAR, '5-17') == set((
date(year=YEAR, month=MONTH, day=5),
date(year=YEAR, month=MONTH, day=6),
date(year=YEAR, month=MONTH, day=7),
Expand All @@ -95,9 +95,9 @@ def test_undelivered_string_parsing():
date(year=YEAR, month=MONTH, day=15),
date(year=YEAR, month=MONTH, day=16),
date(year=YEAR, month=MONTH, day=17)
])
))

assert test_function(MONTH, YEAR, '5-17', '19') == set([
assert test_function(MONTH, YEAR, '5-17', '19') == set((
date(year=YEAR, month=MONTH, day=5),
date(year=YEAR, month=MONTH, day=6),
date(year=YEAR, month=MONTH, day=7),
Expand All @@ -112,9 +112,9 @@ def test_undelivered_string_parsing():
date(year=YEAR, month=MONTH, day=16),
date(year=YEAR, month=MONTH, day=17),
date(year=YEAR, month=MONTH, day=19)
])
))

assert test_function(MONTH, YEAR, '5-17', '19-21') == set([
assert test_function(MONTH, YEAR, '5-17', '19-21') == set((
date(year=YEAR, month=MONTH, day=5),
date(year=YEAR, month=MONTH, day=6),
date(year=YEAR, month=MONTH, day=7),
Expand All @@ -131,9 +131,9 @@ def test_undelivered_string_parsing():
date(year=YEAR, month=MONTH, day=19),
date(year=YEAR, month=MONTH, day=20),
date(year=YEAR, month=MONTH, day=21)
])
))

assert test_function(MONTH, YEAR, '5-17', '19-21', '23') == set([
assert test_function(MONTH, YEAR, '5-17', '19-21', '23') == set((
date(year=YEAR, month=MONTH, day=5),
date(year=YEAR, month=MONTH, day=6),
date(year=YEAR, month=MONTH, day=7),
Expand All @@ -151,17 +151,17 @@ def test_undelivered_string_parsing():
date(year=YEAR, month=MONTH, day=20),
date(year=YEAR, month=MONTH, day=21),
date(year=YEAR, month=MONTH, day=23)
])
))

assert test_function(MONTH, YEAR, 'mondays') == set([
assert test_function(MONTH, YEAR, 'mondays') == set((
date(year=YEAR, month=MONTH, day=1),
date(year=YEAR, month=MONTH, day=8),
date(year=YEAR, month=MONTH, day=15),
date(year=YEAR, month=MONTH, day=22),
date(year=YEAR, month=MONTH, day=29)
])
))

assert test_function(MONTH, YEAR, 'mondays', 'wednesdays') == set([
assert test_function(MONTH, YEAR, 'mondays', 'wednesdays') == set((
date(year=YEAR, month=MONTH, day=1),
date(year=YEAR, month=MONTH, day=8),
date(year=YEAR, month=MONTH, day=15),
Expand All @@ -172,114 +172,114 @@ def test_undelivered_string_parsing():
date(year=YEAR, month=MONTH, day=17),
date(year=YEAR, month=MONTH, day=24),
date(year=YEAR, month=MONTH, day=31)
])
))

assert test_function(MONTH, YEAR, '2-monday') == set([
date(year=YEAR, month=MONTH, day=8)
])
assert test_function(MONTH, YEAR, '2-monday') == set((
date(year=YEAR, month=MONTH, day=8),
))

assert test_function(MONTH, YEAR, '2-monday', '3-wednesday') == set([
assert test_function(MONTH, YEAR, '2-monday', '3-wednesday') == set((
date(year=YEAR, month=MONTH, day=8),
date(year=YEAR, month=MONTH, day=17)
])
))


def test_calculating_cost_of_one_paper():
DAYS_PER_WEEK = [5, 4, 4, 4, 4, 5, 5]

COST_AND_DELIVERY_DATA = (
array([0, 0, 2, 2, 5, 0, 1]),
array([False, False, True, True, True, False, True])
array((0, 0, 2, 2, 5, 0, 1)),
array((False, False, True, True, True, False, True))
)

test_function = npbc_core.calculate_cost_of_one_paper

assert test_function(
DAYS_PER_WEEK,
set([]),
set(()),
*COST_AND_DELIVERY_DATA
) == 41

assert test_function(
DAYS_PER_WEEK,
set([]),
array([0, 0, 2, 2, 5, 0, 1]),
array([False, False, True, True, True, False, False])
set(()),
array((0, 0, 2, 2, 5, 0, 1)),
array((False, False, True, True, True, False, False))
) == 36

assert test_function(
DAYS_PER_WEEK,
set([
date(year=2022, month=1, day=8)
]),
set((
date(year=2022, month=1, day=8),
)),
*COST_AND_DELIVERY_DATA
) == 41

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=8),
date(year=2022, month=1, day=8)
]),
)),
*COST_AND_DELIVERY_DATA
) == 41

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=8),
date(year=2022, month=1, day=17)
]),
)),
*COST_AND_DELIVERY_DATA
) == 41

assert test_function(
DAYS_PER_WEEK,
set([
date(year=2022, month=1, day=2)
]),
set((
date(year=2022, month=1, day=2),
)),
*COST_AND_DELIVERY_DATA
) == 40

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=2),
date(year=2022, month=1, day=2)
]),
)),
*COST_AND_DELIVERY_DATA
) == 40

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=6),
date(year=2022, month=1, day=7)
]),
)),
*COST_AND_DELIVERY_DATA
) == 34

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=6),
date(year=2022, month=1, day=7),
date(year=2022, month=1, day=8)
]),
)),
*COST_AND_DELIVERY_DATA
) == 34

assert test_function(
DAYS_PER_WEEK,
set([
set((
date(year=2022, month=1, day=6),
date(year=2022, month=1, day=7),
date(year=2022, month=1, day=7),
date(year=2022, month=1, day=7),
date(year=2022, month=1, day=8),
date(year=2022, month=1, day=8),
date(year=2022, month=1, day=8)
]),
)),
*COST_AND_DELIVERY_DATA
) == 34

Expand Down
28 changes: 14 additions & 14 deletions test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_db_creation():
def test_get_papers():
connection = setup_db()

known_data = [
known_data = (
(1, 'paper1', 0, 0, 0),
(1, 'paper1', 1, 1, 6.4),
(1, 'paper1', 2, 0, 0),
Expand All @@ -71,7 +71,7 @@ def test_get_papers():
(3, 'paper3', 4, 1, 3.4),
(3, 'paper3', 5, 1, 4.6),
(3, 'paper3', 6, 1, 6)
]
)

assert Counter(npbc_core.get_papers(connection)) == Counter(known_data)
connection.close()
Expand All @@ -80,13 +80,13 @@ def test_get_papers():
def test_get_undelivered_strings():
connection = setup_db()

known_data = [
known_data = (
(1, 1, 2020, 11, '5'),
(2, 1, 2020, 11, '6-12'),
(3, 2, 2020, 11, 'sundays'),
(4, 3, 2020, 11, '2-tuesday'),
(5, 3, 2020, 10, 'all')
]
)

assert Counter(npbc_core.get_undelivered_strings(connection)) == Counter(known_data)
assert Counter(npbc_core.get_undelivered_strings(connection, string_id=3)) == Counter([known_data[2]])
Expand All @@ -105,7 +105,7 @@ def test_delete_paper():

npbc_core.delete_existing_paper(connection, 2)

known_data = [
known_data = (
(1, 'paper1', 0, 0, 0),
(1, 'paper1', 1, 1, 6.4),
(1, 'paper1', 2, 0, 0),
Expand All @@ -120,7 +120,7 @@ def test_delete_paper():
(3, 'paper3', 4, 1, 3.4),
(3, 'paper3', 5, 1, 4.6),
(3, 'paper3', 6, 1, 6)
]
)

assert Counter(npbc_core.get_papers(connection)) == Counter(known_data)

Expand All @@ -134,7 +134,7 @@ def test_delete_paper():
def test_add_paper():
connection = setup_db()

known_data = [
known_data = (
(1, 'paper1', 0, 0, 0),
(1, 'paper1', 1, 1, 6.4),
(1, 'paper1', 2, 0, 0),
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_add_paper():
(4, 'paper4', 4, 0, 0),
(4, 'paper4', 5, 1, 1),
(4, 'paper4', 6, 1, 7)
]
)

npbc_core.add_new_paper(
connection,
Expand Down Expand Up @@ -252,13 +252,13 @@ def test_edit_paper():


def test_delete_string():
known_data = [
known_data = (
(1, 1, 2020, 11, '5'),
(2, 1, 2020, 11, '6-12'),
(3, 2, 2020, 11, 'sundays'),
(4, 3, 2020, 11, '2-tuesday'),
(5, 3, 2020, 10, 'all')
]
)

connection = setup_db()
npbc_core.delete_undelivered_string(connection, string='all')
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_add_string():
def test_save_results():
connection = setup_db()

known_data = [
known_data = (
(1, 1, 2020, '04/01/2022 01:05:42 AM', '2020-01-01'),
(1, 1, 2020, '04/01/2022 01:05:42 AM', '2020-01-02'),
(2, 1, 2020, '04/01/2022 01:05:42 AM', '2020-01-01'),
Expand All @@ -321,14 +321,14 @@ def test_save_results():
(1, 1, 2020, '04/01/2022 01:05:42 AM', 105.0),
(2, 1, 2020, '04/01/2022 01:05:42 AM', 51.0),
(3, 1, 2020, '04/01/2022 01:05:42 AM', 647.0)
]
)

npbc_core.save_results(
connection,
{1: 105, 2: 51, 3: 647},
{
1: set([date(month=1, day=1, year=2020), date(month=1, day=2, year=2020)]),
2: set([date(month=1, day=1, year=2020), date(month=1, day=5, year=2020), date(month=1, day=3, year=2020)]),
1: set((date(month=1, day=1, year=2020), date(month=1, day=2, year=2020))),
2: set((date(month=1, day=1, year=2020), date(month=1, day=5, year=2020), date(month=1, day=3, year=2020))),
3: set()
},
1,
Expand Down

0 comments on commit c4019e4

Please sign in to comment.