Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor "test" to a test #772

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pulp/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,3 @@ def col_based_arrays(self):
lenBase.append(len(elemBase) - startsBase[-1])
startsBase.append(len(elemBase))
return numEls, startsBase, lenBase, indBase, elemBase


if __name__ == "__main__":
"""unit test"""
rows = list(range(10))
cols = list(range(50, 60))
mat = Matrix(rows, cols)
mat.add(1, 52, "item")
mat.add(2, 54, "stuff")
print(mat.col_based_arrays())
23 changes: 12 additions & 11 deletions pulp/tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import pulp
from pulp.tests import test_pulp, test_examples, test_gurobipy_env
from pulp.tests import test_examples, test_gurobipy_env, test_pulp, test_sparse


def pulpTestAll(test_docs=False):
Expand All @@ -16,20 +17,20 @@ def pulpTestAll(test_docs=False):
raise pulp.PulpError("Tests Failed")


def get_test_suite(test_docs=False):
# Tests
def get_test_suite(test_docs: bool = False) -> unittest.TestSuite:
loader = unittest.TestLoader()
suite_all = unittest.TestSuite()
# we get suite with all PuLP tests
pulp_solver_tests = loader.loadTestsFromModule(test_pulp)
suite_all.addTests(pulp_solver_tests)
# Add tests for gurobipy env
gurobipy_env = loader.loadTestsFromModule(test_gurobipy_env)
suite_all.addTests(gurobipy_env)

suite_all.addTests(loader.loadTestsFromModule(test_pulp))
suite_all.addTests(loader.loadTestsFromModule(test_sparse))
suite_all.addTests(loader.loadTestsFromModule(test_gurobipy_env))

# We add examples and docs tests
if test_docs:
docs_examples = loader.loadTestsFromTestCase(test_examples.Examples_DocsTests)
suite_all.addTests(docs_examples)
suite_all.addTests(
loader.loadTestsFromTestCase(test_examples.Examples_DocsTests)
)

return suite_all


Expand Down
19 changes: 19 additions & 0 deletions pulp/tests/test_sparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from pulp.sparse import Matrix


class SparseTest(unittest.TestCase):
def test_sparse(self):
rows = list(range(10))
cols = list(range(50, 60))
mat = Matrix(rows, cols)
mat.add(1, 52, "item")
mat.add(2, 54, "stuff")
assert mat.col_based_arrays() == (
2,
[0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2],
[0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
[1, 2],
["item", "stuff"],
)