From 4c4a447afec83526e7d4b35b375427657e773496 Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Thu, 14 Apr 2022 17:12:48 -0400 Subject: [PATCH 01/10] add pytest --- .docker-compose/Dockerfile | 1 + Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index 62f8a78..b8715c1 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -6,6 +6,7 @@ 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 mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index 58839d7..c41c12d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ 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 mkdir /app WORKDIR /app From 41856322f8b0285b21f9a030b0a19e09786587aa Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Thu, 14 Apr 2022 23:54:10 -0400 Subject: [PATCH 02/10] test framework and example test added --- .docker-compose/Dockerfile | 1 + Dockerfile | 1 + app/test/test_example.py | 7 +++++++ 3 files changed, 9 insertions(+) create mode 100644 app/test/test_example.py diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index b8715c1..65e1df4 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -7,6 +7,7 @@ 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-spec RUN mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index c41c12d..cbdd950 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ 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-spec RUN mkdir /app WORKDIR /app diff --git a/app/test/test_example.py b/app/test/test_example.py new file mode 100644 index 0000000..443721e --- /dev/null +++ b/app/test/test_example.py @@ -0,0 +1,7 @@ +# content of example.py +def func(x): + return x + 1 + + +def test_answer(): + assert func(3) == 5 \ No newline at end of file From e3f6c975031b899eae94830fa22340b498e06eb4 Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Sun, 17 Apr 2022 23:33:22 -0400 Subject: [PATCH 03/10] added pass and fail tests --- app/models/objective_function.py | 2 -- app/test/test_example.py | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/objective_function.py b/app/models/objective_function.py index 5081f1d..9bd332f 100644 --- a/app/models/objective_function.py +++ b/app/models/objective_function.py @@ -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): diff --git a/app/test/test_example.py b/app/test/test_example.py index 443721e..54b0caa 100644 --- a/app/test/test_example.py +++ b/app/test/test_example.py @@ -3,5 +3,9 @@ def func(x): return x + 1 -def test_answer(): +def test_pass(): + assert func(4) == 5 + + +def test_failure(): assert func(3) == 5 \ No newline at end of file From 2a3f6c7fc6455b2af8aa60f143986ee66d3f9662 Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Sun, 17 Apr 2022 23:53:31 -0400 Subject: [PATCH 04/10] added nose2 for perspective --- .docker-compose/Dockerfile | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index 65e1df4..4c6c356 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -7,7 +7,7 @@ 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-spec +RUN python -m pip install nose2 RUN mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index cbdd950..edc5d19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ 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-spec +RUN python -m pip install nose2 RUN mkdir /app WORKDIR /app From e3d9b2e36effba0863dbb350be2e6bc641cb0b76 Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Tue, 19 Apr 2022 18:37:51 +0000 Subject: [PATCH 05/10] added yosh loop to test case --- app/test/test_example.py | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/app/test/test_example.py b/app/test/test_example.py index 54b0caa..35ec4b6 100644 --- a/app/test/test_example.py +++ b/app/test/test_example.py @@ -1,4 +1,6 @@ # content of example.py +from pulp import LpProblem, LpVariable, LpMinimize, LpStatus, lpSum + def func(x): return x + 1 @@ -8,4 +10,51 @@ def test_pass(): def test_failure(): - assert func(3) == 5 \ No newline at end of file + 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") + + 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) + break + +def test_solver(): + print(yosh_loop()) + assert yosh_loop() == 'Solved' From 0380401b2b0dd915ee39b28ea0ccf4bfb8e3e031 Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Tue, 19 Apr 2022 18:41:31 +0000 Subject: [PATCH 06/10] return value added --- app/test/test_example.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/test/test_example.py b/app/test/test_example.py index 35ec4b6..51198ee 100644 --- a/app/test/test_example.py +++ b/app/test/test_example.py @@ -33,6 +33,7 @@ def yosh_loop(): 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) @@ -53,8 +54,13 @@ def yosh_loop(): else: for v in prob.variables(): print(v.name, "=", v.varValue) + + result = LpStatus[prob.status] break + return result + + def test_solver(): print(yosh_loop()) - assert yosh_loop() == 'Solved' + assert yosh_loop() == 'Optimal' From e6e8f49816f4b6756b176933d9b793ed4b49718e Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Tue, 19 Apr 2022 14:49:31 -0400 Subject: [PATCH 07/10] formatting and print removal --- app/test/test_example.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/app/test/test_example.py b/app/test/test_example.py index 51198ee..acdc04e 100644 --- a/app/test/test_example.py +++ b/app/test/test_example.py @@ -1,6 +1,7 @@ # content of example.py from pulp import LpProblem, LpVariable, LpMinimize, LpStatus, lpSum + def func(x): return x + 1 @@ -12,22 +13,11 @@ def test_pass(): 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 - } + 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 @@ -37,12 +27,17 @@ def yosh_loop(): 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([(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 += 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() @@ -62,5 +57,4 @@ def yosh_loop(): def test_solver(): - print(yosh_loop()) assert yosh_loop() == 'Optimal' From 9054c92103d97cb378b86aab86966e9b6815928b Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Mon, 25 Apr 2022 18:27:06 +0000 Subject: [PATCH 08/10] remove nose2 --- .docker-compose/Dockerfile | 1 - Dockerfile | 1 - 2 files changed, 2 deletions(-) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index 4c6c356..b8715c1 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -7,7 +7,6 @@ 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 nose2 RUN mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index edc5d19..c41c12d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ 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 nose2 RUN mkdir /app WORKDIR /app From 3af90e317e8727c8629af0eddae98594c63d7300 Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Mon, 25 Apr 2022 18:31:06 +0000 Subject: [PATCH 09/10] adds test coverage --- .docker-compose/Dockerfile | 1 + Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index b8715c1..ec22307 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -7,6 +7,7 @@ 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 mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index c41c12d..4c9e296 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ 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 mkdir /app WORKDIR /app From 67a6303c45afa629a0955b0b473205add3bcfba6 Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Tue, 26 Apr 2022 16:51:29 +0000 Subject: [PATCH 10/10] add stub and mock --- .docker-compose/Dockerfile | 2 ++ Dockerfile | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index ec22307..593525a 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -8,6 +8,8 @@ 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 diff --git a/Dockerfile b/Dockerfile index 4c9e296..4c2bfb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,8 @@ 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