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

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
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 ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
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
srinivasu
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
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
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

We're in Beta

About us Mission Statement