コード例 #1
0
 def test_valid_insert(self):
     self.assertEqual(
         str(
             insert(
                 [Interval('[1,3]'), Interval('[6,9]')],
                 Interval('[2,5]'))), '[[1,9]]')
コード例 #2
0
        except ValueError as message:
            print(message)
        except EOFError:
            sys.exit(0)

            
       #newly input intervals
        while True:
            try:
                new_int=input("Interval?")
                if new_int=='quit':
                    break
                
                else:
                    intervals=insert(intervals,Interval(new_int))
                    print (str(intervals))
            except ValueError as message:
                print(message)
            except EOFError:
                sys.exit(0)
        
if __name__ == "__main__":
    loop()


            

            
            
コード例 #3
0
 def test_valid_insert(self):
     self.assertEqual(str(insert([Interval('[1,3]'), Interval('[6,9]')], Interval('[2,5]'))), '[[1,9]]')
コード例 #4
0
    intervals = []
    for i in range(0, len(intervalStrSplit), 2):
        singleInterval = intervalStrSplit[i] + ',' + intervalStrSplit[i+1]
        intervals.append(Interval(singleInterval)) 
except InputTypeException:
    print('Invalid interval list')
except InputValueException:
    print('Invalid interval list')
except Exception:
    print('Invalid interval list')

# Insert intervals in the correct position
while True:
    inputStr = input('Interval? ')
    if inputStr == 'quit':
        break
    try:
        interval = Interval(inputStr)
    except InputTypeException:
        print('Invalid interval')
        continue
    except InputValueException:
        print('Invalid interval')
        continue
    except Exception:
        print('Invalid interval')
        continue
    intervals = insert(intervals, interval)
    print(intervals)

コード例 #5
0
if __name__ == "__main__":
    interval_list = []

    while (len(interval_list) == 0):
        input = raw_input('List of Intervals?')
        if input == 'quit':
            break
        input.replace(" ", "")
        input = input.split(",")

        try:
            for i in range(0, len(input), 2):
                interval = input[i] + ',' + input[i + 1]
                try:
                    parsedInterval = Interval.Interval(interval)
                    interval_list = insert(interval_list, parsedInterval)
                except:
                    print "Please enter a valid list of intervals separated by commas."
                    interval_list = []
        except:
            print "Please enter a valid list of intervals separated by commas."
            interval_list = []

    interval_list = mergeOverlapping(interval_list)
    print_intervals(interval_list)

    userInput = ''
    while True:
        userInput = raw_input('Interval?')
        if (userInput == 'quit'):
            break
コード例 #6
0
ファイル: assignment6.py プロジェクト: 14062446/assignment6
if __name__ == "__main__":
    interval_list = []
    
    while(len(interval_list)==0):
        input = raw_input('List of Intervals?')
        if input == 'quit':
            break
        input.replace(" ", "")
        input = input.split(",")
    
        try:
            for i in range(0,len(input),2):
                interval = input[i] + ',' + input[i+1]
                try:
                    parsedInterval = Interval.Interval(interval)
                    interval_list = insert(interval_list,parsedInterval)
                except:
                    print "Please enter a valid list of intervals separated by commas." 
                    interval_list = []
        except:
            print "Please enter a valid list of intervals separated by commas." 
            interval_list = []
        
    interval_list = mergeOverlapping(interval_list)
    print_intervals(interval_list)

    userInput = ''
    while True:
        userInput = raw_input('Interval?')
        if(userInput == 'quit'):
            break