What is the standard way to test a map structure


I’m trying to make an assertion that an item has recieved yet another timestamp in a list. My current solution is to do a regular match which will fail the test if not working. I obviously find out if my test does not work but it feels rather hacky and not a proper solution.

What I would like to do is something similar to:

assert [{id, [_t1, _t2]}] == updated_thing.list_with_timestamps

But that only works if I specify the _t1 and _t2 which obviously does not work with timestamps…

What is the standard way to test this?

This timestamp is what? A NaiveDateTime? A DateTime? A Date? A String? And you’re asserting strict equality, not only matching! Please, give a example structure


It is really hard to see what you are trying to do here.
Real code examples will help

I see. It was obviously much clearer in my head than for outsiders. They happen to be strings.

I also see that I could skip a lot of things and just give this question instead:

Given that I have a function random_string() that returns a random string of some sort. the variable list will in actual be constructed in some function that I want to test.

This assertion works if I know the exact outcome

list = ["two", "strings"]
assert ["two", "strings"] == list

but I cannot do this

list = [random_string(), random_string()]
assert [is_bitstring(x), is_bitstring(y)] == list

I can of cause do this

list = [random_string(), random_string()]
[a, b] = list
assert is_bitstring(a)
assert is_bitstring(b)

but it feels a bit clumsy

Simply summarized, can I assert the type of the items in the list without first match them out?

assert [<<_::binary>>,<<_:: binary>>] = value

If you know the results but order is nondeterministic, Enum.sort both sides.

1 Like