Skip to content

Commit

Permalink
isDiscrete flag added to Series
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Aug 24, 2019
1 parent 1a8f4cb commit 26d8268
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/src/data_frame/series.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
class Series {
Series(this.name, this.data);
Series(this.name, this.data, {
bool isDiscrete = false,
}) : discreteValues = isDiscrete
? Set<dynamic>.from(data)
: const <dynamic>[];

final String name;
final Iterable data;
final Iterable discreteValues;

bool get isDiscrete => discreteValues.isNotEmpty;
}
32 changes: 32 additions & 0 deletions test/data_frame/data_frame_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,37 @@ void main() {
expect(frame[2].name, 'third');
expect(frame[2].data, equals([3, 323, 1000]));
});

test('should return null if one tries to access a series using a key of '
'improper type (neither String nor int)', () {
final data = [
['first', 'second', 'third'],
[ '1', 2, 3 ],
[ 10, 12, 323 ],
[ -10, 202, 1000 ],
];
final frame = DataFrame(data, headerExists: true,
columnNames: ['col_1', 'col_3', 'col_4']);

expect(frame[{1}], isNull);
expect(frame[1.2], isNull);
expect(frame[[1, 2]], isNull);
});

test('should throw a range error if one tries to access a series using an '
'integer key which is out of range', () {
final data = [
['first', 'second', 'third'],
[ '1', 2, 3 ],
[ 10, 12, 323 ],
[ -10, 202, 1000 ],
];
final frame = DataFrame(data, headerExists: true,
columnNames: ['col_1', 'col_3', 'col_4']);

expect(() => frame[3], throwsRangeError);
expect(() => frame[4], throwsRangeError);
expect(() => frame[-1], throwsRangeError);
});
});
}
26 changes: 26 additions & 0 deletions test/data_frame/series_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:ml_dataframe/ml_dataframe.dart';
import 'package:test/test.dart';

void main() {
group('Series', () {
test('should initialize properly', () {
final data = [1, 2, 3, '4'];
final series = Series('series_name', data);

expect(series.name, 'series_name');
expect(series.data, equals(data));
expect(series.isDiscrete, isFalse);
expect(series.discreteValues, isEmpty);
});

test('should initialize as a series with discrete data sequence', () {
final data = [1, 2, 3, '4', 1, 2, 10, '4'];
final series = Series('series_name', data, isDiscrete: true);

expect(series.name, 'series_name');
expect(series.data, equals(data));
expect(series.isDiscrete, isTrue);
expect(series.discreteValues, equals([1, 2, 3, '4', 10]));
});
});
}
7 changes: 7 additions & 0 deletions test/numerical_converter/numerical_converter_impl_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:test/test.dart';

void main() {
group('', () {

});
}

0 comments on commit 26d8268

Please sign in to comment.