Skip to content

Commit

Permalink
Migrate code to sound null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermecaldas committed Sep 12, 2021
1 parent 76c8a55 commit 5c7e620
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 33 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ jobs:
- uses: actions/checkout@v1

- name: Install dependencies
run: pub get
run: dart pub get

# - name: Install coverage
# run: dart pub global activate coverage

- name: Run tests
run: pub run test
run: dart run test

- name: Run coverage
run: pub run test_coverage
# - name: Run coverage
# run: collect_coverage

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# - name: Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0
- Support to sound null safety
- Update deprecated dependencies

## 0.1.2
- Update code to match Pedantic recommendations
- Fix examples
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml
6 changes: 3 additions & 3 deletions example/q_calc_util_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:q_calc_util/q_calc_util.dart';

void printResults(DixonResults result, int confidence) {
print('''
Confidence: ${confidence}%
Lower end: ${result.lowerEnd.toStringAsFixed(3)}
Upper end: ${result.upperEnd.toStringAsFixed(3)}
Confidence: $confidence%
Lower end: ${result.lowerEnd!.toStringAsFixed(3)}
Upper end: ${result.upperEnd!.toStringAsFixed(3)}
Q: ${result.q}
N: ${result.n}
Values: ${result.values.toString()}
Expand Down
10 changes: 5 additions & 5 deletions lib/src/q_calc_util_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final Map<int, double> _qTable99 = {

/// Returns a double value from Dixon constants map representing the Q value for
/// the given `confidence` and `n` value
double _getQ(Confidence confidence, int n) {
double? _getQ(Confidence confidence, int n) {
switch (confidence) {
case Confidence.percent95:
return _qTable95[n];
Expand All @@ -93,7 +93,7 @@ double _getQ(Confidence confidence, int n) {

//Checks if value is approved under given confidence and n
bool _isApproved(double value, Confidence confidence, int n) {
return (value < _getQ(confidence, n));
return (value < _getQ(confidence, n)!);
}

//lower end functions
Expand Down Expand Up @@ -161,8 +161,8 @@ DixonResults _calculateQTest(List<double> values, DixonResults results) {

/// A representation of a Q Test calculation result
class DixonResults {
double lowerEnd;
double upperEnd;
double? lowerEnd;
double? upperEnd;
List<double> values;
List<double> removedValues = [];
final Confidence _confidence;
Expand All @@ -176,7 +176,7 @@ class DixonResults {
int get n => values.length;

/// The Q constant from Dixon's table for the resulting n and given confidence
double get q => _getQ(confidence, n);
double? get q => _getQ(confidence, n);
}

/// A representation of a Q Test error
Expand Down
7 changes: 3 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ name: q_calc_util
description: >
Dixon's Q Test calculator package for Dart. It makes it easy to identify an
outlier in a range between 3 and 30 double numbers
version: 0.1.2
version: 1.0.0
homepage: https://github.com/ChemisTechlabs/q_calc_util

environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
lints: ^1.0.1
test: ^1.9.4
test_coverage: ^0.4.0
pedantic: ^1.0.0
24 changes: 12 additions & 12 deletions test/q_calc_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void main() {

expect(results.q, equals(0.569));
expect(results.n, equals(7));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.1531'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.0017'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.1531'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.0017'));
expect(results.removedValues.length, equals(1));
expect(results.removedValues, equals([1.9]));
});
Expand All @@ -107,8 +107,8 @@ void main() {

expect(results.q, equals(0.489));
expect(results.n, equals(20));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.0854'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.1972'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.0854'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.1972'));
expect(results.removedValues.length, equals(0));
expect(results.removedValues, equals([]));
});
Expand All @@ -123,8 +123,8 @@ void main() {

expect(results.q, equals(0.586));
expect(results.n, equals(14));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.1190'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.4714'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.1190'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.4714'));
expect(results.removedValues.length, equals(0));
expect(results.removedValues, equals([]));
});
Expand All @@ -136,8 +136,8 @@ void main() {

expect(results.q, equals(0.717));
expect(results.n, equals(8));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.1531'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.6468'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.1531'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.6468'));
expect(results.removedValues.length, equals(0));
expect(results.removedValues, equals([]));
});
Expand All @@ -152,8 +152,8 @@ void main() {

expect(results.q, equals(0.567));
expect(results.n, equals(20));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.0854'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.1972'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.0854'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.1972'));
expect(results.removedValues.length, equals(0));
expect(results.removedValues, equals([]));
});
Expand All @@ -168,8 +168,8 @@ void main() {

expect(results.q, equals(0.670));
expect(results.n, equals(14));
expect(results.lowerEnd.toStringAsFixed(4), equals('0.1190'));
expect(results.upperEnd.toStringAsFixed(4), equals('0.4714'));
expect(results.lowerEnd!.toStringAsFixed(4), equals('0.1190'));
expect(results.upperEnd!.toStringAsFixed(4), equals('0.4714'));
expect(results.removedValues.length, equals(0));
expect(results.removedValues, equals([]));
});
Expand Down

0 comments on commit 5c7e620

Please sign in to comment.