def test_value_accumulator_can_add_value(): value = 4.2 acc = ValueAccumulator() acc.add(value) assert acc.count == 1 assert acc.sum == value assert acc.avg == value assert acc.stddev is None assert acc.min == value assert acc.max == value
def test_value_accumulator_can_add_several_values(): values = [4.2, -1.3, 10.8] acc = ValueAccumulator() for value in values: acc.add(value) assert acc.count == len(values) assert acc.sum == sum(values) assert acc.avg == statistics.mean(values) assert acc.stddev == statistics.stdev(values) assert acc.min == min(values) assert acc.max == max(values)
def test_value_accumulator_handles_same_values(): value = 4.2 count = 5 acc = ValueAccumulator() for _ in range(count): acc.add(value) assert acc.count == count assert acc.sum == value * count assert acc.avg == value assert acc.stddev == 0 assert acc.min == value assert acc.max == value
def test_value_accumulator_dont_return_anything_when_created(): acc = ValueAccumulator() assert acc.count == 0 assert acc.sum == 0 assert acc.avg is None assert acc.stddev is None assert acc.min is None assert acc.max is None
def test_metrics_stats_frame_can_add_values(): events_transport_batch_size = [10, 2, 54] events_looper_run_time_spent = [0.1, 3.4, 0.01, 0.5] events = [] for v in events_transport_batch_size: events.append((MetricsName.TRANSPORT_BATCH_SIZE, v)) for v in events_looper_run_time_spent: events.append((MetricsName.LOOPER_RUN_TIME_SPENT, v)) shuffle(events) frame = MetricsStatsFrame() for id, value in events: frame.add(id, value) assert frame.get(MetricsName.TRANSPORT_BATCH_SIZE) == ValueAccumulator(events_transport_batch_size) assert frame.get(MetricsName.LOOPER_RUN_TIME_SPENT) == ValueAccumulator(events_looper_run_time_spent) assert frame.get(MetricsName.BACKUP_THREE_PC_BATCH_SIZE) == ValueAccumulator()
def _value_accumulator(values): acc = ValueAccumulator() for v in values: acc.add(v) return acc
def test_value_accumulator_eq_has_value_semantics(): a = ValueAccumulator() b = ValueAccumulator() assert a == b a.add(1.0) assert a != b b.add(1.0) assert a == b a.add(2.0) b.add(3.0) assert a != b