#! /usr/bin/env python3
from collections import defaultdict
import itertools
Copyright By PowCoder代写 加微信 powcoder
from pathlib import Path
from typing import Dict, Iterable, List, Set
from cbi.data_format import (
ObservationStatus,
Predicate,
PredicateInfo,
PredicateType,
from cbi.utils import get_logs
def collect_observations(log: CBILog) -> Dict[Predicate, ObservationStatus]:
Traverse the CBILog and collect observation status for each predicate.
NOTE: If you find a `Predicate(line=3, column=5, pred_type=”BranchTrue”)`
in the log, then you have observed it as True,
further it also means you’ve observed is complement:
`Predicate(line=3, column=5, pred_type=”BranchFalse”)` as False.
:param log: the log
:return: a dictionary of predicates and their observation status.
observations: Dict[Predicate, ObservationStatus] = defaultdict(
lambda: ObservationStatus.NEVER
TODO: Add your code here
Hint: The PredicateType.alternatives will come in handy.
return observations
def collect_all_predicates(logs: Iterable[CBILog]) -> Set[Predicate]:
Collect all predicates from the logs.
:param logs: Collection of CBILogs
:return: Set of all predicates found across all logs.
predicates = set()
# TODO: Add your code here
return predicates
def cbi(success_logs: List[CBILog], failure_logs: List[CBILog]) -> Report:
Compute the CBI report.
:param success_logs: logs of successful runs
:param failure_logs: logs of failing runs
:return: the report
all_predicates = collect_all_predicates(itertools.chain(success_logs, failure_logs))
predicate_infos: Dict[Predicate, PredicateInfo] = {
pred: PredicateInfo(pred) for pred in all_predicates
# TODO: Add your code here to compute the information for each predicate.
# Finally, create a report and return it.
report = Report(predicate_info_list=list(predicate_infos.values()))
return report
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com