示例#1
0
    def testNotContainsEvent(self):
        s = OrderedSet()
        val1 = Event(2.0)
        val2 = Event(2.0)
        val3 = Event(4.0)
        s.insert(val1)
        s.insert(val3)
        self.assertFalse(s.__contains__(val2))

        s = OrderedSet()
        val1 = Event(2.0)
        val2 = Event(2.0)
        val3 = Event(4.0)
        s.insert(val1)
        s.insert(val2)
        self.assertFalse(s.__contains__(val3))

        s = OrderedSet()
        val1 = Event(2.0)
        val2 = Event(2.0)
        val3 = Event(4.0)
        s.insert(val1)
        s.insert(val2)
        s.insert(val3)
        s.removeFirst()
        self.assertFalse(s.__contains__(val1))
 def testNotContainsEvent(self):
     s = OrderedSet()
     val1 = Event(2.0)
     val2 = Event(2.0)
     val3 = Event(4.0)
     s.insert(val1)
     s.insert(val3)
     self.assertFalse(s.__contains__(val2))
     
     s = OrderedSet()
     val1 = Event(2.0)
     val2 = Event(2.0)
     val3 = Event(4.0)
     s.insert(val1)
     s.insert(val2)
     self.assertFalse(s.__contains__(val3))
     
     s = OrderedSet()
     val1 = Event(2.0)
     val2 = Event(2.0)
     val3 = Event(4.0)
     s.insert(val1)
     s.insert(val2)
     s.insert(val3)
     s.removeFirst()
     self.assertFalse(s.__contains__(val1))
示例#3
0
    def testNotContains(self):
        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val3)
        self.assertFalse(s.__contains__(val2))

        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val2)
        self.assertFalse(s.__contains__(val3))

        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val2)
        s.insert(val3)
        self.assertFalse(s.__contains__(val1))

        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val2)
        s.insert(val3)
        s.removeFirst()
        self.assertFalse(s.__contains__(val1))
    def testNotContains(self):
        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val3)
        self.assertFalse(s.__contains__(val2))
        
        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val2)
        self.assertFalse(s.__contains__(val3))
        
        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val2)
        s.insert(val3)
        self.assertFalse(s.__contains__(val1))

        s = OrderedSet()
        val1 = 2.0
        val2 = 3.0
        val3 = 4.0
        s.insert(val1)
        s.insert(val2)
        s.insert(val3)
        s.removeFirst()
        self.assertFalse(s.__contains__(val1))
示例#5
0
 def testRemoveFirstEmptyInOut(self):
     #Then an out of order test
     S = OrderedSet()
     S.insert(5)
     val = S.removeFirst()
     self.assertEqual(val, 5)
     val = S.removeFirst()
     self.assertEqual(val, None)
 def testRemoveFirstEmptyInOut(self):
     #Then an out of order test
     S= OrderedSet()
     S.insert(5)
     val = S.removeFirst()
     self.assertEqual(val, 5)
     val = S.removeFirst()
     self.assertEqual(val, None)
示例#7
0
    def testRemoveFirst(self):
        #Then an out of order test
        S = OrderedSet()

        S.insert(3.5)
        S.insert(2.5)
        val = S.removeFirst()
        self.assertEqual(val, 2.5)
        self.assertEqual(str(S), '[3.5*]')

        val = S.removeFirst()
        self.assertEqual(val, 3.5)
        self.assertEqual(str(S), '[]')
 def testRemoveFirst(self):
     #Then an out of order test
     S= OrderedSet()
     
     S.insert(3.5)
     S.insert(2.5)
     val = S.removeFirst()
     self.assertEqual(val, 2.5)
     self.assertEqual(str(S), '[3.5*]')
     
     val = S.removeFirst()
     self.assertEqual(val, 3.5)
     self.assertEqual(str(S), '[]')
示例#9
0
    def testEmptyConstructor(self):
        '''Test For Consturct the empty Set'''
        #Case1
        #Construct empty set first
        b = OrderedSet()
        self.assertEqual('[]', str(b))

        #Case2
        #insert in first the removeFirst to empty
        #---------------------------------------------------------------------------------
        a = OrderedSet()
        a.insert(4)
        a.insert(5)
        a.insert(0)
        a.removeFirst()
        a.removeFirst()
        a.removeFirst()
        self.assertEqual('[]', str(a))
示例#10
0
    def testRemovefirst(self):
        ''' Test for RemoveFirst method'''

        a = OrderedSet()
        event1 = CounterEvent(2)
        event2 = CounterEvent(1)
        event3 = CounterEvent(0.5)
        event4 = CounterEvent(4.5)
        #Insert the events in first
        #---------------------------------------------------------------------------------
        a.insert(event1)
        a.insert(event2)
        a.insert(event3)
        a.insert(event4)

        #Aplly RemoveFirst
        #Check both the thing returned
        #and also the object left in the set
        #---------------------------------------------------------------------------------
        self.assertEqual(
            '[<Event: 0.5>*, <Event: 1.0>, <Event: 2.0>, <Event: 4.5>]',
            str(a))
        temp = a.removeFirst()
        self.assertEqual(True, temp is event3)

        self.assertEqual('[<Event: 1.0>*, <Event: 2.0>, <Event: 4.5>]', str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event2)

        self.assertEqual('[<Event: 2.0>*, <Event: 4.5>]', str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event1)
        self.assertEqual('[<Event: 4.5>*]', str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event4)
        self.assertEqual('[]', str(a))

        temp = a.removeFirst()
        self.assertEqual(None, temp)
    def testEmptyConstructor(self):
        '''Test For Consturct the empty Set'''
        #Case1
        #Construct empty set first
        b = OrderedSet()
        self.assertEqual('[]',str(b))




        #Case2
        #insert in first the removeFirst to empty
#---------------------------------------------------------------------------------
        a = OrderedSet()
        a.insert(4)
        a.insert(5)
        a.insert(0)
        a.removeFirst()
        a.removeFirst()
        a.removeFirst()
        self.assertEqual('[]',str(a))
    def testRemovefirst(self):
        ''' Test for RemoveFirst method'''

        a = OrderedSet()
        event1 = CounterEvent(2)
        event2 = CounterEvent(1)
        event3 = CounterEvent(0.5)
        event4 = CounterEvent(4.5)
        #Insert the events in first
        #---------------------------------------------------------------------------------                      
        a.insert(event1)
        a.insert(event2)
        a.insert(event3)
        a.insert(event4)

        #Aplly RemoveFirst
        #Check both the thing returned
        #and also the object left in the set
        #---------------------------------------------------------------------------------
        self.assertEqual('[<Event: 0.5>*, <Event: 1.0>, <Event: 2.0>, <Event: 4.5>]',str(a))
        temp = a.removeFirst()
        self.assertEqual(True, temp is event3)
        
        self.assertEqual('[<Event: 1.0>*, <Event: 2.0>, <Event: 4.5>]',str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event2)
        
        self.assertEqual('[<Event: 2.0>*, <Event: 4.5>]',str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event1)
        self.assertEqual('[<Event: 4.5>*]',str(a))

        temp = a.removeFirst()
        self.assertEqual(True, temp is event4)
        self.assertEqual('[]', str(a) )

        temp = a.removeFirst()
        self.assertEqual(None,temp)
示例#13
0
class ParticleSim:
    '''
    CounterSim is the real driver for the DES simulation.
    The info 1. is an OrderedSet Whose Elements are CounterEvents
             2. and also a Virtual Time Keeper initially at 0.0
    '''

    #Constructor
    def __init__(self):
        '''
        pre: None
        post: An initial empty OrderedSet (the collection of CounterEvents later)
        '''
        #Construct the Empty CounterSim Object
        #Initialize the virtual time
        self.event = OrderedSet()
        self.t = 0.0

    #Current time method
    def now(self):
        '''
        pre:None
        post:return the current virtual time
        '''
        return self.t

    #Insertion Method
    def insert(self, x):
        '''
        pre: X is a CounterEvent Ojbect
        post: insert the CounterEvent to the event Collection(OrderedSet)
        exception:TypeErro if x  is not CounterEvent Object
        '''

        #raise typeError if x not the right Type

        if not isinstance(x, ParticleEvent):
            raise TypeError

        #insert if right type
        self.event.insert(x)

    #Setup Method
    def setup(self, n=5, mean=4, seed=None):

        #raise typeError if x not the right Type
        if not (isinstance(n, int)):
            raise TypeError
        if not (isinstance(mean, int) or isinstance(mean, float)):
            raise TypeError

        random.seed()
        for i in range(n):

            self.insert(ParticleEvent(random.expovariate(1 / 4)))

# the simulation Engine method

    def doAllEvents(self):
        '''
        pre:None
        post:THe SImulator has porperly run
        '''
        #The main loop for carrying out DES

        #going through the Events collection
        #applying right method to it
        while len(self.event) > 0:

            event = self.event.removeFirst()

            self.t = event.time()
            event.execute()
示例#14
0
class ParticleSim:
    """
    CounterSim is the real driver for the DES simulation.
    The info 1. is an OrderedSet Whose Elements are CounterEvents
             2. and also a Virtual Time Keeper initially at 0.0
    """

    # Constructor
    def __init__(self):
        """
        pre: None
        post: An initial empty OrderedSet (the collection of CounterEvents later)
        """
        # Construct the Empty CounterSim Object
        # Initialize the virtual time
        self.event = OrderedSet()
        self.t = 0.0

    # Current time method
    def now(self):
        """
        pre:None
        post:return the current virtual time
        """
        return self.t

    # Insertion Method
    def insert(self, x):

        """
        pre: X is a CounterEvent Ojbect
        post: insert the CounterEvent to the event Collection(OrderedSet)
        exception:TypeErro if x  is not CounterEvent Object
        """

        # raise typeError if x not the right Type

        if not isinstance(x, ParticleEvent):
            raise TypeError

        # insert if right type
        self.event.insert(x)

    # Setup Method
    def setup(self, n=5, mean=4, seed=None):

        # raise typeError if x not the right Type
        if not (isinstance(n, int)):
            raise TypeError
        if not (isinstance(mean, int) or isinstance(mean, float)):
            raise TypeError

        random.seed()
        for i in range(n):

            self.insert(ParticleEvent(random.expovariate(1 / 4)))

    # the simulation Engine method
    def doAllEvents(self):
        """
        pre:None
        post:THe SImulator has porperly run
        """
        # The main loop for carrying out DES

        # going through the Events collection
        # applying right method to it
        while len(self.event) > 0:

            event = self.event.removeFirst()

            self.t = event.time()
            event.execute()