relative_rect_test.dart 2.25 KB
Newer Older
1 2 3 4 5
// Copyright 2017 The Chromium 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/rendering.dart';
6
import '../flutter_test_alternative.dart';
7 8 9

void main() {
  test('RelativeRect.==', () {
10
    const RelativeRect r = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
11
    expect(r, RelativeRect.fromSize(Rect.fromLTWH(10.0, 20.0, 0.0, 0.0), const Size(40.0, 60.0)));
12 13
  });
  test('RelativeRect.shift', () {
14
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
15
    final RelativeRect r2 = r1.shift(const Offset(5.0, 50.0));
16 17 18
    expect(r2, const RelativeRect.fromLTRB(15.0, 70.0, 25.0, -10.0));
  });
  test('RelativeRect.inflate', () {
19
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
20
    final RelativeRect r2 = r1.inflate(5.0);
21 22 23
    expect(r2, const RelativeRect.fromLTRB(5.0, 15.0, 25.0, 35.0));
  });
  test('RelativeRect.deflate', () {
24
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
25
    final RelativeRect r2 = r1.deflate(5.0);
26 27 28
    expect(r2, const RelativeRect.fromLTRB(15.0, 25.0, 35.0, 45.0));
  });
  test('RelativeRect.intersect', () {
29 30
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
    const RelativeRect r2 = RelativeRect.fromLTRB(0.0, 30.0, 60.0, 0.0);
31 32
    final RelativeRect r3 = r1.intersect(r2);
    final RelativeRect r4 = r2.intersect(r1);
33 34 35 36
    expect(r3, r4);
    expect(r3, const RelativeRect.fromLTRB(10.0, 30.0, 60.0, 40.0));
  });
  test('RelativeRect.toRect', () {
37
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
38 39
    final Rect r2 = r1.toRect(Rect.fromLTRB(10.0, 20.0, 90.0, 180.0));
    expect(r2, Rect.fromLTRB(10.0, 20.0, 50.0, 120.0));
40
  });
Ian Hickson's avatar
Ian Hickson committed
41
  test('RelativeRect.toSize', () {
42
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
Ian Hickson's avatar
Ian Hickson committed
43 44 45
    final Size r2 = r1.toSize(const Size(80.0, 160.0));
    expect(r2, const Size(40.0, 100.0));
  });
46
  test('RelativeRect.lerp', () {
47
    const RelativeRect r1 = RelativeRect.fill;
48
    const RelativeRect r2 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
49
    final RelativeRect r3 = RelativeRect.lerp(r1, r2, 0.5);
50 51 52
    expect(r3, const RelativeRect.fromLTRB(5.0, 10.0, 15.0, 20.0));
  });
}