-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
81 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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,23 @@ | ||
/// Checks if n is between start and up to, but not including, end. If end is not specified, it's set to start with start then set to 0. If start is greater than end the params are swapped to support negative ranges. | ||
/// | ||
/// Arguments | ||
/// | ||
/// - number (num): The number to check. | ||
/// - [start = 0] (num): The start of the range. | ||
/// - end (num): The end of the range. | ||
/// | ||
/// Returns | ||
/// | ||
/// - (bool): Returns true if number is in the range, else false. | ||
dynamic inRange(num number, num? start, [num? end]) { | ||
if (end == null) { | ||
end = start; | ||
start = 0; | ||
} | ||
if (start! > end!) { | ||
var temp = start; | ||
start = end; | ||
end = temp; | ||
} | ||
return number >= start && number < end; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'clamp.dart'; | ||
export 'in_range.dart'; | ||
export 'random.dart'; |
This file contains 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 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,25 @@ | ||
import 'package:flodash/flodash.dart' as flodash; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
main() { | ||
test('with both start and end', () { | ||
expect(flodash.inRange(3, 2, 4), equals(true)); | ||
}); | ||
test('end is greater than number', () { | ||
expect(flodash.inRange(4, 8), equals(true)); | ||
}); | ||
test('end is less than number', () { | ||
expect(flodash.inRange(4, 2), equals(false)); | ||
}); | ||
test('end is same as number', () { | ||
expect(flodash.inRange(2, 2), equals(false)); | ||
}); | ||
test('with floating point numbers', () { | ||
expect(flodash.inRange(1.2, 2), equals(true)); | ||
expect(flodash.inRange(5.2, 4), equals(false)); | ||
}); | ||
test('end is less than start', () { | ||
expect(flodash.inRange(-3, -2, -6), equals(true)); | ||
}); | ||
} |