Skip to content
Open
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
50 changes: 50 additions & 0 deletions linkedlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Define the class to be tested
class Node:
def __init__(self, value):
self.value = value
self.next = None

class LinkedList:
def __init__(self):
self.head = None

def append(self, value):
new_node = Node(value)
if not self.head:
self.head = new_node
else:
current = self.head
while current.next:
current = current.next
current.next = new_node

def find_max(self) -> int:
if not self.head:
raise ValueError("Empty list")

max_value = self.head.value
current = self.head.next # Start from the second node
while current:
if current.value > max_value:
max_value = current.value
current = current.next

return max_value

# Define test functions for LinkedList
def test_linked_list():
ll = LinkedList() # Correct instantiation
ll.append(3)
ll.append(1)
ll.append(4)
ll.append(2)
assert ll.find_max() == 4 # Test for the highest value
print("test_linked_list passed!")



#Run the test

if __name__=="__main__":
test_linked_list()
print("linked_list test passed!")
16 changes: 16 additions & 0 deletions reverse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Define the function to be tested
def reverse_string(s: str) -> str:
return s[::-1] # Simple implementation using slicing

# Define test functions
def test_reverse_string():
assert reverse_string("hello") == "olleh"
assert reverse_string("Python") == "nohtyP"
assert reverse_string("") == ""
print("test_reverse_string passed")


#Run all tests
if __name__ == "__main__":
test_reverse_string()
print("reverse_string passed!")
31 changes: 31 additions & 0 deletions stacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Define the class to be tested
class QueueWithStacks:
def __init__(self):
self.stack1 = []
self.stack2 = []

def enqueue(self, x: int):
self.stack1.append(x)

def dequeue(self) -> int:
if not self.stack2:
while self.stack1:self.stack2.append(self.stack1.pop())
if not self.stack2:
raise IndexError("dequeue from empty queue")
return self.stack2.pop()

# Define test functions
def test_queue_with_stacks():
q = QueueWithStacks()
q.enqueue(1)
q.enqueue(2)
assert q.dequeue() == 1
assert q.dequeue() == 2
print("test_queue_with_stacks passed")



#Run the test
if __name__=="__main__":
test_queue_with_stacks()
print("queue_with stack test is passed!")
85 changes: 85 additions & 0 deletions test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Define the function to be tested
def reverse_string(s: str) -> str:
return s[::-1] # Simple implementation using slicing

# Define test functions
def test_reverse_string():
assert reverse_string("hello") == "olleh"
assert reverse_string("Python") == "nohtyP"
assert reverse_string("") == ""
print("test_reverse_string passed")

# Define the class to be tested
class QueueWithStacks:
def __init__(self):
self.stack1 = []
self.stack2 = []

def enqueue(self, x: int):
self.stack1.append(x)

def dequeue(self) -> int:
if not self.stack2:
while self.stack1:self.stack2.append(self.stack1.pop())
if not self.stack2:
raise IndexError("dequeue from empty queue")
return self.stack2.pop()

# Define test functions
def test_queue_with_stacks():
q = QueueWithStacks()
q.enqueue(1)
q.enqueue(2)
assert q.dequeue() == 1
assert q.dequeue() == 2
print("test_queue_with_stacks passed")

# Define the class to be tested
class Node:
def __init__(self, value):
self.value = value
self.next = None

class LinkedList:
def __init__(self):
self.head = None

def append(self, value):
new_node = Node(value)
if not self.head:
self.head = new_node
else:
current = self.head
while current.next:
current = current.next
current.next = new_node

def find_max(self) -> int:
if not self.head:
raise ValueError("Empty list")

max_value = self.head.value
current = self.head.next # Start from the second node
while current:
if current.value > max_value:
max_value = current.value
current = current.next

return max_value

# Define test functions for LinkedList
def test_linked_list():
ll = LinkedList() # Correct instantiation
ll.append(3)
ll.append(1)
ll.append(4)
ll.append(2)
assert ll.find_max() == 4 # Test for the highest value
print("test_linked_list passed!")

# Run all tests
if __name__ == "__main__":
test_reverse_string()
test_queue_with_stacks()
test_linked_list()
print("All tests passed!")