Question: Check Functional Dependencies Write a function, named check _ funtional _ dependency, that takes two arguments, a table ( represented as a list of dictionaries,
Check Functional Dependencies
Write a function, named checkfuntionaldependency, that takes two arguments, a table represented as a list of dictionaries, where each dictionarys key is a column and its value is the datum and a functional dependency a class already implemented in the starter code Your function should return True if the functional dependency is true for the table, False otherwise.
Here are a few test cases:
def testvisibleself: # First Test Case Okay listofdictrows name: "Josh", "age": "pet": "RaceTrack", "allergies": "Wheat"name: "Cam", "age": "pet": "CrashDown", "allergies": "None"name: "Zizhen", "age": "pet": "Bugs Bunny", "allergies": "Calculus"name: "Dennis", "age": "pet": "Dany", "allergies": "Wheat"name: "Jie", "age": "pet": "Ghost", "allergies": "None" # This table has columns: name, age, pet, and allergies leftsideset age "allergies" rightsideset name "age" functionaldependency FunctionalDependencyleftsideset, rightsideset # age allergies name age # it holds because no rows matching on the left attributes disagree on the right printTable: pprintlistofdictrows printfFD: functionaldependency result checkfuntionaldependencylistofdictrows, functionaldependency printfResult: result assert result def testvisibleself: # Doesn't Hold listofdictrows name: "Josh", "age": "pet": "RaceTrack", "allergies": "Wheat"name: "Cam", "age": "pet": "CrashDown", "allergies": "None"name: "Zizhen", "age": "pet": "Bugs Bunny", "allergies": "Calculus"name: "Dennis", "age": "pet": "Dany", "allergies": "Wheat"name: "Jie", "age": "pet": "Ghost", "allergies": "None" leftsideset allergies rightsideset name "age" functionaldependency FunctionalDependencyleftsideset, rightsideset printTable: pprintlistofdictrows printfFD: functionaldependency result checkfuntionaldependencylistofdictrows, functionaldependency printfResult: result # FD doesn't hold because Josh and Dennis both have a wheat allergy, but differ in name and age too assert not result def testvisibleself: # Other Columns listofdictrows name: "Josh", "age": "pet": "RaceTrack", "allergies": "Wheat", "zipcode": name: "Cam", "age": "pet": "CrashDown", "allergies": "None", "zipcode": name: "Zizhen", "age": "pet": "Bugs Bunny", "allergies": "Calculus", "zipcode": name: "Dennis", "age": "pet": "Dany", "allergies": "Wheat", "zipcode": name: "Jie", "age": "pet": "Ghost", "allergies": "None", "zipcode": leftsideset zipcode "allergies" rightsideset name "age" functionaldependency FunctionalDependencyleftsideset, rightsideset printTable: pprintlistofdictrows printfFD: functionaldependency result checkfuntionaldependencylistofdictrows, functionaldependency printfResult: result assert result leftsideset zipcode rightsideset zipcode functionaldependency FunctionalDependencyleftsideset, rightsideset printTable: pprintlistofdictrows printfFD: functionaldependency result checkfuntionaldependencylistofdictrows, functionaldependency printfResult: result assert result
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
