Created
October 23, 2018 23:39
-
-
Save roxsula/2203b9b5cf7b49b547810ba1701f7850 to your computer and use it in GitHub Desktop.
Generator of input test cases for linked lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Test Suite: | |
Node class | |
LinkedList class with methods insert_tail(data) and monitoring() | |
genTestCases class with methods generateCustomTestCase(values), generateRandomTestCase(max_len, max_val), generateEqualValuesTestCase(max_len, val) | |
runTests(): | |
Custom your tests | |
DebugL1 will show the results of each TestCase | |
DebugL2 will show the linked list generated | |
''' | |
#******************** TEST SUITE ********************# | |
class Node: | |
def __init__(self, data=None, next=None): | |
self.data = data | |
self.next = next | |
class LinkedList(Node): | |
def __init__(self, head=None): | |
self.head = head | |
def insert_tail(self, data): | |
if (self.head == None): | |
self.head = Node(data) | |
else: | |
current = self.head | |
while (current.next != None): | |
current = current.next | |
current.next = Node(data) | |
def monitoring(self): | |
node = self.head | |
while node != None: | |
print(node.data), | |
node = node.next | |
print('\n') | |
class genTestCases(LinkedList): | |
def __init__(self, debug = False): | |
self.test_list = LinkedList() | |
self.arr = [] | |
self.debug = debug | |
#User set specific values | |
def generateCustomTestCase(self, values): | |
self.arr = values | |
for i in values: | |
self.test_list.insert_tail(i) | |
if self.debug: | |
print('Custom Test') | |
print('Reference Array = {}'.format(self.arr)) | |
print('linked list') | |
self.test_list.monitoring() | |
#User set max list length desired and the max value of the nodes | |
def generateRandomTestCase(self, max_len, max_val): | |
length = random.randint(0, max_len) | |
for j in range(length): | |
rand_val = random.randint(0, max_len ) | |
self.test_list.insert_tail(rand_val) | |
self.arr.append(rand_val) | |
if self.debug: | |
print('Random Test') | |
print('Reference Array = {}'.format(self.arr)) | |
print('linked list') | |
self.test_list.monitoring() | |
#User set max list length and the value to repeat | |
def generateEqualValuesTestCase(self, max_len, val): | |
self.arr = max_len * [val] | |
for k in range(max_len): | |
self.test_list.insert_tail(val) | |
if self.debug: | |
print('Equal Values') | |
print('Reference Array = {}'.format(self.arr)) | |
print('linked list') | |
self.test_list.monitoring() | |
#****************** TEST EXECUTION *******************# | |
def runTests(debugL1=False, debugL2 = False, negTesting=False): | |
#This is only an example of how test cases can be generate to test linked list. | |
#you can use debugL1 var to set specific debug messages | |
#you can add your own return codes. And fail/pass criteria | |
#Generates Test Cases Objects | |
TC = [genTestCases(debug=debugL2) for i in range(2)] | |
#Counters for pass/fail cases | |
testCasePassed = 0 | |
testCaseFailed = 0 | |
'''Sequential positive numbers''' | |
TC[0].generateCustomTestCase([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | |
TC[0].test_list.monitoring() #Linked List | |
print(TC[0].arr)#Reference Array | |
'''Random Test 0 <= length,values <= 100''' | |
TC[1].generateRandomTestCase(100,100) | |
TC[1].test_list.monitoring() #Linked List | |
print(TC[1].arr)#Reference Array | |
if debugL1: | |
print('TEST FINISHED') | |
return 0 | |
#******************** USE CASES ********************# | |
runTests() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment