Comments (4)
expect
does not use ==
, but has a more sophisticated matching method.
See https://github.com/dart-lang/matcher/blob/3a80b989c5c1071d32af11ea9d3fae55807a14c2/lib/src/equals_matcher.dart#L18 ,
and https://github.com/dart-lang/matcher/blob/3a80b989c5c1071d32af11ea9d3fae55807a14c2/lib/src/equals_matcher.dart#L107 in particular.
So, Iterables are compared deeply by expect, even if ==
would return false
on them.
But you don't give an Iterable to expect
, you give a Right([1, 2, 3, 4, 5]) to expect
.
So expect
eventually compares the Either
instances by ==
.
And Either compares the wrapped value by ==
, which will return false, because List don't implement ==
, and since these are two instances of Lists, ==
will return false.
@SandroMaglione suggested using Lists that do implement ==
, for example fast_immutable_collections.
Your would use it like this: Right(IList([1, 2, 3, 4, 5]));
I would recommend doing this anyway since mutable collections don't play well with functional programming.
from fpdart.
Hi @Babwenbiber
The reason the test fails is that natively dart compares lists by identity. This means that dart will not compare the elements inside the list but it will check that the two lists are the same instance (which is not the case).
There are many solutions to this problem. Generally, you should override the ==
and hashCode
methods (like fpdart does for Either
).
Another solution would be to use Equatable package.
For lists specifically, you must either implement a custom equality method (that compares by equality and not by identity) or relay on some package that does this already:
Does this answer solve your doubts?
from fpdart.
Thanks a lot for the detailed answer.
I am still quite unsure about some points.
I have read many times, that == does compare identity, but expect([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]);
yields true. So how does this fit into the story?
Furthermore, I checked out the fast_.. package and couldn't understand how to apply this to either. Can you give me a mini example or best practice on how you write your tests?
Thanks
from fpdart.
Thanks.
I didn't know people use IList instead of List :)
from fpdart.
Related Issues (20)
- fpdart sortBy is very slow and time processing scales very quickly HOT 3
- Add methods to convert `IO` to other classes (`TaskEither`, `TaskOption`, `IOEither`)
- Llinks are not working HOT 1
- fpdart v1.0.0 HOT 20
- Add getOrThrow for Either TaskEither HOT 1
- slight typo in lib/src/class/applicative.dart
- [BUG]: unnable to create stubs any of the fpdart types HOT 7
- DISCUSSION : Extension HOT 1
- Factory const constructor(s) HOT 1
- [Question] Update 0.6.0 functions to 1.1.0 HOT 2
- Mockito can't generate stubs for functions returning Either HOT 1
- Help with adaptation to fpdart HOT 13
- Support for TaskEither.tryCatchK HOT 1
- Code formatting HOT 2
- Anchors in menu of readme file doesn't work HOT 2
- Export fpdart package conflict with State of material. HOT 3
- Do Notation throws instance of '_OptionThrow' HOT 7
- [question] cannot use .andThen in option HOT 4
- Issue: Version 0.4.1 creates Type Exception on getOrElse HOT 2
- foldLeft documentation is incorrect HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fpdart.