Kaweeda
PropertyTesting : migrating from js diffing library to elixir diffing library and need help writing proptest
Trying to write a property based test to prove ‘js_lib.patch(json_a, elixir_lib.diff(json_a, json_b)) == json_b’
- a , b are maps and I need to check if the diff of (a,b) is equal to b.
First Post!
Qqwy
TypeCheck Core Team
I think something like this should probably be close to what you are looking for:
defmodule MyDiffingToolTest
use ExUnit, async: true
use ExUnitProperties
import StreamData
property "the Elixir tool works the same as the JS tool" do
check all map_a <- map_of(term(), term()),
map_b <- map_of(term(), term()) do
assert JsLib.diff(map_a, map_b) == ElixirLib.diff(map_a, map_b)
end
end
end
And then inside JsLib you’d have some Elixir code that invokes the JS tool from within Elixir.
You might need to change term() into something like one_of([integer(), boolean(), string(), nil]) to restrict the types to only have things that can be JSON-encoded.
Writing a generator that can generate deeply nested JSON objects/arrays is also possible, but takes a little more work. (C.f. StreamData.tree/2)
Popular in Questions
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
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
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New








