Ejemplo n.º 1
0
def test5():
    ''' hash items()'''
    root = LinesOfActionState(10, 50)
    succs = root.getSuccessors().items()[0][1].getSuccessors()
    dd = {}
    
    def count(d):
        k,v = d.popitem()
        r = v.getSuccessors()
        d[k]=v
        sum = 0
        #for k in d.items():
        #    sum += 1
        return sum
    
    def counts():
        smax = -1
        smin = 10000000
        for _ in xrange(1000):
            sum = GTimeStatistics.measure_function(count,succs)
            smax = max(smax,sum)
            smin = min(smin,sum)
        return smax,smin
        
    smax,smin = GTimeStatistics.measure_function(counts)
    print GTimeStatistics
    print smax,smin
Ejemplo n.º 2
0
 def test__measure_function(self):
     stat = TimeStatisticsClass()
     ev = CenterMassEvaluator()
     root_state  = LinesOfActionState(15, 50)
     
     def f(the_state):
         ev.evaluate( the_state, WHITE, 10)
     
     for ss in root_state.getSuccessors().values():
         stat.measure_function(f,ss)
     
     print stat.stats
     pass        
Ejemplo n.º 3
0
 def test__clean_up_if_need(self):
     o = TurnCache()
     
     current_state = LinesOfActionState(6, 50)
     succs = o.get_cached_value(current_state, LinesOfActionState.getSuccessors)
     self.assertEqual(succs,current_state.getSuccessors())        
     for s in succs.values():
         o.get_cached_value(s, LinesOfActionState.getSuccessors)
         
     ns = filter(lambda s: s.blacks == 7, succs.values() )[0]
     
     self.assertEquals(o.checkers_left_table.keys(),[(8, 8), (8, 7)])
     o.clean_up_if_need(current_state, ns)
     self.assertEquals(o.checkers_left_table.keys(),[ (8, 7)])
Ejemplo n.º 4
0
 def test__get_cached_value(self):
     o = TurnCache()
     
     current_state = LinesOfActionState(6, 50)
     succs = o.get_cached_value(current_state, LinesOfActionState.getSuccessors)
     self.assertEqual(succs,current_state.getSuccessors())
     
     for s in succs.values():
         o.get_cached_value(s, LinesOfActionState.getSuccessors)
         
     t =  o.checkers_left_table.has_key((8,7))
     self.assertTrue(t)
     
     f =  o.checkers_left_table.has_key((7,8))
     self.assertFalse(f)