Skip to content

Commit

Permalink
add: added node tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warmachine028 committed Aug 3, 2023
1 parent 811b5e9 commit d1f2cae
Show file tree
Hide file tree
Showing 21 changed files with 537 additions and 189 deletions.
8 changes: 4 additions & 4 deletions tests/arrays_tests/priority_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional, Any

from datastax.Arrays import PriorityQueue
from datastax.errors import UnderFlowError, OverFlowError
from datastax.Utils.Exceptions import UnderflowException, OverflowException


class TestPriorityQueue(unittest.TestCase):
Expand All @@ -20,7 +20,7 @@ def test_complete_fill_complete_empty(self):
self.limitedPriorityQueue.enqueue(20)

# Should raise overflow error
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedPriorityQueue.enqueue(30)

# Completely Emptied
Expand All @@ -43,7 +43,7 @@ def test_construction(self):
self.assertEqual([], self.items_in(queue))

def test_dequeue_from_empty_queue(self):
with self.assertRaises(UnderFlowError):
with self.assertRaises(UnderflowException):
self.limitedPriorityQueue.dequeue()
self.unlimitedPriorityQueue.dequeue()

Expand All @@ -57,7 +57,7 @@ def test_enqueue_in_full_queue(self):
self.limitedPriorityQueue.enqueue(30)
self.limitedPriorityQueue.enqueue(40)
self.assertEqual([40, 30], self.items_in(self.limitedPriorityQueue))
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedPriorityQueue.enqueue(50)

self.unlimitedPriorityQueue.enqueue(30)
Expand Down
8 changes: 4 additions & 4 deletions tests/arrays_tests/queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Any

from datastax.Arrays import Queue
from datastax.errors import UnderFlowError, OverFlowError
from datastax.Utils.Exceptions import UnderflowException, OverflowException
from datastax.Lists import LinkedList


Expand All @@ -18,7 +18,7 @@ def test_complete_fill_complete_empty(self):
self.limitedQueue.enqueue(20)

# Should raise overflow error
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedQueue.enqueue(30)

# Completely Emptied
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_construction(self):
self.assertEqual([], self.items_in(queue))

def test_dequeue_from_empty_queue(self):
with self.assertRaises(UnderFlowError):
with self.assertRaises(UnderflowException):
self.limitedQueue.dequeue()
self.unlimitedQueue.dequeue()

Expand All @@ -64,7 +64,7 @@ def test_enqueue_in_full_queue(self):
self.limitedQueue.enqueue(30)
self.limitedQueue.enqueue(40)
self.assertEqual([30, 40], self.items_in(self.limitedQueue))
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedQueue.enqueue(50)

self.unlimitedQueue.enqueue(30)
Expand Down
8 changes: 4 additions & 4 deletions tests/arrays_tests/stack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Any

from datastax.Arrays import Stack
from datastax.errors import UnderFlowError, OverFlowError
from datastax.Utils.Exceptions import UnderflowException, OverflowException
from datastax.Lists import LinkedList


Expand All @@ -18,7 +18,7 @@ def test_complete_fill_complete_empty(self):
self.limitedStack.push(20)

# Should raise overflow error
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedStack.push(30)

# Completely Emptied
Expand All @@ -41,7 +41,7 @@ def test_construction(self):
self.assertEqual([], self.items_in(stack))

def test_dequeue_from_empty_queue(self):
with self.assertRaises(UnderFlowError):
with self.assertRaises(UnderflowException):
self.limitedStack.pop()
self.unlimitedStack.pop()

Expand All @@ -55,7 +55,7 @@ def test_enqueue_in_full_queue(self):
self.limitedStack.push(30)
self.limitedStack.push(40)
self.assertEqual([30, 40], self.items_in(self.limitedStack))
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedStack.push(50)

self.unlimitedStack.push(30)
Expand Down
8 changes: 4 additions & 4 deletions tests/list_tests/queue_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import unittest
from typing import Optional, Any
from datastax.errors import UnderFlowError, OverFlowError
from datastax.Utils.Exceptions import UnderflowException, OverflowException
from datastax.Lists import Queue, LinkedList


Expand All @@ -24,7 +24,7 @@ def test_complete_fill_complete_empty(self):
self.limitedQueue.enqueue(20)

# Should raise overflow error
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedQueue.enqueue(30)

# Completely Emptied
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_construction(self):
self.assertEqual([], self.items_in(queue))

def test_dequeue_from_empty_queue(self):
with self.assertRaises(UnderFlowError):
with self.assertRaises(UnderflowException):
self.limitedQueue.dequeue()
self.unlimitedQueue.dequeue()

Expand All @@ -69,7 +69,7 @@ def test_enqueue_in_full_queue(self):
self.limitedQueue.enqueue(30)
self.limitedQueue.enqueue(40)
self.assertEqual([30, 40], self.items_in(self.limitedQueue))
with self.assertRaises(OverFlowError):
with self.assertRaises(OverflowException):
self.limitedQueue.enqueue(50)

self.unlimitedQueue.enqueue(30)
Expand Down
1 change: 0 additions & 1 deletion tests/node_tests/doubly_node_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest

from datastax.Nodes import Node, DoublyNode


Expand Down
6 changes: 3 additions & 3 deletions tests/node_tests/node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_string_with_none(self):
' │ None ║ ------> NULL\n' \
' └────────╨────┘\n'

self.assertEqual(result, Node(self.test_cases[0]).__str__())
self.assertEqual(result, str(Node(self.test_cases[0])))

def test_string_with_list(self):
result = \
' ┌───────╥────┐\n' \
' │ [1] ║ ------> NULL\n' \
' └───────╨────┘\n'

self.assertEqual(result, Node(self.test_cases[1]).__str__())
self.assertEqual(result, str(Node(self.test_cases[1])))

def test_string_with_combination(self):
result = \
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_next_as_None(self):

def test_next_as_NonNode(self):
next_item = ['Non Node Item']
self.assertRaises(TypeError, lambda: Node('data', next_item))
self.assertRaises(TypeError, lambda: Node('data', _next=next_item))

def test_next_set_manually(self):
next_item = Node(10)
Expand Down
44 changes: 44 additions & 0 deletions tests/node_tests/threaded_node_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest
from datastax.Nodes import ThreadedNode


class TestThreadedNode(unittest.TestCase):

def _test_string(self):
result = \
' \n' \
'│ 1 │\n' \
'└───┴───┘\n'
self.assertEqual(str(ThreadedNode(1)), result)
result = \
' \n' \
'│ 12 │\n' \
'└───┴───┘\n'
self.assertEqual(str(ThreadedNode(12)), result)
result = \
' \n' \
'│ 123 │\n' \
'└────┴────┘\n'
self.assertEqual(str(ThreadedNode(123)), result)

def _test_string_with_left(self):
result = \
(' \n'
' 1 │\n'
'┌───┴───┘\n'
'20')
self.assertEqual(str(ThreadedNode(1, ThreadedNode(20))), result)
# result = \
# ' \n' \
# '│ 12 │\n' \
# '└───┴───┘\n'
# self.assertEqual(str(ThreadedNode(12)), result)
# result = \
# ' \n' \
# '│ 123 │\n' \
# '└────┴────┘\n'
# self.assertEqual(str(ThreadedNode(123)), result)


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit d1f2cae

Please sign in to comment.