Beispiel #1
0
    def test_make_json_formatted_for_single_chart_regression(self):
        """Test making a regression chart with a single point on it."""
        inference_result_proto = regression_pb2.RegressionResponse()
        regression = inference_result_proto.result.regressions.add()
        regression.value = 0.45
        regression = inference_result_proto.result.regressions.add()
        regression.value = 0.55

        original_feature = inference_utils.OriginalFeatureList(
            'feature_name', [2.], 'float_list')
        mutant_feature = inference_utils.MutantFeatureValue(original_feature,
                                                            index=0,
                                                            mutant_value=20)
        mutant_feature_2 = inference_utils.MutantFeatureValue(original_feature,
                                                              index=0,
                                                              mutant_value=10)

        jsonable = inference_utils.make_json_formatted_for_single_chart(
            [mutant_feature, mutant_feature_2], inference_result_proto, 0)

        self.assertEqual(['value'], list(jsonable.keys()))
        self.assertEqual(2, len(jsonable['value']))
        self.assertEqual(10, jsonable['value'][0]['step'])
        self.assertAlmostEqual(0.55, jsonable['value'][0]['scalar'])
        self.assertEqual(20, jsonable['value'][1]['step'])
        self.assertAlmostEqual(0.45, jsonable['value'][1]['scalar'])
Beispiel #2
0
    def test_make_json_formatted_for_single_chart_classification(self):
        """Test making a classification chart with a single point on it."""
        inference_result_proto = classification_pb2.ClassificationResponse()
        classification = inference_result_proto.result.classifications.add()
        inference_class = classification.classes.add()
        inference_class.label = 'class_a'
        inference_class.score = 0.7

        inference_class = classification.classes.add()
        inference_class.label = 'class_b'
        inference_class.score = 0.3

        original_feature = inference_utils.OriginalFeatureList(
            'feature_name', [2.], 'float_list')
        mutant_feature = inference_utils.MutantFeatureValue(original_feature,
                                                            index=0,
                                                            mutant_value=20)

        jsonable = inference_utils.make_json_formatted_for_single_chart(
            [mutant_feature], inference_result_proto, 0)

        self.assertEqual(['class_a', 'class_b'], sorted(jsonable.keys()))
        self.assertEqual(1, len(jsonable['class_a']))
        self.assertEqual(20, jsonable['class_a'][0]['step'])
        self.assertAlmostEqual(0.7, jsonable['class_a'][0]['scalar'])

        self.assertEqual(1, len(jsonable['class_b']))
        self.assertEqual(20, jsonable['class_b'][0]['step'])
        self.assertAlmostEqual(0.3, jsonable['class_b'][0]['scalar'])