From e6bdeb8a5b679ee6f92a204910da8dbb7eb296b1 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 26 Jun 2019 16:44:35 +0530 Subject: [PATCH] Increased coverage (#20) * increased coverage * gitignore updated --- .gitignore | 1 + pydatastructs/linear_data_structures/tests/test_arrays.py | 5 ++++- pydatastructs/miscellaneous_data_structures/stack.py | 2 +- .../miscellaneous_data_structures/tests/test_stack.py | 5 ++++- pydatastructs/trees/tests/test_binary_trees.py | 3 +++ pydatastructs/trees/tests/test_space_partitioning_tree.py | 3 +-- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2d5590d69..999995a84 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__/ .vscode/ .pytest_cache/ pre_commit.ps1 +.coverage diff --git a/pydatastructs/linear_data_structures/tests/test_arrays.py b/pydatastructs/linear_data_structures/tests/test_arrays.py index d9799679b..fe3adf0e4 100644 --- a/pydatastructs/linear_data_structures/tests/test_arrays.py +++ b/pydatastructs/linear_data_structures/tests/test_arrays.py @@ -4,10 +4,13 @@ def test_OneDimensionalArray(): ODA = OneDimensionalArray - assert ODA(int, 5, [1, 2, 3, 4, 5], init=6) + A = ODA(int, 5, [1, 2, 3, 4, 5], init=6) + assert A assert ODA(int, (1, 2, 3, 4, 5), 5) assert ODA(int, 5) assert ODA(int, [1, 2, 3]) + raises(IndexError, lambda: A[7]) + raises(IndexError, lambda: A[-1]) raises(ValueError, lambda: ODA()) raises(ValueError, lambda: ODA(int, 1, 2, 3)) raises(TypeError, lambda: ODA(int, 5.0, set([1, 2, 3]))) diff --git a/pydatastructs/miscellaneous_data_structures/stack.py b/pydatastructs/miscellaneous_data_structures/stack.py index b840cedd4..79dba575d 100644 --- a/pydatastructs/miscellaneous_data_structures/stack.py +++ b/pydatastructs/miscellaneous_data_structures/stack.py @@ -80,7 +80,7 @@ def __new__(cls, maxsize=None, top=0, items=None, dtype=int): if not _check_type(maxsize, int): raise ValueError("maxsize is missing.") if not _check_type(top, int): - raise ValueError("top is missing.") + raise TypeError("top is not of type int.") if items == None: items = OneDimensionalArray(dtype, maxsize) if not _check_type(items, OneDimensionalArray): diff --git a/pydatastructs/miscellaneous_data_structures/tests/test_stack.py b/pydatastructs/miscellaneous_data_structures/tests/test_stack.py index ce0343d22..614b51637 100644 --- a/pydatastructs/miscellaneous_data_structures/tests/test_stack.py +++ b/pydatastructs/miscellaneous_data_structures/tests/test_stack.py @@ -17,6 +17,9 @@ def test_Stack(): assert s.top == 0 raises(ValueError, lambda: s.pop()) raises(ValueError, lambda: Stack()) + raises(TypeError, lambda: Stack(maxsize=8, top=3.5)) raises(ValueError, lambda: Stack(maxsize=5, top=0, items=[1, 2, 3])) raises(ValueError, lambda: Stack(maxsize=5, top=0, - items=OneDimensionalArray(6))) + items=OneDimensionalArray(int, 6))) + raises(NotImplementedError, lambda: Stack(implementation='', + maxsize=5, top=0)) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index ca64f6c3c..8152105c3 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -24,8 +24,11 @@ def test_BinarySearchTree(): assert b.search(10) == None assert b.delete(3) == True assert b.search(3) == None + assert b.delete(13) == None assert str(b) == \ ("[(1, 8, 8, 7), (3, 4, 4, 4), (None, 10, 10, 7), (None, 1, 1, None), " "(None, 6, 6, 6), (None, 4, 4, None), (None, 7, 7, None), (None, 14, 14, None), " "(None, 13, 13, None)]") + bc = BST(1, 1) + assert bc.insert(1, 2) == None raises(ValueError, lambda: BST(root_data=6)) diff --git a/pydatastructs/trees/tests/test_space_partitioning_tree.py b/pydatastructs/trees/tests/test_space_partitioning_tree.py index 40263e69f..586ced204 100644 --- a/pydatastructs/trees/tests/test_space_partitioning_tree.py +++ b/pydatastructs/trees/tests/test_space_partitioning_tree.py @@ -5,8 +5,6 @@ def test_OneDimensionalSegmentTree(): ODST = OneDimensionalSegmentTree segt = ODST([(0, 5), (1, 6), (9, 13), (1, 2), (3, 8), (9, 20)]) assert segt.cache == False - segt.build() - assert segt.cache == True segt2 = ODST([(1, 4)]) assert str(segt2) == ("[(None, [False, 0, 1, False], None, None), " "(None, [True, 1, 1, True], ['(None, [True, 1, 4, True], None, None)'], " @@ -16,6 +14,7 @@ def test_OneDimensionalSegmentTree(): "None, 5), (None, [False, 4, 5, False], None, None), (-3, [False, 0, 5, " "False], None, -2)]") assert len(segt.query(1.5)) == 3 + assert segt.cache == True assert len(segt.query(-1)) == 0 assert len(segt.query(2.8)) == 2 raises(ValueError, lambda: ODST([(1, 2, 3)]))