Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/integration_test/vector/constructors/from_json/from_json_constructor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:ml_linalg/dtype.dart'; | ||
|
||
import 'from_json_constructor_test_group_factory.dart'; | ||
|
||
void main() { | ||
fromJsonConstructorTestGroupFactory(DType.float32); | ||
fromJsonConstructorTestGroupFactory(DType.float64); | ||
} |
36 changes: 36 additions & 0 deletions
36
...egration_test/vector/constructors/from_json/from_json_constructor_test_group_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:ml_linalg/dtype.dart'; | ||
import 'package:ml_linalg/dtype_to_json.dart'; | ||
import 'package:ml_linalg/src/vector/vector_json_keys.dart'; | ||
import 'package:ml_linalg/vector.dart'; | ||
import 'package:ml_tech/unit_testing/matchers/iterable_almost_equal_to.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../../../dtype_to_title.dart'; | ||
|
||
void fromJsonConstructorTestGroupFactory(DType dtype) => | ||
group(dtypeToVectorTestTitle[dtype], () { | ||
group('fromJson constructor', () { | ||
final data = <double>[12, 23, 44.0, -1e10, 10007.888, -10, 0, 7]; | ||
final json = { | ||
vectorDTypeJsonKey: dTypeToJson(dtype), | ||
vectorDataJsonKey: data, | ||
}; | ||
final unknownJson = { | ||
vectorDTypeJsonKey: 'some_unknown_dtype', | ||
vectorDataJsonKey: data, | ||
}; | ||
|
||
test('should decode serialized vector', () { | ||
final vector = Vector.fromJson(json); | ||
|
||
expect(vector, iterableAlmostEqualTo(data, 1e-3)); | ||
expect(vector.dtype, dtype); | ||
}); | ||
|
||
test('should throw an error if unknown decoded value is passed', () { | ||
final actual = () => Vector.fromJson(unknownJson); | ||
|
||
expect(actual, throwsUnsupportedError); | ||
}); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
test/integration_test/vector/methods/to_json/to_json_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:ml_linalg/dtype.dart'; | ||
|
||
import 'to_json_test_group_factory.dart'; | ||
|
||
void main() { | ||
vectorToJsonTestGroupFactory(DType.float32); | ||
vectorToJsonTestGroupFactory(DType.float64); | ||
} |
24 changes: 24 additions & 0 deletions
24
test/integration_test/vector/methods/to_json/to_json_test_group_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:ml_linalg/dtype.dart'; | ||
import 'package:ml_linalg/dtype_to_json.dart'; | ||
import 'package:ml_linalg/src/vector/vector_json_keys.dart'; | ||
import 'package:ml_linalg/vector.dart'; | ||
import 'package:ml_tech/unit_testing/matchers/iterable_almost_equal_to.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../../../dtype_to_title.dart'; | ||
|
||
void vectorToJsonTestGroupFactory(DType dtype) => | ||
group(dtypeToVectorTestTitle[dtype], () { | ||
group('toJson method', () { | ||
final data = <double>[100, 129, 3.555, 5.07, -600, 17, 84]; | ||
final vector = Vector.fromList(data, dtype: dtype); | ||
|
||
test('should return a json-serializable map', () { | ||
final encoded = vector.toJson(); | ||
|
||
expect(encoded[vectorDTypeJsonKey], dTypeToJson(dtype)); | ||
expect(encoded[vectorDataJsonKey], iterableAlmostEqualTo(data)); | ||
expect(encoded.keys, hasLength(2)); | ||
}); | ||
}); | ||
}); |
44 changes: 0 additions & 44 deletions
44
test/unit_test/vector/serialization/from_vector_json_test.dart
This file was deleted.
Oops, something went wrong.