Merge pull request #31 from yardstick/feature/QUANT-1556-test-library-implementation

QUANT-1556: Test library implementation
This commit is contained in:
brmnjsh 2022-04-27 11:42:35 -04:00 committed by GitHub
commit b83783d907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 2 deletions

View File

@ -6,6 +6,10 @@ RUN python -m pip install pulp
RUN python -m pip install pydantic
RUN python -m pip install daemonize
RUN python -m pip install sqspy
RUN python -m pip install -U pytest
RUN python -m pip install pytest-cov
RUN python -m pip install pytest-stub
RUN python -m pip install pytest-mock
RUN mkdir /app
WORKDIR /app

View File

@ -6,6 +6,10 @@ RUN python -m pip install pulp
RUN python -m pip install pydantic
RUN python -m pip install daemonize
RUN python -m pip install sqspy
RUN python -m pip install -U pytest
RUN python -m pip install pytest-cov
RUN python -m pip install pytest-stub
RUN python -m pip install pytest-mock
RUN mkdir /app
WORKDIR /app

View File

@ -27,8 +27,6 @@ class ObjectiveFunction(BaseModel):
else:
for target in targets:
target.drift = round(target.drift + amount, 2)
print(self.tif_targets)
print(self.tcc_targets)
return amount
def update_targets_drift(self, amount: float = 0.0):

60
app/test/test_example.py Normal file
View File

@ -0,0 +1,60 @@
# content of example.py
from pulp import LpProblem, LpVariable, LpMinimize, LpStatus, lpSum
def func(x):
return x + 1
def test_pass():
assert func(4) == 5
def test_failure():
assert func(3) == 5
def yosh_loop():
Items = [1, 2, 3, 4, 5]
tif = {1: 0.2, 2: 0.5, 3: 0.3, 4: 0.8, 5: 0.1}
iif = {1: 0.09, 2: 0.2, 3: 0.113, 4: 0.3, 5: 0.1}
drift = 0.0
drift_limit = 0.2
iif_target = 0.5
tif_target = 0.9
item_vars = LpVariable.dicts("Item", Items, cat="Binary")
result = 'Infeasible'
while drift <= drift_limit:
prob = LpProblem("tif_tcc_test", LpMinimize)
prob += lpSum([(tif[i] + iif[i]) * item_vars[i]
for i in Items]), "TifTccSum"
prob += lpSum([item_vars[i] for i in Items]) == 3, "TotalItems"
prob += lpSum([tif[i] * item_vars[i] for i in Items
]) >= tif_target - (tif_target * drift), 'TifMin'
prob += lpSum([tif[i] * item_vars[i] for i in Items
]) <= tif_target + (tif_target * drift), 'TifMax'
prob += lpSum([iif[i] * item_vars[i] for i in Items
]) >= iif_target - (iif_target * drift), 'TccMin'
prob += lpSum([iif[i] * item_vars[i] for i in Items
]) <= iif_target + (iif_target * drift), 'TccMax'
prob.solve()
if LpStatus[prob.status] == "Infeasible":
for v in prob.variables():
print(v.name, "=", v.varValue)
drift += 0.02
else:
for v in prob.variables():
print(v.name, "=", v.varValue)
result = LpStatus[prob.status]
break
return result
def test_solver():
assert yosh_loop() == 'Optimal'