Prototype implementation
This commit is contained in:
parent
315143a6fc
commit
14b0bc6d01
160 changed files with 5731 additions and 42 deletions
0
vergabe_teilnahme/apps/core/tests/__init__.py
Normal file
0
vergabe_teilnahme/apps/core/tests/__init__.py
Normal file
41
vergabe_teilnahme/apps/core/tests/test_services.py
Normal file
41
vergabe_teilnahme/apps/core/tests/test_services.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from vergabe_teilnahme.apps.core.services import gewichteter_durchschnitt
|
||||
|
||||
|
||||
class FakePreispunkt:
|
||||
def __init__(self, einzelpreis, vergleichsgewicht):
|
||||
self.einzelpreis = Decimal(str(einzelpreis)) if einzelpreis is not None else None
|
||||
self.vergleichsgewicht = Decimal(str(vergleichsgewicht))
|
||||
|
||||
|
||||
class TestGewichteterDurchschnitt:
|
||||
def test_blueprint_beispiel(self):
|
||||
# 100×1,0 + 80×0,2 + 110×1,2 = 100+16+132=248 / (1,0+0,2+1,2)=2,4 = 103,333...
|
||||
punkte = [
|
||||
FakePreispunkt(100, '1.0'),
|
||||
FakePreispunkt(80, '0.2'),
|
||||
FakePreispunkt(110, '1.2'),
|
||||
]
|
||||
result = gewichteter_durchschnitt(punkte)
|
||||
assert result is not None
|
||||
assert abs(result['wert'] - Decimal('103.333')) < Decimal('0.001')
|
||||
assert result['anzahl'] == 3
|
||||
assert result['minimum'] == Decimal('80')
|
||||
assert result['maximum'] == Decimal('110')
|
||||
|
||||
def test_leerer_input(self):
|
||||
assert gewichteter_durchschnitt([]) is None
|
||||
|
||||
def test_alle_gewichte_null(self):
|
||||
punkte = [FakePreispunkt(100, '0.0'), FakePreispunkt(200, '0.0')]
|
||||
assert gewichteter_durchschnitt(punkte) is None
|
||||
|
||||
def test_einzelpreis_none_wird_ausgeschlossen(self):
|
||||
punkte = [FakePreispunkt(None, '1.0'), FakePreispunkt(100, '1.0')]
|
||||
result = gewichteter_durchschnitt(punkte)
|
||||
assert result is not None
|
||||
assert result['anzahl'] == 1
|
||||
assert result['wert'] == Decimal('100')
|
||||
Loading…
Add table
Add a link
Reference in a new issue