Beispiel #1
0
 def test_resource_create_pieces(self):
     ''' test that we can create n pieces of the cake '''
     user = IntervalPreference('user', [(0.0, 1.0), (1.0, 1.0)])
     cake = IntervalResource((F(0,1), F(1,1)))
     pieces = create_equal_pieces(user, cake, 3)
     actual = [
         IntervalResource((F(0,3), F(1,3))),
         IntervalResource((F(1,3), F(2,3))),
         IntervalResource((F(2,3), F(3,3))),
     ]
     self.assertEqual(pieces, actual)
 def test_resource_create_pieces(self):
     ''' test that we can create n pieces of the cake '''
     user = ContinuousPreference('mark', lambda x: F(1))
     cake = ContinuousResource(F(0), F(1))
     pieces = create_equal_pieces(user, cake, 3)
     actual = [
         ContinuousResource(F(0, 1), F(1, 3)),
         ContinuousResource(F(1, 3), F(1, 3)),
         ContinuousResource(F(2, 3), F(1, 3))
     ]
     self.assertEqual(pieces, actual)
Beispiel #3
0
 def test_resource_create_pieces(self):
     ''' test that we can create n pieces of the cake '''
     user = ContinuousPreference('mark', lambda x: F(1))
     cake = ContinuousResource(F(0), F(1))
     pieces = create_equal_pieces(user, cake, 3)
     actual = [
         ContinuousResource(F(0, 1), F(1, 3)),
         ContinuousResource(F(1, 3), F(1, 3)),
         ContinuousResource(F(2, 3), F(1, 3))
     ]
     self.assertEqual(pieces, actual)
Beispiel #4
0
 def test_resource_create_pieces(self):
     ''' test that we can create n pieces of the cake '''
     keys = ['red', 'blue', 'green', 'yellow', 'orange', 'purple']
     vals = dict((k, F(1,1)) for k in keys)
     cake = CollectionResource(keys)
     user = CollectionPreference('mark', vals)
     pieces = create_equal_pieces(user, cake, 3)
     actual = [
         CollectionResource(['red', 'blue']),
         CollectionResource(['green', 'yellow']),
         CollectionResource(['orange', 'purple'])
     ]
     for this,that in zip(pieces, actual):
         self.assertEqual(this.value, that.value)
cs = [      # skew, resource
    lambda: (0.05, ContinuousResource(F(0), F(1))),
    lambda: (0.25, counted_factory()),
    lambda: (0.20, CollectionResource.random(10)),
    lambda: (0.20, CollectionResource.random(10)),
    lambda: (0.10, IntervalResource((F(0), F(1))))
]

#------------------------------------------------------------ 
# test that the methods work
#------------------------------------------------------------ 
print "\n","=" * 60
print "Create Equal Pieces Stress Test"
print "=" * 60,"\n"

for user_factory, cake_factory in zip(us, cs):
    print "-" * 60
    print cake_factory()[1].__class__.__name__
    print "-" * 60
    for size in range(2, iterations):
        skew, cake = cake_factory()
        user   = user_factory()
        total  = user.value_of(cake)
        value  = F(1, size) * total
        pieces = create_equal_pieces(user, cake, size)
        values = [user.value_of(piece) for piece in pieces]
        print "needed[%f]\t<= found:%s" % (value, values)

        assert(abs(sum(values) - total) < (total * 0.01))               # should roughly sum to 1
        #assert(all(abs(v - value) < (value * skew) for v in values))   # should all be ~ equal
Beispiel #6
0
cs = [  # skew, resource
    lambda: (0.05, ContinuousResource(F(0), F(1))), lambda:
    (0.25, counted_factory()), lambda: (0.20, CollectionResource.random(10)),
    lambda: (0.20, CollectionResource.random(10)), lambda:
    (0.10, IntervalResource((F(0), F(1))))
]

#------------------------------------------------------------
# test that the methods work
#------------------------------------------------------------
print "\n", "=" * 60
print "Create Equal Pieces Stress Test"
print "=" * 60, "\n"

for user_factory, cake_factory in zip(us, cs):
    print "-" * 60
    print cake_factory()[1].__class__.__name__
    print "-" * 60
    for size in range(2, iterations):
        skew, cake = cake_factory()
        user = user_factory()
        total = user.value_of(cake)
        value = F(1, size) * total
        pieces = create_equal_pieces(user, cake, size)
        values = [user.value_of(piece) for piece in pieces]
        print "needed[%f]\t<= found:%s" % (value, values)

        assert (abs(sum(values) - total) <
                (total * 0.01))  # should roughly sum to 1
        #assert(all(abs(v - value) < (value * skew) for v in values))   # should all be ~ equal