-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixed_test.dart
44 lines (37 loc) · 1.48 KB
/
fixed_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'package:test/test.dart';
import 'package:money2/money2.dart';
void main() {
const maxScale = 100;
const maxInts = 100;
test('scale 0-$maxScale test', () {
for (var scale = 0; scale <= maxScale; scale++) {
final str = scale == 0 ? '1' : '1.${'0' * (scale - 1)}1';
final fmt = scale == 0 ? 'S#' : '#.${'#' * scale}';
expect(Fixed.parse(str, scale: scale).format(fmt), str, reason: 'Failed with $scale scale');
}
});
test('integers 0-$maxInts test', () {
for (var ints = 0; ints <= maxInts; ints++) {
final str = ints == 0 ? '0' : '9' * ints;
final fmt = '#';
expect(Fixed.parse(str, scale: 0).format(fmt), str, reason: 'Failed with $ints ints');
}
});
test('scale 0-$maxScale and integers 0-$maxInts test', () {
for (var scale = 0; scale <= maxScale; scale++) {
for (var ints = 0; ints <= maxInts; ints++) {
final intsStr = ints == 0 ? '0' : '9' * ints;
final str = scale == 0 ? intsStr : '$intsStr.${'0' * (scale - 1)}1';
// Fixed doesn't like leading zeroes!
final expectIntsStr = (ints == 0 && scale == 0)
? '0'
: ints == 0
? ''
: '9' * ints;
final expectStr = scale == 0 ? expectIntsStr : '$expectIntsStr.${'0' * (scale - 1)}1';
final fmt = scale == 0 ? '#' : '#.${'#' * scale}';
expect(Fixed.parse(str, scale: scale).format(fmt), expectStr, reason: 'Failed with $scale scale, $ints ints');
}
}
});
}