carom-server/billard/tests.py

113 lines
3.4 KiB
Python
Raw Permalink Normal View History

from datetime import datetime, time
2017-01-03 19:26:51 +01:00
from django.test import TestCase
from billard.utils import calculate_prize_for, get_prize_for
class PrizeCalculationTestCase(TestCase):
def calculate_prize_for(self, start, end, pph, expected):
self.assertEqual(calculate_prize_for(start, end, pph), expected)
def test_cpf_1(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 7)
pph = 10
self.calculate_prize_for(start, end, pph, pph)
def test_cpf_2(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 6, 30)
pph = 10
expected = 5
self.calculate_prize_for(start, end, pph, expected)
def test_cpf_3(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 6, 15)
pph = 10
expected = 2.5
self.calculate_prize_for(start, end, pph, expected)
def test_cpf_4(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 6, 1)
pph = 60
expected = 1
self.calculate_prize_for(start, end, pph, expected)
class PrizeGetTestCase(TestCase):
2018-02-11 10:56:44 +01:00
def get_prize_for(self, start, end, pph=0, hh_start=None, hh_end=None, pphh=0, expected=(0, 0, 0)):
self.assertEqual(get_prize_for(start, end, pph, hh_start, hh_end, pphh), expected)
def test_gpf_1(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 7)
hh_start = None
hh_end = None
pph = 10
pphh = 5
expected = (10, 10, 0)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_2(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 8)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (15, 10, 5)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_3(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 1, 9)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (25, 20, 5)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_4(self):
start = datetime(2017, 1, 1, 6)
end = datetime(2017, 1, 2, 9)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (260, 250, 10)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_5(self):
start = datetime(2017, 1, 1, 7, 30)
end = datetime(2017, 1, 1, 8)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (2.5, 0, 2.5)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_6(self):
start = datetime(2017, 1, 1, 7, 30)
end = datetime(2017, 1, 1, 8, 30)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (7.5, 5, 2.5)
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)
def test_gpf_7(self):
start = datetime(2017, 1, 1, 6, 30)
end = datetime(2017, 1, 1, 7, 30)
hh_start = time(7)
hh_end = time(8)
pph = 10
pphh = 5
expected = (7.5, 5, 2.5)
2018-02-11 10:56:44 +01:00
self.get_prize_for(start, end, pph, hh_start, hh_end, pphh, expected)