Exemplo n.º 1
0
 def test_auto_increment(self):
     new_prototype = Reporter()
     report0 = new_prototype.create_report({})
     report1 = new_prototype.create_report({})
     self.assertEqual(report0.identifier, 0)
     self.assertEqual(report1.identifier, 1)
     pass
Exemplo n.º 2
0
 def test_addition(self):
     prototype1 = Reporter(attributes=[DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
                                       DictValue('noisier', faults=GaussianNoise(sigma=0.2))])
     prototype2 = Reporter(attributes=[DictValue('noised', faults=GaussianNoise(sigma=0.1)),
                                       DictValue('noisier', faults=InterruptionFault(likelihood=0.1))])
     new_prototype = prototype1 + prototype2
     self.assertIs(len(new_prototype.attributes), 3)
     self.assertIs(len(new_prototype.get_attribute_by_id('noisier').faults), 2)
     pass
 def test_introspected_attribute_fault_mapping(self):
     new_reporter = Reporter(faults=GaussianNoise(sigma=1))
     data = {'att1': 1, 'att2': 2}
     output_data = new_reporter(data).observed
     self.assertNotEqual(data, output_data)
     self.assertEqual(data.keys(), output_data.keys())
     pass
 def test_attribute_fault_mapping(self):
     new_reporter = Reporter(
         attributes=[DictValue('att1'),
                     DictValue('att2')],
         faults=GaussianNoise(sigma=1))
     data = {'att1': 1, 'att2': 2}
     output_data = new_reporter(data).observed
     self.assertNotEqual(data, output_data)
     pass
Exemplo n.º 5
0
def machine_error(scale):
    """
    Simple example Noisifier recipe, applies gaussian noise and occasional interruptions to the input
    depending on the scale given, recommended scale range from 1-10
    """
    return Noisifier(reporter=Reporter(faults=[
        GaussianNoise(sigma=0.1 * scale),
        InterruptionFault(likelihood=min(1, 0.01 * scale))
    ]),
                     faults=None)
Exemplo n.º 6
0
def human_error(scale):
    """
    Simple example Noisifier recipe, applies typos and attribute scrambling to the input depending
    on the scale given, recommended scale range from 1-10
    """
    return Noisifier(reporter=Reporter(faults=[
        TypographicalFault(likelihood=min(1, 0.1 * scale),
                           severity=0.1 * scale),
        ScrambleAttributes(likelihood=0.1 * scale)
    ]),
                     faults=None)
 def test_specific_attribute_confusion(self):
     new_reporter = Reporter(
         attributes=[DictValue('att1'),
                     DictValue('att2')],
         faults=ConfuseSpecificAttributes('att1', 'att2', likelihood=1))
     data = {'att1': 1, 'att2': 2}
     output_data = new_reporter(data).observed
     self.assertEqual(data['att1'], output_data['att2'])
     self.assertEqual(data['att2'], output_data['att1'])
     self.assertNotEqual(data, output_data)
     pass
Exemplo n.º 8
0
 def test_attribute_faults(self):
     new_prototype = Reporter(attributes=[DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
                                          DictValue('noiseless')])
     report0 = new_prototype({'noisy': 100, 'noiseless': 100})
     self.assertEqual(report0.truth, {'noisy': 100, 'noiseless': 100})
     self.assertEqual(report0.observed['noiseless'], 100)
     self.assertNotEqual(report0.observed['noisy'], 100)
     self.assertEqual(len(report0.triggered_faults['reporter']), 0)
     self.assertEqual(len(report0.triggered_faults['noiseless']), 0)
     self.assertEqual(len(report0.triggered_faults['noisy']), 1)
     self.assertIsInstance(report0.triggered_faults['noisy'][0], GaussianNoise)
     pass
 def test_attribute_scrambling(self):
     attributes_list = [DictValue('att%d' % index) for index in range(50)]
     new_reporter = Reporter(attributes=attributes_list)
     data = {'att%d' % index: index for index in range(50)}
     output_data = new_reporter(data).observed
     scramble_fault = ScrambleAttributes(likelihood=100)
     output_data = scramble_fault.impact_dictionary(output_data)
     self.assertNotEqual(data, output_data)
     self.assertEqual({i
                       for i in data.keys()},
                      {i
                       for i in output_data.keys()})
     pass
Exemplo n.º 10
0
    def test_object_series_call(self):
        class Foo:
            def __init__(self, noisy, noiseless):
                self.noisy = noisy
                self.noiseless = noiseless

        new_prototype = Reporter(attributes=[
            ObjectAttribute('noisy', faults=GaussianNoise(sigma=0.1)),
            ObjectAttribute('noiseless')
        ])
        series_builder = Noisifier(reporter=new_prototype)

        data = [Foo(100, 100), Foo(10, 100), Foo(100, 10)]
        result = series_builder(data)

        self.assertEqual(len([i for i in result]), 3)
        for truth, new in zip(data, result):
            self.assertEqual(truth.noiseless, new.noiseless)
            self.assertNotEqual(truth.noisy, new.noisy)
        pass
Exemplo n.º 11
0
 def test_looping(self):
     new_prototype = Reporter(attributes=[
         DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
         DictValue('noiseless')
     ])
     series_builder = Noisifier(reporter=new_prototype)
     data = [{
         'noisy': 100,
         'noiseless': 100
     }, {
         'noisy': 10,
         'noiseless': 50
     }, {
         'noisy': 100,
         'noiseless': 10
     }]
     result = series_builder(data, loop=True)
     for index, value in enumerate(result):
         if index == 4:
             break
     self.assertEqual(value['noiseless'], 50)
     pass
Exemplo n.º 12
0
 def test_dict_series_call(self):
     new_prototype = Reporter(attributes=[
         DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
         DictValue('noiseless')
     ])
     series_builder = Noisifier(reporter=new_prototype)
     data = [{
         'noisy': 100,
         'noiseless': 100
     }, {
         'noisy': 10,
         'noiseless': 100
     }, {
         'noisy': 100,
         'noiseless': 10
     }]
     result = series_builder(data)
     self.assertEqual(len([i for i in result]), 3)
     for truth, new in zip(data, result):
         self.assertEqual(truth['noiseless'], new['noiseless'])
         self.assertNotEqual(truth['noisy'], new['noisy'])
     pass
Exemplo n.º 13
0
 def test_slicing(self):
     new_prototype = Reporter(attributes=[DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
                                          DictValue('noiseless')])
     report = new_prototype({'noisy': 100, 'noiseless': 100})
     self.assertEqual(report['noiseless'], 100)
     pass
Exemplo n.º 14
0
 def test_method_delegation(self):
     new_prototype = Reporter(attributes=[DictValue('noisy', faults=GaussianNoise(sigma=0.1)),
                                          DictValue('noiseless')])
     report = new_prototype({'noisy': 100, 'noiseless': 100})
     self.assertEqual(set(report.keys()), {'noisy', 'noiseless'})
     pass