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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

def longestIncreasingSubsequence(nums):
def longest_increasing_subsequence(nums):
"""
Returns length of longest increasing subsequence given an array of numbers.
"""
Expand Down Expand Up @@ -33,7 +33,7 @@ def longestIncreasingSubsequence(nums):
testNumber = d['desc']
args = d['args'][0]
expected = d['res']
actual = longestIncreasingSubsequence(args)
actual = longest_increasing_subsequence(args)
if not actual == expected:
failedTests.append(testNumber)
allTestsPass = actual == expected and allTestsPass
Expand Down
47 changes: 25 additions & 22 deletions hard/longest_increasing_subsequence/tests.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
[
{
"desc": 1,
"args": [[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]],
"res": 6
},
{
"desc": 2,
"args": [[1, 2, 3, 4, 5]],
"res": 5
},
{
"desc": 3,
"args": [[1, 2, 0, 4, 5]],
"res": 4
},
{
"desc": 4,
"args": [[1, 2, 0, -4, 5]],
"res": 3
}
]
{
"title": "longest_increasing_subsequence",
"tests": [
{
"desc": 1,
"args": [[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]],
"res": 6
},
{
"desc": 2,
"args": [[1, 2, 3, 4, 5]],
"res": 5
},
{
"desc": 3,
"args": [[1, 2, 0, 4, 5]],
"res": 4
},
{
"desc": 4,
"args": [[1, 2, 0, -4, 5]],
"res": 3
}
]
}
32 changes: 32 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os, json, sys
from hard.longest_increasing_subsequence.longest_increasing_subsequence import *
tests_to_run = []

# Walk through directories, and look for tests.json files
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith("tests.json"):
with open(os.path.join(root, file), 'r') as f:
tests_to_run.append(json.load(f))

all_tests_passed = True
# Go through parsed tests
for tests in tests_to_run:
function = tests['title']
for t in tests['tests']:
parameters = ["(", None, ")"]
parameters[1] = ",".join([str(x) for x in t['args']])
parameters = "".join(parameters)
actual_result = eval(function + parameters) # Build function with parameters and evaluates it
expected_result = t['res']

# Prints test details if test failed
if actual_result != expected_result:
print("{}: Failed at test case {}".format(function, t['desc']))
print("Input: {}".format(t['args']))
print("Actual: {}".format(actual_result))
print("Expected: {}".format(expected_result))
all_tests_passed = False

if all_tests_passed:
print("All tests passed")
Empty file removed tests/test_medium.py
Empty file.