-
Notifications
You must be signed in to change notification settings - Fork 4
/
spa_test.dart
68 lines (54 loc) · 1.85 KB
/
spa_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@Timeout(Duration(seconds: 1000))
import 'dart:convert';
import 'dart:io';
import 'package:spa/src/spa.dart';
import 'package:test/test.dart';
bool doubleEq(double a, double b) => (a - b).abs() < 0.000001;
Future<bool> testCsv(String fileName) async {
final file = File(fileName);
if (!file.existsSync()) return false;
test(fileName, () async {
bool first = true;
int lineNum = 0;
await for (final line
in const LineSplitter().bind(utf8.decoder.bind(file.openRead()))) {
lineNum++;
if (first) {
// Skip column names
first = false;
continue;
}
final row = line.split(',');
final params = SPAParams.list(row.map((e) => num.parse(e)).toList());
final itm = SPAIntermediate();
final output = spaCalculate(params, intermediate: itm);
void check(double res, int idx) {
if (!doubleEq(res, double.parse(row[idx]))) {
throw TestFailure('Test failed at line $lineNum\n'
'Row $idx: expected ${row[idx]} but got $res');
}
}
check(output.zenith, 17);
check(output.azimuthAstro, 18);
check(output.azimuth, 19);
check(output.incidence!, 20);
check(output.sunTransit!, 21);
check(output.sunrise!, 22);
check(output.sunset!, 23);
}
});
return true;
}
Future<void> main() async {
// The full dataset is 1,000,000 rows containing randomly generated input
// sets along with calculation results from the NREL C Implementation of SPA.
//
// It is not included in this repository due to it's size (280 MB)
// but you download it here: https://i.tst.sh/spa/dataset.zip
//
// If dataset.csv is not found, fall back to the smaller version
// which contains the first 1,000 rows of the full dataset.
if (!await testCsv('test/dataset.csv')) {
await testCsv('test/dataset_small.csv');
}
}