Kaweeda

Kaweeda

Streamdata: Unique generated data

Hi all, generating a property test and want to make sure that map_a and map_b are not equal, if they are then just pass :ok, and if not then assert.

Here is the code :

property "when a & b are arbitrary small json objects; patch(a, diff(a,b)) == b" do
    primitive = one_of([string(:printable), integer()])

    json_fragment_gen =
      tree(primitive, fn child_gen ->
        StreamData.one_of([
          # A JSON array
          list_of(child_gen),
          # A JSON object. Only supports string keys.
          map_of(string(:printable), child_gen)
        ])
      end)

    # Only valid top-level JSON are objects and arrays
    json_gen = json_fragment_gen |> filter(fn val -> is_map(val) end, 100)

    check all(
            map_a <- json_gen,
            map_b <- json_gen,

            max_runs: 100,
            initial_size: 1,
            max_generation_size: 50
          ) do

        
        assert map_b == js_patch(map_a, JsonDiffEx.diff(map_a, map_b))

So instead of checking before the assertion, is there a way to generate two unique maps that can never be equal to each other or if they are equal to each to just ignore it or pass :ok.

property "when a & b are arbitrary small json objects; patch(a, diff(a,b)) == b" do
    primitive = one_of([string(:printable), integer()])

    json_fragment_gen =
      tree(primitive, fn child_gen ->
        StreamData.one_of([
          # A JSON array
          list_of(child_gen),
          # A JSON object. Only supports string keys.
          map_of(string(:printable), child_gen)
        ])
      end)

    # Only valid top-level JSON are objects and arrays
    json_gen = json_fragment_gen |> filter(fn val -> is_map(val) end, 100)

    check all(
            map_a <- json_gen,
            map_b <- json_gen,

            max_runs: 100,
            initial_size: 1,
            max_generation_size: 50
          ) do

          if map_a == map_b do
            :ok
          else
            assert map_b == js_patch(map_a, JsonDiffEx.diff(map_a, map_b))

Any help would be appreciated, thanks in advance.

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

@Kaweeda check all takes a filter, you can

    check all(
            map_a <- json_gen,
            map_b <- json_gen,
            map_a != map_b,

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement