Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test cases for HWB Functions, problems 1 and 2
# Function test cases
f1 = {0:[1], 1:[2], 2:[0]} # Is a function
f2 = {0:[1,2], 1:[2], 2:[0]} # Not a function
f3 = {'a': ['c'], 'b':['c'], 'c':['a']} # Is a function
f4 = {'a': ['a'], 'b':['c'], 'c':['a']} # Is a function
f5 = {'a': ['b', 'c'], 'b':['c'], 'c':['a']} # Not a function
f6 = {1:[2], 2:[2]} # Is a function
function_test_cases = [f1, f2, f3, f4, f5, f6]
# Injectivity
f7 = {0:[1], 1:[2], 2:[4], 3:[5], 4:[6], 5:[3], 6:[6]} # Injective
f8 = {0:[1], 1:[1], 2:[4], 3:[5], 4:[6], 5:[6], 6:[6]} # Not injective
inj_test_cases = [f1, f2, f3, f4, f5, f6, f7, f8]
# Surjectivity
s1 = {0: [2],
1: [6],
2: [5],
3: [0],
4: [4],
5: [6],
6: [5],
7: [2],
8: [3],
9: [1]} # Not surjective
s2 = {0: [0],
1: [8],
2: [6],
3: [5],
4: [0],
5: [6],
6: [0],
7: [2],
8: [7],
9: [4]} # Not surjective
s3 = {0:[1], 1:[2], 2:[3], 3:[4], 4:[5], 5:[6], 6:[7], 7:[8], 8:[9], 9:[0]} # Surjective
s4 = {0:[2], 1:[4], 2:[6], 3:[8], 4:[0], 5:[1], 6:[3], 7:[5], 8:[7], 9:[9]} # Surjective
surj_test_cases = [s1, s2, s3, s4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.