This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Add tests for lerpDouble #20778
Merged
Merged
Add tests for lerpDouble #20778
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2013 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. | ||
|
|
||
| // @dart = 2.10 | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| test('lerpDouble should return null if and only if both inputs are null', () { | ||
| expect(lerpDouble(null, null, 1.0), isNull); | ||
| expect(lerpDouble(5.0, null, 0.25), isNotNull); | ||
| expect(lerpDouble(null, 5.0, 0.25), isNotNull); | ||
| }); | ||
|
|
||
| test('lerpDouble should treat a null input as 0 if the other input is non-null', () { | ||
| expect(lerpDouble(null, 10.0, 0.25), 2.5); | ||
| expect(lerpDouble(10.0, null, 0.25), 7.5); | ||
| }); | ||
|
|
||
| test('lerpDouble should handle interpolation values < 0.0', () { | ||
| expect(lerpDouble(0.0, 10.0, -5.0), -50.0); | ||
| expect(lerpDouble(10.0, 0.0, -5.0), 60.0); | ||
| }); | ||
|
|
||
| test('lerpDouble should return the start value at 0.0', () { | ||
| expect(lerpDouble(2.0, 10.0, 0.0), 2.0); | ||
| expect(lerpDouble(10.0, 2.0, 0.0), 10.0); | ||
| }); | ||
|
|
||
| test('lerpDouble should interpolate between two values', () { | ||
| expect(lerpDouble(0.0, 10.0, 0.25), 2.5); | ||
| expect(lerpDouble(10.0, 0.0, 0.25), 7.5); | ||
| }); | ||
|
|
||
| test('lerpDouble should return the end value at 1.0', () { | ||
| expect(lerpDouble(2.0, 10.0, 1.0), 10.0); | ||
| expect(lerpDouble(10.0, 2.0, 1.0), 2.0); | ||
| }); | ||
|
|
||
| test('lerpDouble should handle interpolation values > 1.0', () { | ||
| expect(lerpDouble(0.0, 10.0, 5.0), 50.0); | ||
| expect(lerpDouble(10.0, 0.0, 5.0), -40.0); | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also test infinities, NaNs, very large numbers, very small numbers...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I'll land this as-is for the moment and make the wiki updates so that @matthew-carroll is unblocked on his work, but will add those in a followup PR.