Eiji

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

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

Also Liked

OvermindDL1

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)? :slight_smile:

Where Next?

Popular in Questions Top

Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
qwerescape
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vac
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
dokuzbir
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
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
alice
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
lucidguppy
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
Brian
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 Top

9mm
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
siddhant3030
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
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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
johnnyicon
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
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
Brian
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
AstonJ
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement