Skip to content

Commit

Permalink
unit tests for [] operator added
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Aug 23, 2019
1 parent b369053 commit 1a8f4cb
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/data_frame/data_frame_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:ml_dataframe/ml_dataframe.dart';
import 'package:ml_dataframe/src/data_frame/data_frame.dart';
import 'package:ml_linalg/matrix.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -87,6 +88,31 @@ void main() {
]));
});

test('should initialize from a series collection', () {
final series = [
Series('first', <dynamic>[1, 2, 3, true, '32']),
Series('second', <dynamic>[10, 12, 323, false, '1132']),
Series('third', <dynamic>[-10, 202, null, true, 'abs']),
];
final frame = DataFrame.fromSeries(series);

expect(frame.header, equals(['first', 'second', 'third']));
expect(frame.rows, equals([
[ 1, 10, -10 ],
[ 2, 12, 202 ],
[ 3, 323, null ],
[ true, false, true ],
[ '32', '1132', 'abs' ],
]));
expect(frame.series.map((series) => series.name),
equals(['first', 'second', 'third']));
expect(frame.series.map((series) => series.data), equals([
<dynamic>[1, 2, 3, true, '32'],
<dynamic>[10, 12, 323, false, '1132'],
<dynamic>[-10, 202, null, true, 'abs'],
]));
});

test('should use predefined header while initializng even if source data '
'has header row', () {
final data = [
Expand Down Expand Up @@ -215,5 +241,45 @@ void main() {
[-10, 1000, 1.5],
]));
});

test('should provide access to its series by series name', () {
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['first'].name, 'first');
expect(frame['first'].data, equals(['1', 10, -10]));

expect(frame['second'].name, 'second');
expect(frame['second'].data, equals([2, 12, 202]));

expect(frame['third'].name, 'third');
expect(frame['third'].data, equals([3, 323, 1000]));
});

test('should provide access to its series by series index', () {
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[0].name, 'first');
expect(frame[0].data, equals(['1', 10, -10]));

expect(frame[1].name, 'second');
expect(frame[1].data, equals([2, 12, 202]));

expect(frame[2].name, 'third');
expect(frame[2].data, equals([3, 323, 1000]));
});
});
}

0 comments on commit 1a8f4cb

Please sign in to comment.