question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct way to test laws.

See original GitHub issue

Hello fantasy crew!

I’m wondering, what is the “correct” way to ensure that a custom data type is lawful?

My initial thought was to include modules from the /laws directory and define a custom eq method.

Here is an example for an IO implementation conforming to Functor (using jest, if you’re interested)

const VAL = 1;
const eq = (a, b) =>
  a.run() === b.run();

test('Functor', () => {
  const identity = functor.identity(IO.of)(eq)(VAL);
  const composition =
    functor.composition(IO.of)(eq)(add(1))(multiply(10))(VAL);

  expect(identity).toBe(true);
  expect(composition).toBe(true);
});

This was going quite well until I tried to write a test for Foldable. It seems that the test for Foldable depends on a toArray method that isn’t mentioned anywhere in the spec. This leads me to believe that the the checks defined in /laws are more guidelines for writing tests, instead of being the tests themselves.

I was hoping someone could provide some clarification. I would love to be able to prove in tests that implementations are law-abiding for any given version of FL.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davidchamberscommented, Aug 12, 2017

That depends on your use case, @dustinws. It’s probably a good idea to point to a commit hash rather than the branch name as I’ll delete the branch once the pull request has been merged. GitHub never seems to garbage collect dangling commits, so even if I rebase you should be able to continue to access the existing commits by their hashes.

1reaction
davidchamberscommented, Aug 12, 2017

@dustinws, have a look at fantasyland/fantasy-laws#1. The code is complete, but I’d like to improve the readme before merging the pull request. Please share any thoughts that occur to you. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rational Basis Test | Wex - Law.Cornell.Edu
The rational basis test is a judicial review test. A judicial review test is what courts use to determine the constitutionality of a...
Read more >
Test (law) - Wikipedia
In law, a test is a commonly applied method of evaluation used to resolve matters of jurisprudence. In the context of a trial,...
Read more >
Applying Common Law Control Test for Employer/Employee ...
The primary consideration when applying the common law test is to determine who has the right to control two basic elements; WHAT MUST...
Read more >
Federal Laws and Regulations | SAMHSA
Numerous federal requirements govern drug-free workplace policies.
Read more >
Employment Tests and Selection Procedures
The test or selection procedure must be job-related and its results appropriate for the employer's purpose.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found