Пример #1
0
class RandomNormalDistributionIntegerProviderTest(unittest.TestCase):
  """Test class for NormalIntegerProvider.
  """

  def setUp(self):
    self.provider = RandomNormalDistributionIntegerProvider()

  def tearDown(self):
    pass

  def testGetValue(self):
    """Tests getValue()
    """
    value = self.provider.getValue()
    self.assertTrue(self.provider.DEFAULT_MIN <= value <=
                    self.provider.DEFAULT_MAX)
    min = 0
    max = 100
    mean = 50
    variance = 10
    self.provider.param_values = {'min': min,
                                  'max': max,
                                  'mean': mean,
                                  'variance': variance}
    value = self.provider.getValue()
    self.assertTrue(min <= value <= max)

  def testGetValueWithInvalidParameters(self):
    """Tests getValue() with invalid parameters.
    """
    min = 'asdf'
    max = None
    mean = None
    stdev = 'asdf'
    self.provider.param_values = {'min': min,
                                  'max': max}
    self.assertRaises(ParameterValueError, self.provider.getValue)

    self.provider.param_values = {'mean': mean,
                                  'stdev': stdev}
    self.assertRaises(ParameterValueError, self.provider.getValue)
Пример #2
0
 def testSeed(self):
     """Tests the seed method.
 """
     from soc.models.sponsor import Sponsor
     from soc.models.user import User
     from soc.modules.gsoc.models.organization import GSoCOrganization
     from soc.modules.seeder.logic.providers.integer \
         import RandomNormalDistributionIntegerProvider
     from soc.modules.seeder.logic.providers.integer \
         import RandomUniformDistributionIntegerProvider
     # Test specifying property values
     properties = {'name': "A User", 'is_developer': False}
     user = seeder_logic.seed(User, properties=properties)
     for key, value in properties.iteritems():
         self.assertEqual(user._entity[key], value)
     # Test specifying reference property values
     properties = {'founder': user}
     sponsor = seeder_logic.seed(Sponsor, properties=properties)
     for key, value in properties.iteritems():
         self.assertEqual(sponsor._entity[key], value.key())
     # Test specifying property providers
     min_slots, max_slots = 0, 20
     mean_slots_desired, std_slots_desired = 10, 5
     min_slots_desired, max_slots_desired = 1, 21
     properties = {
         'slots':
         RandomUniformDistributionIntegerProvider(min=min_slots,
                                                  max=max_slots),
         'slots_desired':
         RandomNormalDistributionIntegerProvider(mean=mean_slots_desired,
                                                 stdev=std_slots_desired,
                                                 min=min_slots_desired,
                                                 max=max_slots_desired),
     }
     gsoc_organization = seeder_logic.seed(GSoCOrganization,
                                           properties=properties)
     self.assertTrue(min_slots <= gsoc_organization.slots <= max_slots)
     self.assertTrue(min_slots_desired <= gsoc_organization.slots_desired <=
                     max_slots_desired)
Пример #3
0
 def setUp(self):
   self.provider = RandomNormalDistributionIntegerProvider()