Answered step by step
Verified Expert Solution
Link Copied!

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 determine_precedence, 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 sqlite3
import unittest
from pprint import pprint
import sys
import os
sys.path.append("/home/codio/workspace/student_code/")
from precedence import determine_precedence
class Action:
def __init__(self, object_, transaction, is_write):
self.object_= object_
self.transaction = transaction
self.is_write = is_write
def __str__(self):
return f"Action({self.object_},{self.transaction},{self.is_write})"
__repr__=__str__
class TestPrecedence(unittest.TestCase):
def test_visible_1(self):
actions =[
Action(object_="A", transaction="T2", is_write=False),
Action(object_="B", transaction="T1", is_write=False),
Action(object_="A", transaction="T2", is_write=True),
Action(object_="A", transaction="T3", is_write=False),
Action(object_="B", transaction="T1", is_write=True),
Action(object_="A", transaction="T3", is_write=True),
Action(object_="B", transaction="T2", is_write=False),
Action(object_="B", transaction="T2", is_write=True),
]
print("Actions:")
pprint(actions)
result = determine_precedence(actions)
print("Result:")
pprint(result)
print("Expected:")
expected =[('T1','T2'),('T2','T3')]
pprint(expected)
assert expected == result
def test_visible_2(self):
actions =[
Action(object_="A", transaction="T2", is_write=False),
Action(object_="B", transaction="T1", is_write=False),
Action(object_="A", transaction="T2", is_write=True),
Action(object_="A", transaction="T3", is_write=False),
Action(object_="C", transaction="T3", is_write=True),
Action(object_="B", transaction="T1", is_write=True),
Action(object_="A", transaction="T3", is_write=True),
Action(object_="C", transaction="T1", is_write=False),
Action(object_="B", transaction="T2", is_write=False),
Action(object_="B", transaction="T2", is_write=True),
]
print("Actions:")
pprint(actions)
result = determine_precedence(actions)
print("Result:")
pprint(result)
print("Expected:")
expected =[('T1','T2'),('T2','T3'),('T3','T1')]
pprint(expected)
assert expected == result
def test_visible_3(self):
actions =[
Action(object_="A", transaction="T2", is_write=False),
Action(object_="B", transaction="T1", is_write=False),
Action(object_="A", transaction="T2", is_write=True),
Action(object_="A", transaction="T3", is_write=False),
Action(object_="C", transaction="T3", is_write=True),
Action(object_="B", transaction="T1", is_write=True),
Action(object_="B", transaction="T4", is_write=True),
Action(object_="A", transaction="T3", is_write=True),
Action(object_="C", transaction="T1", is_write=False),
Action(object_="B", transaction="T4", is_write=False),
Action(object_="B", transaction="T2", is_write=False),
Action(object_="B", transaction="T2", is_write=True),
]
print("Actions:")
pprint(actions)
result = determine_precedence(actions)
print("Result:")
pprint(result)
print("Expected:")
expected =[('T1','T2'),('T1','T4'),('T2','T3'),('T3','T1'),('T4','T2')]
pprint(expected)
assert expected == result
if __name__=='__main__':
unittest.main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions