As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code.
Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code.
Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code.
Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task:
Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code.
Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code. Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted)code. Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
Here is what I have done:. I would like to know how I might improve it.
I would like to know how I might improve it.
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code. Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
Here is what I have done:
I would like to know how I might improve it.
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code.
Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
Here is what I have done. I would like to know how I might improve it.
Create a full automation test suite using a mock file
As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task: Create a full automation test suite (in Python3), so that when our developers finish writing the code, we will all be able to immediately test the code. Note: This task should be completed without using the actual binary file. We recommend that you create your own mock file in working on this task.
./MyBinary --add [[int]] Adds an integer to an online database that the binary is connected to. Example: ./MyBinary --add 5678
./MyBinary --clear Deletes all the integers from the online database that the binary is connected to
./MyBinary --isSorted Prints whether all the numbers in the database (since the start/last clear) were added from smallest number to biggest. Output to the standard output: "True" or "False"
./MyBinary --count [[int]] Prints how many times this number is stored in the database (since the start/last clear) Example: ./MyBinary --count 5678 Output to the standard output: "0" or "1" or "2" or .... ./MyBinary --getAll Returns all the numbers stored in the database (the number returns in a random order, not necessarily the order they were inserted). Example output to the standard output: "5 17 3 25 4 25 6 25"
In order to carry out this task, I created Application.py as a mock application, which can run as a CLI application. Then I created TestSuite.py including all the test cases with comments .
Here is what I have done:
Application.py
import click
import csv
import os
FILE = 'data.csv'
@click.command()
@click.option('--add', help='Adds an integer to an online database that the binary is connected to.')
@click.option('--clear',
help='Deletes all the integers from the online database that the binary is connected to')
@click.option('--issorted', help='Prints whether all the numbers in the database')
@click.option('--getall', help='Prints how many times this number is stored in the database')
@click.option('--count', help='Returns all the numbers stored in the database ')
def main(add, clear, issorted, getall, count):
if add:
"""
./MyBinary --add [[int]]
Adds an integer to an online database that the binary is connected to.
Example: ./MyBinary --add 5678
"""
try:
with open(FILE, 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([add])
file.close()
return
except Exception as er:
return er
elif clear:
"""
./MyBinary --clear
Deletes all the integers from the online database that the binary is connected to
"""
if os.path.exists(FILE):
os.remove(FILE)
elif issorted:
"""
./MyBinary --isSorted
Prints whether all the numbers in the database (since the start/last clear) were added
from smallest number to biggest.
Output to the standard output: "True" or "False"
"""
with open(FILE, 'r') as f:
data = f.read()
l = [int(i) for i in data.split()]
print(all(l[i] <= l[i+1] for i in range(len(l)-1)))
elif count:
"""
./MyBinary --count [[int]]
Prints how many times this number is stored in the database (since the start/last
clear)
Example: ./MyBinary --count 5678
Output to the standard output: "0" or "1" or "2" or ....
"""
try:
results = []
with open(FILE) as file:
reader = csv.reader(file)
for row in reader:
if int(count) == int(row[0]):
results.append(int(row[0]))
file.close()
print(len(results))
except Exception as er:
print(er)
elif getall:
"""
./MyBinary --getAll
Returns all the numbers stored in the database (the number returns in a random
order, not necessarily the order they were inserted).
Example output to the standard output: "5 17 3 25 4 25 6 25"
"""
with open(FILE, 'r') as f:
data = f.read()
print([int(i) for i in data.split()])
if __name__ == '__main__':
main()
TestSuite.py
import pytest
import numpy as np
import subprocess
from subprocess import check_output
class TestSuite:
def __init__(self):
"""
CLI Application path, this should be the exact path to the application executable
"""
self.applicationPath = "mockApplication/Application.py"
def test_add(self, newNumber):
""" Test Case 01
Adds an integer to an online database that the binary is connected to.
Iterate for all array elements of the random array.
No output should be there.
"""
try:
result = subprocess.run(["python", self.applicationPath, "--add", str(newNumber)])
print(result)
assert result.returncode is 0
except Exception as e:
print(e)
def test_clear(self):
""" Test Case 2
Deletes all the integers from the data store. There should not be any value after executing this function.
No output
"""
result = subprocess.run(["python", self.applicationPath, "--clear", " "])
assert result.stdout is None
def test_isSorted(self, expected):
"""
Test Case 3
Prints whether all the numbers in the database were added
from smallest number to biggest.
Output to the standard output: "True" or "False"
"""
out = check_output(["python", self.applicationPath, "--issorted", " "])
assert expected is bool(out.decode('utf-8'))
def test_count(self, number, expected):
"""
Test case 4
Prints how many times a given number is stored in the database.
"""
out = check_output(["python", self.applicationPath, "--count", str(number)])
assert expected is int(out.decode('utf-8'))
def test_getAll(self, expected):
""" Test Case 5
Returns all the numbers stored in the database ,
not necessarily the order they were inserted.
"""
out = check_output(["python", self.applicationPath, "--getall", " "])
str1 = out.decode('utf-8').replace(']', '').replace('[', '').replace("\r\n", "")
arr = str1.split(",")
l = [int(x) for x in arr]
assert expected == l
if __name__ == '__main__':
"""
Generate a random integer array with 5 numbers between 1 and 10
to be used as the test data for this test suite
"""
testData = [1, 2, 3, 4, 10, 100, 1000, 10000]
testDataFinal = [1, 2, 3, 4, 10, 100, 1000, 10000, 10]
specialNumber = 10
# initialize test suite
testSuite = TestSuite()
# clear data
testSuite.test_clear()
# add numbers
for number in testData:
testSuite.test_add(number)
# check number of occurrences for 10, there should be 1
testSuite.test_count(10, 1)
# check is sorted
testSuite.test_isSorted(True)
# add special number
testSuite.test_add(specialNumber)
# check number of occurrences for 10, there should be 2
testSuite.test_count(specialNumber, 2)
I would like to know how I might improve it.