New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize result #127

Closed
joneshf opened this Issue Jul 31, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@joneshf
Contributor

joneshf commented Jul 31, 2015

What do you think about moving from specifically booleans to a more generalized approach like Testable?

I'd like to be able to attach reasons to errors, among other things, and booleans don't carry enough information with them for this.

@phadej phadej added the enhancement label Jul 31, 2015

@phadej

This comment has been minimized.

Show comment
Hide comment
@phadej

phadej Jul 31, 2015

Member

Yes!

Currently only true in considered as successful value, so:

> jsc.check(jsc.forall("nat", function (n) { return "cause: " + n; }))
Failed after 1 tests and 6 shrinks. rngState: 00da3714f9c2058eb6; Counterexample: 0;  [ 0 ]

You don't see the non-true value though, but it should be easy to add, as we show exceptions (which are the current workaround):

> jsc.check(jsc.forall("nat", function (n) { throw new Error("cause: " + n); }))
Failed after 1 tests and 4 shrinks. rngState: 0adc76385e20ab149f; Counterexample: 0; Exception: cause: 0
Member

phadej commented Jul 31, 2015

Yes!

Currently only true in considered as successful value, so:

> jsc.check(jsc.forall("nat", function (n) { return "cause: " + n; }))
Failed after 1 tests and 6 shrinks. rngState: 00da3714f9c2058eb6; Counterexample: 0;  [ 0 ]

You don't see the non-true value though, but it should be easy to add, as we show exceptions (which are the current workaround):

> jsc.check(jsc.forall("nat", function (n) { throw new Error("cause: " + n); }))
Failed after 1 tests and 4 shrinks. rngState: 0adc76385e20ab149f; Counterexample: 0; Exception: cause: 0
@joneshf

This comment has been minimized.

Show comment
Hide comment
@joneshf

joneshf Aug 19, 2015

Contributor

Oh, I see. So the quick way to go about this is to just wrap up that difference in a function.

function assert(b, msg) {
  if (b) {
    return b;
  } else {
    throw new Error(msg);
  }
}

But that seems really dirty.

Contributor

joneshf commented Aug 19, 2015

Oh, I see. So the quick way to go about this is to just wrap up that difference in a function.

function assert(b, msg) {
  if (b) {
    return b;
  } else {
    throw new Error(msg);
  }
}

But that seems really dirty.

@phadej phadej closed this in c31e46a Aug 22, 2015

phadej added a commit that referenced this issue Aug 22, 2015

Merge pull request #131 from jsverify/127-non-true-result
Resolve #127: non-true result as an exception
@phadej

This comment has been minimized.

Show comment
Hide comment
@phadej

phadej Aug 22, 2015

Member
> jsc.assert(jsc.forall("nat", function () { return "foobar"; }));
Error: Failed after 1 tests and 6 shrinks. rngState: 0073892e5dfbc4a016; Counterexample: 0; Error: foobar
Member

phadej commented Aug 22, 2015

> jsc.assert(jsc.forall("nat", function () { return "foobar"; }));
Error: Failed after 1 tests and 6 shrinks. rngState: 0073892e5dfbc4a016; Counterexample: 0; Error: foobar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment