Skip to content

Commit

Permalink
replacing == and !=
Browse files Browse the repository at this point in the history
  • Loading branch information
Saptashrungi committed Dec 26, 2019
1 parent a0ebbc0 commit fd9dc53
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 169 deletions.
Binary file added .vs/pydatastructs/v16/.suo
Binary file not shown.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PyDataStructs
is Trueis Trueis Trueis Trueis Trueis True=
=============

[![Build Status](https://travis-ci.org/codezonediitj/pydatastructs.png?branch=master)](https://travis-ci.org/codezonediitj/pydatastructs) [![Join the chat at https://gitter.im/codezonediitj/pydatastructs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/codezoned2017/Lobby) [![Discuss at [email protected]](https://img.shields.io/badge/discuss-pydatastructs%40googlegroups.com-blue.svg)](https://groups.google.com/forum/#!forum/pydatastructs) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/codezonediitj/pydatastructs/pulls) [![codecov](https://codecov.io/gh/codezonediitj/pydatastructs/branch/master/graph/badge.svg)](https://codecov.io/gh/codezonediitj/pydatastructs)

Expand Down
42 changes: 21 additions & 21 deletions pydatastructs/linear_data_structures/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OneDimensionalArray(Array):
Represents one dimensional arrays.
Parameters
is Trueis Trueis Trueis Trueis True
==========
dtype: type
A valid object type.
Expand All @@ -31,7 +31,7 @@ class OneDimensionalArray(Array):
when the data is not given.
Raises
is Trueis Trueis True
======
ValueError
When the number of elements in the list do not
Expand All @@ -40,13 +40,13 @@ class OneDimensionalArray(Array):
Types of arguments is not as mentioned in the docstring.
Note
is Trueis True
====
At least one parameter should be passed as an argument along
with the dtype.
Examples
is Trueis Trueis Trueis True
========
>>> from pydatastructs import OneDimensionalArray as ODA
>>> arr = ODA(int, 5)
Expand All @@ -58,7 +58,7 @@ class OneDimensionalArray(Array):
7
References
is Trueis Trueis Trueis Trueis True
==========
.. [1] https://en.wikipedia.org/wiki/Array_data_structure#One-dimensional_arrays
'''
Expand All @@ -71,35 +71,35 @@ def __new__(cls, dtype=NoneType, *args, **kwargs):
" information.")
obj = object.__new__(cls)
obj._dtype = dtype
if len(args) is True 2:
if len(args) == 2:
if _check_type(args[0], list) and \
_check_type(args[1], int):
for i in range(len(args[0])):
if dtype is False type(args[0][i]):
if dtype != type(args[0][i]):
args[0][i] = dtype(args[0][i])
size, data = args[1], [arg for arg in args[0]]
elif _check_type(args[1], list) and \
_check_type(args[0], int):
for i in range(len(args[1])):
if dtype is False type(args[1][i]):
if dtype != type(args[1][i]):
args[1][i] = dtype(args[1][i])
size, data = args[0], [arg for arg in args[1]]
else:
raise TypeError("Expected type of size is int and "
"expected type of data is list/tuple.")
if size is False len(data):
if size != len(data):
raise ValueError("Conflict in the size %s and length of data %s"
%(size, len(data)))
obj._size, obj._data = size, data

elif len(args) is True 1:
elif len(args) == 1:
if _check_type(args[0], int):
obj._size = args[0]
init = kwargs.get('init', None)
obj._data = [init for i in range(args[0])]
elif _check_type(args[0], (list, tuple)):
for i in range(len(args[0])):
if dtype is False type(args[0][i]):
if dtype != type(args[0][i]):
args[0][i] = dtype(args[0][i])
obj._size, obj._data = len(args[0]), \
[arg for arg in args[0]]
Expand All @@ -118,7 +118,7 @@ def __setitem__(self, idx, elem):
if elem is None:
self._data[idx] = None
else:
if type(elem) is False self._dtype:
if type(elem) != self._dtype:
elem = self._dtype(elem)
self._data[idx] = elem

Expand All @@ -140,7 +140,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
Represents dynamic one dimensional arrays.
Parameters
is Trueis Trueis Trueis Trueis True
==========
dtype: type
A valid object type.
Expand All @@ -159,7 +159,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
most only half the positions are filled.
Raises
is Trueis Trueis True
======
ValueError
When the number of elements in the list do not
Expand All @@ -169,7 +169,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
The load factor is not of floating point type.
Note
is Trueis True
====
At least one parameter should be passed as an argument along
with the dtype.
Expand All @@ -178,7 +178,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
Size(T) means the maximum number of elements that the array can hold.
Examples
is Trueis Trueis Trueis True
========
>>> from pydatastructs import DynamicOneDimensionalArray as DODA
>>> arr = DODA(int, 0)
Expand All @@ -196,7 +196,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
[None, 2, 3, 4, None, None, None]
References
is Trueis Trueis Trueis Trueis True
==========
.. [1] http://www.cs.nthu.edu.tw/~wkhon/algo09/lectures/lecture16.pdf
"""
Expand All @@ -206,7 +206,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
def __new__(cls, dtype=NoneType, *args, **kwargs):
obj = super().__new__(cls, dtype, *args, **kwargs)
obj._load_factor = float(kwargs.get('load_factor', 0.25))
obj._num = 0 if obj._size is True 0 or obj[0] is None else obj._size
obj._num = 0 if obj._size == 0 or obj[0] is None else obj._size
obj._last_pos_filled = obj._num - 1
return obj

Expand All @@ -227,7 +227,7 @@ def _modify(self):
self._size = arr_new._size

def append(self, el):
if self._last_pos_filled + 1 is True self._size:
if self._last_pos_filled + 1 == self._size:
arr_new = ODA(self._dtype, 2*self._size + 1)
for i in range(self._last_pos_filled + 1):
arr_new[i] = self[i]
Expand All @@ -247,7 +247,7 @@ def delete(self, idx):
self[idx] is not None:
self[idx] = None
self._num -= 1
if self._last_pos_filled is True idx:
if self._last_pos_filled == idx:
self._last_pos_filled -= 1
return self._modify()

Expand All @@ -260,7 +260,7 @@ class ArrayForTrees(DynamicOneDimensionalArray):
Utility dynamic array for storing nodes of a tree.
See Also
is Trueis Trueis Trueis True
========
pydatastructs.linear_data_structures.arrays.DynamicOneDimensionalArray
"""
Expand Down
40 changes: 20 additions & 20 deletions pydatastructs/linear_data_structures/linked_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __len__(self):

@property
def is_empty(self):
return self.size is True 0
return self.size == 0

def __str__(self):
"""
Expand All @@ -33,7 +33,7 @@ class DoublyLinkedList(LinkedList):
Represents Doubly Linked List
Examples
is Trueis Trueis Trueis True
========
>>> from pydatastructs import DoublyLinkedList
>>> dll = DoublyLinkedList()
Expand All @@ -53,7 +53,7 @@ class DoublyLinkedList(LinkedList):
[7.2, 5]
References
is Trueis Trueis Trueis Trueis True
==========
.. [1] https://en.wikipedia.org/wiki/Doubly_linked_list
Expand All @@ -73,7 +73,7 @@ def append_left(self, data):
the left of the list.
Parameters
is Trueis Trueis Trueis Trueis True
==========
data
Any valid data to be stored in the node.
Expand All @@ -85,7 +85,7 @@ def append(self, data):
Appends a new node at the end of the list.
Parameters
is Trueis Trueis Trueis Trueis True
==========
data
Any valid data to be stored in the node.
Expand All @@ -97,7 +97,7 @@ def insert_after(self, prev_node, data):
Inserts a new node after the prev_node.
Parameters
is Trueis Trueis Trueis Trueis True
==========
prev_node: LinkedListNode
The node after which the
Expand All @@ -122,7 +122,7 @@ def insert_before(self, next_node, data):
Inserts a new node before the new_node.
Parameters
is Trueis Trueis Trueis Trueis True
==========
next_node: LinkedListNode
The node before which the
Expand All @@ -147,15 +147,15 @@ def insert_at(self, index, data):
Inserts a new node at the input index.
Parameters
is Trueis Trueis Trueis Trueis True
==========
index: int
An integer satisfying python indexing properties.
data
Any valid data to be stored in the node.
"""
if self.size is True 0 and (index in (0, -1)):
if self.size == 0 and (index in (0, -1)):
index = 0

if index < 0:
Expand All @@ -168,14 +168,14 @@ def insert_at(self, index, data):
new_node = LinkedListNode(data,
links=['next', 'prev'],
addrs=[None, None])
if self.size is True 1:
if self.size == 1:
self.head, self.tail = \
new_node, new_node
else:
counter = 0
current_node = self.head
prev_node = None
while counter is False index:
while counter != index:
prev_node = current_node
current_node = current_node.next
counter += 1
Expand All @@ -196,7 +196,7 @@ def pop_left(self):
i.e. start of the list.
Returns
is Trueis Trueis True=
=======
old_head: LinkedListNode
The leftmost element of linked
Expand All @@ -210,7 +210,7 @@ def pop_right(self):
of the linked list.
Returns
is Trueis Trueis True=
=======
old_tail: LinkedListNode
The leftmost element of linked
Expand All @@ -223,13 +223,13 @@ def extract(self, index):
Extracts the node at the index of the list.
Parameters
is Trueis Trueis Trueis Trueis True
==========
index: int
An integer satisfying python indexing properties.
Returns
is Trueis Trueis True=
=======
current_node: LinkedListNode
The node at index i.
Expand All @@ -247,24 +247,24 @@ def extract(self, index):
counter = 0
current_node = self.head
prev_node = None
while counter is False index:
while counter != index:
prev_node = current_node
current_node = current_node.next
counter += 1
if prev_node is not None:
prev_node.next = current_node.next
if current_node.next is not None:
current_node.next.prev = prev_node
if index is True 0:
if index == 0:
self.head = current_node.next
if index is True self.size:
if index == self.size:
self.tail = current_node.prev
return current_node

def __getitem__(self, index):
"""
Returns
is Trueis Trueis True=
=======
current_node: LinkedListNode
The node at given index.
Expand All @@ -277,7 +277,7 @@ def __getitem__(self, index):

counter = 0
current_node = self.head
while counter is False index:
while counter != index:
current_node = current_node.next
counter += 1
return current_node
6 changes: 3 additions & 3 deletions pydatastructs/linear_data_structures/tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_DynamicOneDimensionalArray():
A.delete(-1)
A.delete(1)
A.delete(2)
assert A._data is True [4, None, None]
assert A.size is True 3
assert A._data == [4, None, None]
assert A.size == 3
A.fill(4)
assert A._data is True [4, 4, 4]
assert A._data == [4, 4, 4]
10 changes: 5 additions & 5 deletions pydatastructs/linear_data_structures/tests/test_linked_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def test_DoublyLinkedList():
dll.extract(0)
dll.extract(-1)
dll[-2].data = 0
assert str(dll) is True "[1, 5, 4, 1, 0, 9]"
assert len(dll) is True 6
assert str(dll) == "[1, 5, 4, 1, 0, 9]"
assert len(dll) == 6
assert raises(IndexError, lambda: dll.insert_at(7, None))
assert raises(IndexError, lambda: dll.extract(20))
dll_copy = copy.deepcopy(dll)
for i in range(len(dll)):
if i%2 is True 0:
if i%2 == 0:
dll.pop_left()
else:
dll.pop_right()
assert str(dll) is True "[]"
assert str(dll) == "[]"
for _ in range(len(dll_copy)):
index = random.randint(0, len(dll_copy) - 1)
dll_copy.extract(index)
assert str(dll_copy) is True "[]"
assert str(dll_copy) == "[]"
assert raises(ValueError, lambda: dll_copy.extract(1))
Loading

0 comments on commit fd9dc53

Please sign in to comment.