Eiji
Inspecting numbers in iex and tests
I was think about numbers in console (iex) and tests. It’s hard to read bigger numbers.
Of course in tests we have colors for changes (thanks!), but its only for tests and only when comparing results by assert macro.
So here is my proposition:
Environment
- Elixir & Erlang versions (elixir -v):
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10]
Elixir 1.5.0-dev (40c55f3)
Erlang is from portage. Elixir is compiled from source.
- Operating system:
Funtoo Linux (Gentoo based) stable (stage1 setup) with latest updates.
Test code:
defmodule MyApp do
def number_a(), do: 100000
# ...
def number_b(), do: 1000000
end
defmodule MyAppTest do
use ExUnit.Case
doctest MyApp
import MyApp
test "numbers" do
assert number_a() == number_b()
end
end
Current behavior
iex(1)> num = 1_000_000
1000000
iex(2)> IO.puts num
1000000
:ok
iex(3)> IO.inspect num
1000000
1000000
mix test
1) test numbers (MyAppTest)
test/my_app_test.exs:9
Assertion with == failed
code: a == b
lhs: 1000000
rhs: 100000
stacktrace:
test/my_app_test.exs:9: (test)
Finished in 0.1 seconds
2 tests, 1 failure
Expected behavior
iex(1)> num = 1_000_000
1_000_000
iex(2)> IO.puts num
1_000_000
:ok
iex(3)> IO.inspect num
1_000_000
1_000_000
mix test
1) test numbers (MyAppTest)
test/my_app_test.exs:9
Assertion with == failed
code: a == b
lhs: 1_000_000
rhs: 100_000
stacktrace:
test/my_app_test.exs:9: (test)
Finished in 0.1 seconds
2 tests, 1 failure
What do you think about it?
Marked As Solved
wojtekmach
Hex Core Team
Pretty printing integers was considered as addition to Elixir but ultimately it didn’t get through. See this PR: https://github.com/elixir-lang/elixir/pull/4916
1
Also Liked
OvermindDL1
Adding underscores might be interesting, but I think Elixir 1.4 is adding red/removed and green/add part of comparisons. If it does not do it with numbers then it should with a PR (I think it does it to anything inspectable)? ![]()
1
Popular in Questions
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
Hello, how can I check the Phoenix version ?
Thanks !
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 I...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Other popular topics
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
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
Hello, how can I check the Phoenix version ?
Thanks !
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
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
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








