ab_test.dart 1.56 KB
Newer Older
1 2 3 4 5
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_devicelab/framework/ab.dart';
6
import 'package:flutter_devicelab/framework/task_result.dart';
7 8 9 10 11

import 'common.dart';

void main() {
  test('ABTest', () {
12
    final ABTest ab = ABTest('engine', 'test');
13 14

    for (int i = 0; i < 5; i++) {
15 16
      final TaskResult aResult = TaskResult.fromJson(<String, dynamic>{
        'success': true,
17 18 19 20 21 22 23
        'data': <String, dynamic>{
          'i': i,
          'j': 10 * i,
          'not_a_metric': 'something',
        },
        'benchmarkScoreKeys': <String>['i', 'j'],
      });
24 25 26
      ab.addAResult(aResult);
      final TaskResult bResult = TaskResult.fromJson(<String, dynamic>{
        'success': true,
27 28 29 30 31 32
        'data': <String, dynamic>{
          'i': i + 1,
          'k': 10 * i + 1,
        },
        'benchmarkScoreKeys': <String>['i', 'k'],
      });
33
      ab.addBResult(bResult);
34
    }
35
    ab.finalize();
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

    expect(
      ab.rawResults(),
      'i:\n'
      '  A:\t0.00\t1.00\t2.00\t3.00\t4.00\t\n'
      '  B:\t1.00\t2.00\t3.00\t4.00\t5.00\t\n'
      'j:\n'
      '  A:\t0.00\t10.00\t20.00\t30.00\t40.00\t\n'
      '  B:\tN/A\n'
      'k:\n'
      '  A:\tN/A\n'
      '  B:\t1.00\t11.00\t21.00\t31.00\t41.00\t\n',
    );
    expect(
        ab.printSummary(),
        'Score\tAverage A (noise)\tAverage B (noise)\tSpeed-up\n'
        'i\t2.00 (70.71%)\t3.00 (47.14%)\t0.67x\t\n'
        'j\t20.00 (70.71%)\t\t\n'
        'k\t\t21.00 (67.34%)\t\n');
  });
}