Beispiel #1
0
 def test_is_Overlap(self):
     self.assertEqual(
         interval.isOverlap(interval('[1,5)'), interval('[3,8]')), 1)
     self.assertEqual(interval.insert('[1,3],[6,9]', '[2,5]'), '[1,9]')
     self.assertEqual(
         interval.insert('[1,2], (3,5), [6,7), (8,10], [12,16]', '[4,9]'),
         '[1,2], (3,10], [12,16]')
Beispiel #2
0
 def test_insert(self):
     int1 = interval('[1,3]')
     int2 = interval('[5,7]')
     int3 = interval('[9,14]')
     int4 = interval('[4,6]')
     mergedInt124 = interval('[1,7]')
     mergedInts = [mergedInt124]
     ## test basic insert:
     self.assertEqual(interval.insert([int1,int3],int2), [int1,int2,int3])
     ## test overlapping and adjacent merges:
     self.assertEqual(interval.insert([int1,int2],int4), mergedInts)
Beispiel #3
0
 def test_insert(self):
     int1 = interval('[1,3]')
     int2 = interval('[5,7]')
     int3 = interval('[9,14]')
     int4 = interval('[4,6]')
     mergedInt124 = interval('[1,7]')
     mergedInts = [mergedInt124]
     ## test basic insert:
     self.assertEqual(interval.insert([int1, int3], int2),
                      [int1, int2, int3])
     ## test overlapping and adjacent merges:
     self.assertEqual(interval.insert([int1, int2], int4), mergedInts)
Beispiel #4
0
def startProgram():
    '''Function runs the program to take list of intervals and then new interval
    each time from the user and inserts the new interval to the list of intervals
    and merges if overlapping or adjacent then returns the new list of intervals.
    Program terminates when the user inputs quit.
    '''
    
    ExitProgram = False
    
    intervals = input("List of intervals? ")
    
    if intervals == 'quit':
        ExitProgram = True
    else:
        intervals = intervals.split(', ')
        intervals = [interval(i) for i in intervals]
    
    while not ExitProgram:
        int1 = input("Interval? ")
        if int1 == 'quit':
            break
        try:
            int1 = interval(int1)
        except Exception as e:
            print(e)
        else:
            intervals = insert(intervals, int1)
            print(', '.join([i.interval for i in intervals]))
Beispiel #5
0
def main():
    """
    Prompts user for intervals, which it merges. Exits on "quit".
    """
    intlist = []
    while True:
        try:
            inp = input('List of intervals? ')
            if inp == "quit":
                return
            intlist = interval.parseList(inp)
            intlist = interval.mergeOverlapping(intlist)
            interval.printList(intlist)
            break
        except (IntervalError, ValueError):
            print('Error inputting intervals')
    while True:
        istr = input('interval? ')
        if istr == "quit":
            break
        try:
            val = interval(istr)
            intlist = interval.insert(intlist, val)
            interval.printList(intlist)
        except (IntervalError, ValueError):
            print('Invalid interval')
Beispiel #6
0
def main():
	while True:
		try:
			list_of_intervals = input("List of intervals? ")
			if list_of_intervals == 'quit':
				print ('')
				sys.exit(1)

			list_of_intervals = interval.mergeOverlapping(list_of_intervals)
			break
		except KeyboardInterrupt:
			sys.exit(1)
		except Exception:
			print ('Invalid list of intervals')
			pass

	while True:
		try:
			interv = input('Interval? ')
			if interv == 'quit':
				print ('')
				break
			else:
				interval(interv)
				list_of_intervals = interval.insert(list_of_intervals, interv)
				print (list_of_intervals)
		except KeyboardInterrupt:
			sys.exit(1)
		except:
			print ('Invalid interval')
Beispiel #7
0
def main() :
    """
    Prompts user for intervals, which it merges. Exits on "quit".
    """
    intlist = []
    while True :
        try :
            inp = input('List of intervals? ')
            if inp == "quit":
                return
            intlist = interval.parseList(inp)
            intlist = interval.mergeOverlapping(intlist)
            interval.printList(intlist)
            break
        except (IntervalError, ValueError):
            print('Error inputting intervals')
    while True :
        istr = input('interval? ')
        if istr == "quit" :
            break
        try :
            val = interval(istr)
            intlist = interval.insert(intlist,val)
            interval.printList(intlist)
        except (IntervalError, ValueError) :
            print('Invalid interval')
def startProgram():
    '''Function runs the program to take list of intervals and then new interval
    each time from the user and inserts the new interval to the list of intervals
    and merges if overlapping or adjacent then returns the new list of intervals.
    Program terminates when the user inputs quit.
    '''

    ExitProgram = False

    intervals = input("List of intervals? ")

    if intervals == 'quit':
        ExitProgram = True
    else:
        intervals = intervals.split(', ')
        intervals = [interval(i) for i in intervals]

    while not ExitProgram:
        int1 = input("Interval? ")
        if int1 == 'quit':
            break
        try:
            int1 = interval(int1)
        except Exception as e:
            print(e)
        else:
            intervals = insert(intervals, int1)
            print(', '.join([i.interval for i in intervals]))
Beispiel #9
0
        isCorrect = False
        print 'Please make your input of the form [a,b], [c,d)], ,,, , [z,y]'
        inList = raw_input('List of intervals? ')
 
##############################################################################
# Subsequent Input
##############################################################################

inputInterval = raw_input('Interval? [TYPE quit TO EXIT] ')

# Check intervals
while inputInterval != 'quit':     
    
    try:
        if inputInterval == '': raise Exception
    
        outList = interval.insert(outList,interval(inputInterval))
        print outList
        
    except KeyboardInterrupt:
        
        exit()
    
    except:
    
        print 'Invalid Interval'
    
    inputInterval = raw_input('Interval? [TYPE quit TO EXIT] ')


Beispiel #10
0
            is_interval_list_valid = False
            break

user_interval_input = "hey"

while user_interval_input <> "quit":  #Introducing the word "quit" is the way to exit the program
    try:
        user_interval_input = raw_input("Interval? ")
    except:
        (KeyboardInterrupt, EOFError)  #avoid interrupting the program

    user_interval_input = user_interval_input.replace(" ", "")

    try:
        new_interval = interval(user_interval_input)
        my_intervals_list = interval.insert(my_intervals_list, new_interval)
        new_list_string = ""
        for i in my_intervals_list:
            new_list_string += str(i)
            new_list_string += ", "
        new_list_string = new_list_string[:-2]
        print new_list_string

    except:  #If one of the errors of the class is raised, then the user input is invalid.
        "\n"
        if user_interval_input <> "quit":
            print "Invalid interval"
        is_interval_list_valid = False
        continue

print "Bye Bye!"
Beispiel #11
0
            is_interval_list_valid = False
            break


user_interval_input = "hey"

while user_interval_input <> "quit":    #Introducing the word "quit" is the way to exit the program
    try:
        user_interval_input = raw_input("Interval? ")
    except: (KeyboardInterrupt, EOFError)  #avoid interrupting the program

    user_interval_input = user_interval_input.replace(" ","")

    try:
        new_interval = interval(user_interval_input)
        my_intervals_list = interval.insert(my_intervals_list, new_interval)
        new_list_string = ""
        for i in my_intervals_list:
            new_list_string += str(i)
            new_list_string += ", "
        new_list_string = new_list_string[:-2]
        print new_list_string

    except:   #If one of the errors of the class is raised, then the user input is invalid.
        "\n"
        if user_interval_input <> "quit":
            print "Invalid interval"
        is_interval_list_valid = False
        continue

    def test_insert(self):

        # test to insert an interval into a list        
        
        self.assertEquals(interval.insert([self.interval1, self.interval4], self.interval2),[self.interval3, self.interval4])
Beispiel #13
0
 def test_insert(self):
     self.assertEqual(interval.insert('[1,2), [3,6], (6,8]', '[4,7]'),
                      '[1,2), [3,8]')
Beispiel #14
0
 def test_is_Overlap(self):
     self.assertEqual(interval.isOverlap(interval("[1,5)"), interval("[3,8]")), 1)
     self.assertEqual(interval.insert("[1,3],[6,9]", "[2,5]"), "[1,9]")
     self.assertEqual(interval.insert("[1,2], (3,5), [6,7), (8,10], [12,16]", "[4,9]"), "[1,2], (3,10], [12,16]")
Beispiel #15
0
 def test_insert(self):
     self.assertEqual(interval.insert("[1,2), [3,6], (6,8]", "[4,7]"), "[1,2), [3,8]")