Lisplog

Blogging in Lisp

Search

Feed Aggregator Page 344

Rendered on Wed, 15 May 2019 14:02:05 GMT  newer latest older 

Idea: add statistical labeling to elm-test

via Elm Discourse - Latest posts by @brian Brian on Wed, 15 May 2019 13:53:37 GMT

Have a look at the talk starting about here: https://youtu.be/NcJOiQlzlXQ?t=2402

He justifies why this must be the case. :slight_smile:

Idea: add statistical labeling to elm-test

via Elm Discourse - Latest posts by @gampleman Jakub Hampl on Wed, 15 May 2019 13:49:02 GMT

Don’t think that would be very valuable, since whether or not one gets the warning is pure luck as is whether the warning is a false positive.

Idea: add statistical labeling to elm-test

via Elm Discourse - Latest posts by @brian Brian on Wed, 15 May 2019 13:46:29 GMT

Why? What about fuzz2 and so on? There’s composition there, would it discard the labels? If no, why? If you want a string and an int, and labels live on the fuzzer, you’d have to make a fuzzer like Fuzz.map2 Tuple.pair Fuzz.int Fuzz.string with new labeling and validation per test. This indicates to me that the labels, at least in the composition case, are better as a test responsibility.

I don’t understand how you got from the first sentence to the second. Could you help me by saying more about the link here? What requires this, philosophically? What philosophy are we talking about here?

That said, I think there are tradeoffs either way. Based on your understanding of the world you say that they should live on the fuzzer. Based on mine, I say they should live on the test. I don’t see anything that prevents either from being successful. I started from the test side because that’s what the Haskell QuickCheck does, but from what I understand they have less control over fuzz input than we do. If that creates some bad assumptions for us, OK! I’ll drop 'em. :slight_smile:

Verifying coverage targets have been met will have to be a special mode for exactly this reason (like seeing examples.) We can warn if coverage is not met during a regular test run, though.

How to write parameterized tests in Elm

via Elm Discourse - Latest posts by @choonkeat on Wed, 15 May 2019 13:07:39 GMT

If you want different Expectations, then you’ll need to have different tests.

suite : Test
suite =
    describe "isOdd" <|
        List.map
            (\{ given, expected } ->
                test (String.fromInt given) <|
                    \_ ->
                        Expect.equal expected (isOdd given)
            )
            [ { given = 1, expected = True }
            , { given = 2, expected = False }
            , { given = 3, expected = True }
            , { given = 6, expected = False }
            ]

This pattern is similar to “table driven tests” that Go community prefers, but because of the way List.map argument order works, your test code will come before your test data “table”; no biggie imo

Also, feel free to use Debug.toString given instead of String.fromInt given if your given is a more complicated type. Since this is just test, using Debug to spell out the test name is probably forgivable.

Elm-json: A tool for managing elm.json files

via Elm Discourse - Latest posts by @system system on Wed, 15 May 2019 12:54:06 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Simulate an onInput event from javascript

via Elm Discourse - Latest posts by @chalmagean Cezar Halmagean on Wed, 15 May 2019 12:19:28 GMT

I’m testing an Elm form with selenium and whenever I change the value of a select, Elm doesn’t receive the event. So I am unable to simulate a real user selecting a different option in a dropdown.

I’ve tried triggering the event with javascript in the browser with no luck.

What’s the best way to do this?

The most basic of POS systems written in ELM

via Elm Discourse - Latest posts by @dnk8n Dean Kayton on Wed, 15 May 2019 09:59:28 GMT

I would definitely not want it online though. Internet can be flaky out where I live (rural South Africa, place called Kosi Bay)

Looks like a local backend server is the obvious choice for simplicity!

Optimizing Base64 encoding/decoding

via Elm Discourse - Latest posts by @folkertdev Folkert De Vries on Wed, 15 May 2019 09:50:00 GMT

The code presented here has now been merged into master and will be part of the next release of base64-bytes.

@unsoundscapes interesting. I know that haskell under some circumstances will realize that it creates a tuple, only to immediately pattern match on it again (in the next loop iteration).
It then unboxes the tuple saving some indirection. Perhaps the jit does something similar? It would be convenient if elm could do that kind of optimization for this kind of work.

@mgold absolutely, which is why it was so nice the package already had a solid set of fuzz tests.
Also i remember some 1000000x speedups because a function just immediately returned Nothing.

The most basic of POS systems written in ELM

via Elm Discourse - Latest posts by @Herteby Simon Herteby on Wed, 15 May 2019 09:46:17 GMT

So you’d do peer-to-peer networking using WebRTC? That’ll definitely require JS, and seems pretty complicated. There’s also no real safe way to store data in a browser (that survives “clearing cookies”).

I think the simplest option when you don’t want to worry about the backend is probably a BaaS like Firebase. With Firebase you can get realtime messaging too, though you’ll have to install the Firebase JS client and connect it to Elm with ports.

Integration tests in Elm?

via Elm Discourse - Latest posts by @system system on Wed, 15 May 2019 09:42:03 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

How to write simple test cases in Elm

via Elm Discourse - Latest posts by @ondrej on Wed, 15 May 2019 09:33:16 GMT

I agree that it’s good practice to have a single reason to fail. What I wrote was for simplification.

Usually the testing fw has some way to write down test cases and it will then generate those tests for you. In C# you would usually annotate the method and the build system would generate tests with one assertion each.

[TestCase(-1, True)]
[TestCase(0, False)]
[TestCase(1, True)]
public void IsOdd_Tests(int input, bool expected) {
  Assert.Equal(Utils.isOdd(input), expected);
}

I’m looking for something similar in Elm so I don’t have to write a bunch of boilerplate code.

How to write simple test cases in Elm

via Elm Discourse - Latest posts by @dillonkearns Dillon Kearns on Tue, 14 May 2019 22:29:12 GMT

There’s a common testing principle that many people follow, which is that a test should only have a single reason to fail. That way, you don’t end up with tests failing and keeping you from getting information about other assertions in the test case. And you have a clear focus for each test. elm-test takes that stance. That’s why Expect.all applies to a single test subject. And perhaps it helps explain the design if I point out that the subject argument is really intended to be a single test subject that you make multiple assertions about, so passing in True or False as the last argument to Expect.all is probably going to end up feeling awkward I would say.

Also, I would recommend trying out Expect.true and Expect.false instead of Expect.equal. You can create a nice helper function for isOdd or whatever helpers would make sense.

isOdd n =
  (n |> modBy 2 == 0)
  |> Expect.true "Expected an odd number."

Hope that helps!

How to write simple test cases in Elm

via Elm Discourse - Latest posts by @ondrej on Tue, 14 May 2019 20:35:30 GMT

thanks for the solution.

Is there also a way to write it so that the expected could differ for different inputs?

test("sayHi", function(assert) {
  assert.equal(sayHi("Thomas"), "Hello Thomas!");
  assert.equal(sayHi("George"), "Hello George");
  assert.equal(sayHi(""), "Hello");
  ...
})

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @turboMaCk Marek Fajkus on Tue, 14 May 2019 19:29:13 GMT

That’s good to hear @avh4. In my opinion we need to be careful around changes in binwrap. It might be problematic on NixOS right now but it provides support for Mac, Windows and plenty of Linux distros. In my opinion it’s better to be slightly more defensive - we should avoid breaking what is working fine.

Furthermore I don’t think the issue is with binwrap itself but with the way it’s used in npm scripts. I was thinking I about patching it in a way binwrap works as usual but than I though nixpkgs way is usually to build from source and cache the binary so this approach (not using binwrap) is more nixpkgs way in the end I think.

Not sure if you know but elm-format is already in nixpkgs so anyone on NixOS or with nix can just install it via nix-env -i elmPackages.elm-format.

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @avh4 on Tue, 14 May 2019 19:21:31 GMT

  1. Remove all the hacks in upstream packages to make them nix compatible out of the box.
  2. Implement custom nix specific builds for elm tooling with nix specific patches.

Given that nix users makes only for a tiny fraction elm community I believe it would be naive to try to enforce compatibility directly in upstream packages and therefore this project uses 2nd approach to provide elm lang tooling to nix community.

FYI, as the maintainer of elm-format, I am interested in having the distributions directly support nix (approach #1). Also, the reason I made binwrap a reusable library instead of just packaging elm-format manually was so that any improvements could be easily shared with anyone wanting to package an app.

Anyway, to summarize, I can’t speak for other maintainers, but I’m interested in improving elm-format and binwrap toward approach #1. (And my hope is that any improvements to binwrap will make it easy for other maintainers to benefit form those improvements.)

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @turboMaCk Marek Fajkus on Tue, 14 May 2019 19:18:34 GMT

I think we can try to go remote install friendly derivation > NUR > nixpkgs if possible. Of course over course of some time with respect to those upstreams.

I was just thinking about setting up Cachix. Seem that builds are reasonably fast but I just merged optional builds of elmi-to-json from the source. So steps I have in mind now are:

  • test it in the wild
  • compile Haskell by default and use Cachix
  • NUR
  • nixpkgs

Feel free to open any PR / issue or make any suggestion what to do with it. What I would love to see is with this becoming base of community controlled solution in the future as with things like this it’s always nice to share fixes and improvements. I really believe elm dev experience on NixOS can be much much better out of the box without that much work. All it takes is a little bit and all the folks adopting nix after won’t need to spend hours solving issues.

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @brian Brian on Tue, 14 May 2019 18:38:40 GMT

oh yeah, and if you’d like help setting up a Cachix cache for this let me know!

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @brian Brian on Tue, 14 May 2019 18:28:13 GMT

this is great, thanks for setting it up! I’ve felt the pain of not having elm-test a bunch lately… node2nix is not a super fun tool to use!

I wonder if you would consider making this into a NUR package? Then anyone with the NUR channel configured can do like nix-env -iA nur.repos.ruboMaCk.elm-test!

Elm tooling for Nix and NixOS users

via Elm Discourse - Latest posts by @turboMaCk Marek Fajkus on Tue, 14 May 2019 15:51:26 GMT

Hi folks.

Over time I’ve seen several issues related to getting some of the elm toolings run on NixOS or using Nix package manager.

I just want to let you know that I’ve made this repository with scripts to install some of the tools via nix. More detailed description can be found on GitHub.

Issues and PRs are welcome.

OAuth2 Refresh token and Http Request

via Elm Discourse - Latest posts by @turboMaCk Marek Fajkus on Tue, 14 May 2019 15:19:19 GMT

I think the short answer is that in case you want to persist new state like new token you need to do so via update function as there is no other way to update the model in tea.

The second question is how would you go about it. And answer to that is that there are different ways with different tradeoffs. I would personally suggest use something you’re familiar with. It can be anything on a scale from the most simple function String -> Model -> Model to state monad. Passing functions in Msgs or avoiding that.

 newer latest older