diff --git a/lib/src/data_frame/series.dart b/lib/src/data_frame/series.dart index b572c9e..f2784e9 100644 --- a/lib/src/data_frame/series.dart +++ b/lib/src/data_frame/series.dart @@ -1,6 +1,13 @@ class Series { - Series(this.name, this.data); + Series(this.name, this.data, { + bool isDiscrete = false, + }) : discreteValues = isDiscrete + ? Set.from(data) + : const []; final String name; final Iterable data; + final Iterable discreteValues; + + bool get isDiscrete => discreteValues.isNotEmpty; } diff --git a/test/data_frame/data_frame_test.dart b/test/data_frame/data_frame_test.dart index 65ab113..a880d5d 100644 --- a/test/data_frame/data_frame_test.dart +++ b/test/data_frame/data_frame_test.dart @@ -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); + }); }); } diff --git a/test/data_frame/series_test.dart b/test/data_frame/series_test.dart new file mode 100644 index 0000000..b9cf47d --- /dev/null +++ b/test/data_frame/series_test.dart @@ -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])); + }); + }); +} diff --git a/test/numerical_converter/numerical_converter_impl_test.dart b/test/numerical_converter/numerical_converter_impl_test.dart new file mode 100644 index 0000000..44eab59 --- /dev/null +++ b/test/numerical_converter/numerical_converter_impl_test.dart @@ -0,0 +1,7 @@ +import 'package:test/test.dart'; + +void main() { + group('', () { + + }); +}