Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function, named determine _ precedence, that takes a schedule This function should return a list of precendences between transactions as determined by conflicts.
Write a function, named determineprecedence, that takes a schedule
This function should return a list of precendences between transactions as determined by conflicts.
Each precedence is a tuple pair with the first element being the transaction that must precede the second
element transaction. Please sort the precedences before returning them transactions will be strings
utilize from itertools import combinations
here are the test case's that u need to pass:
import sqlite
import unittest
from pprint import pprint
import sys
import os
syspath.appendhomecodioworkspacestudentcode
from precedence import determineprecedence
class Action:
def initself object transaction, iswrite:
self.object object
self.transaction transaction
self.iswrite iswrite
def strself:
return fActionselfobjectselftransactionselfiswrite
reprstr
class TestPrecedenceunittestTestCase:
def testvisibleself:
actions
ActionobjectA transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectA transactionT iswriteTrue
ActionobjectA transactionT iswriteFalse
ActionobjectB transactionT iswriteTrue
ActionobjectA transactionT iswriteTrue
ActionobjectB transactionT iswriteFalse
ActionobjectB transactionT iswriteTrue
printActions:
pprintactions
result determineprecedenceactions
printResult:
pprintresult
printExpected:
expected TTTT
pprintexpected
assert expected result
def testvisibleself:
actions
ActionobjectA transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectA transactionT iswriteTrue
ActionobjectA transactionT iswriteFalse
ActionobjectC transactionT iswriteTrue
ActionobjectB transactionT iswriteTrue
ActionobjectA transactionT iswriteTrue
ActionobjectC transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectB transactionT iswriteTrue
printActions:
pprintactions
result determineprecedenceactions
printResult:
pprintresult
printExpected:
expected TTTTTT
pprintexpected
assert expected result
def testvisibleself:
actions
ActionobjectA transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectA transactionT iswriteTrue
ActionobjectA transactionT iswriteFalse
ActionobjectC transactionT iswriteTrue
ActionobjectB transactionT iswriteTrue
ActionobjectB transactionT iswriteTrue
ActionobjectA transactionT iswriteTrue
ActionobjectC transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectB transactionT iswriteFalse
ActionobjectB transactionT iswriteTrue
printActions:
pprintactions
result determineprecedenceactions
printResult:
pprintresult
printExpected:
expected TTTTTTTTTT
pprintexpected
assert expected result
if namemain:
unittest.main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started