-
Notifications
You must be signed in to change notification settings - Fork 30
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
1 parent
f5cc545
commit 211dbf1
Showing
6 changed files
with
223 additions
and
26 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
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
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
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
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,63 @@ | ||
// Developed by Marcelo Glasberg (2021) https://glasberg.dev and https://github.com/marcglasberg | ||
// and Philippe Fanaro https://github.com/psygo | ||
// For more info, see: https://pub.dartlang.org/packages/fast_immutable_collections | ||
import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
setUp(() { | ||
ImmutableCollection.resetAllConfigurations(); | ||
ImmutableCollection.autoFlush = false; | ||
}); | ||
|
||
test("Runtime Type", () { | ||
expect(const IMapEmpty(), isA<IMapEmpty>()); | ||
expect(const IMapEmpty(), isA<IMapEmpty>()); | ||
expect(const IMapEmpty<String, String>(), isA<IMapEmpty<String, String>>()); | ||
expect(const IMapEmpty<int, String>(), isA<IMapEmpty<int, String>>()); | ||
|
||
expect(const IMapEmpty(), isA<IMap>()); | ||
expect(const IMapEmpty(), isA<IMap>()); | ||
expect(const IMapEmpty<String, String>(), isA<IMap<String, String>>()); | ||
expect(const IMapEmpty<int, String>(), isA<IMap<int, String>>()); | ||
}); | ||
|
||
test("Make sure the IMapEmpty can be modified and later iterated", () { | ||
// MAddAll | ||
IMap<String, int> map = const IMap.empty(); | ||
map = map.addEntries([ | ||
const MapEntry("a", 1), | ||
const MapEntry("b", 2), | ||
const MapEntry("c", 3) | ||
]); | ||
map.forEach((_, __) { }); | ||
|
||
// MAdd | ||
map = const IMap.empty(); | ||
map = map.add("d", 4); | ||
map.forEach((_, __) { }); | ||
|
||
// MReplace | ||
map = const IMap.empty(); | ||
map = map.add("d", 42); | ||
map.forEach((_, __) { }); | ||
}); | ||
|
||
test("Make sure the internal map is Map<int, String>, and not Map<Never>", () { | ||
const m1 = IMapEmpty<String, int>(); | ||
expect(m1.runtimeType.toString(), 'IMapEmpty<String, int>'); | ||
|
||
const m2 = IMapConst<String, int>({'a': 1, 'b': 2, 'c': 3}); | ||
expect(m2.runtimeType.toString(), 'IMapConst<String, int>'); | ||
|
||
final m3 = m1.addAll(m2); | ||
expect(m3.runtimeType.toString(), 'IMapImpl<String, int>'); | ||
|
||
final result = m3.where((String key, int value) => value == 2); | ||
expect(result, {'b': 2}.lock); | ||
}); | ||
|
||
test(".same() is working properly", () { | ||
expect(const IMap.empty().same(const IMap.empty()), isTrue); | ||
}); | ||
} |
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,54 @@ | ||
// Developed by Marcelo Glasberg (2021) https://glasberg.dev and https://github.com/marcglasberg | ||
// and Philippe Fanaro https://github.com/psygo | ||
// For more info, see: https://pub.dartlang.org/packages/fast_immutable_collections | ||
import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
setUp(() { | ||
ImmutableCollection.resetAllConfigurations(); | ||
ImmutableCollection.autoFlush = false; | ||
}); | ||
|
||
test("Runtime Type", () { | ||
expect(const ISetEmpty(), isA<ISetEmpty>()); | ||
expect(const ISetEmpty(), isA<ISetEmpty>()); | ||
expect(const ISetEmpty<String>(), isA<ISetEmpty<String>>()); | ||
expect(const ISetEmpty<int>(), isA<ISetEmpty<int>>()); | ||
|
||
expect(const ISetEmpty(), isA<ISet>()); | ||
expect(const ISetEmpty(), isA<ISet>()); | ||
expect(const ISetEmpty<String>(), isA<ISet<String>>()); | ||
expect(const ISetEmpty<int>(), isA<ISet<int>>()); | ||
}); | ||
|
||
test("Make sure the ISetEmpty can be modified and later iterated", () { | ||
// SAddAll | ||
ISet<String> set = const ISet.empty(); | ||
set = set.addAll(["a", "b", "c"]); | ||
set.forEach((_) { }); | ||
|
||
// SAdd | ||
set = const ISet.empty(); | ||
set = set.add("d"); | ||
set.forEach((_) { }); | ||
}); | ||
|
||
test("Make sure the internal set is Set<int>, and not Set<Never>", () { | ||
const s1 = ISetEmpty<int>(); | ||
expect(s1.runtimeType.toString(), 'ISetEmpty<int>'); | ||
|
||
const s2 = ISetConst<int>({1, 2, 3}); | ||
expect(s2.runtimeType.toString(), 'ISetConst<int>'); | ||
|
||
final s3 = s1.addAll(s2); | ||
expect(s3.runtimeType.toString(), 'ISetImpl<int>'); | ||
|
||
final result = s3.where((int i) => i == 2).toSet(); | ||
expect(result, [2]); | ||
}); | ||
|
||
test(".same() is working properly", () { | ||
expect(const ISet.empty().same(const ISet.empty()), isTrue); | ||
}); | ||
} |