Giter VIP home page Giter VIP logo

Comments (6)

jvanbruegge avatar jvanbruegge commented on June 18, 2024

I found all questions answered. Nothing to complain about.

from time.

rjkip avatar rjkip commented on June 18, 2024

I think it should be mentioned somewhere that completion times are not taken into account when comparing streams. An example: '-x-|' == '-x---|'.

from time.

Widdershin avatar Widdershin commented on June 18, 2024

@rjkip I might change that. My original rationale was that sometimes you want to make assertions against diagrams where the last event and completion occur in the same frame (character in diagram).

Like:

it("creates a stream that emits every period ms", (done) => {
  const Time = mockTimeSource();

  const stream = Time.periodic(40);

  const expected = Time.diagram(
    `----0---1---2|`
  );

  Time.assertEqual(
    stream.take(3),
    expected
  );

  Time.run(done);
});

The expected diagram states that completion occurs the frame after the last event, whereas in reality it occurs immediately. So there is lenience in asserting and a kludge in diagram generation to support this case.

The real fix for this issue is so support syntax for multiple items in a single frame, which I plan on investigating soon.

Even then I think it would be ugly to have to do:

it("creates a stream that emits every period ms", (done) => {
  const Time = mockTimeSource();

  const stream = Time.periodic(40);

  const expected = Time.diagram(
    `----0---1---(2|)`
  );

  Time.assertEqual(
    stream.take(3),
    expected
  );

  Time.run(done);
});

I'm also considering another kludge where I would check the time difference between completion events for actual and expected and fail if it's more than one frame different.

from time.

Widdershin avatar Widdershin commented on June 18, 2024

@rjkip I have released v0.6 which will fail a test if the actual and expected streams end at different times.

As part of this I have also added syntax to express simultaneous events, as per the above example.

However, to improve the readability of the above test, I have allowed for testing infinite streams without completion:

it("creates a stream that emits every period ms", (done) => {
  const Time = mockTimeSource();

  const stream = Time.periodic(80);

  const expected = Time.diagram(
    `----0---1---2---`
  );

  Time.assertEqual(
    stream,
    expected
  );

  Time.run(done);
});

Even though periodic is infinite, now Time.run() will only run to the end of your longest diagram (if you've used a diagram). So we can now test infinite streams without using .take, which is nice, and they will no longer run forever if you forget to use .take.

from time.

rjkip avatar rjkip commented on June 18, 2024

@rjkip I have released v0.6 which will fail a test if the actual and expected streams end at different times.

That sounds good. Confirmed to work as well :)

It does make a test that tests for a value and a completion in the same frame a bit awkward, but I think that's acceptable. These things are hard. You can still change it in a future minor, though :)

Time.assertEqual(Time.periodic(20).take(1), Time.diagram(`-(0|)`));

[...] I have allowed for testing infinite streams without completion:

Great! I was wondering about options there :)

All in all, thanks for replying and creating and maintaining this library 👌

from time.

Widdershin avatar Widdershin commented on June 18, 2024

It does make a test that tests for a value and a completion in the same frame a bit awkward, but I think that's acceptable. These things are hard.

Agreed, but I figure for a testing tool it's important to prioritize accuracy and correctness. I would rather be explicit and slightly awkward than implicit and imprecise.

In any case, this will only really come up when you have a stream designed to emit in the last frame, like of and last. It's thankfully not the common case for Cycle.js apps.

from time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.