Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Add doc tests for util.ex (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion authored and zabirauf committed Dec 19, 2018
1 parent dd3ce7e commit 00f63c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ defmodule Multihash.Util do
* :sha1
* :sha2_256
* :sha2_512
## Examples
iex> Multihash.Util.sum("Hello", :sha1)
<<17, 20, 247, 255, 158, 139, 123, 178, 224, 155, 112, 147, 90, 93, 120, 94, 12, 197, 217, 208, 171, 240>>
iex> Multihash.Util.sum("Hello", :sha2_256)
<<18, 32, 24, 95, 141, 179, 34, 113, 254, 37, 245, 97, 166, 252, 147, 139, 46, 38, 67, 6, 236, 48, 78, 218, 81, 128, 7, 209, 118, 72, 38, 56, 25, 105>>
iex> Multihash.Util.sum("Hello", :sha2_512)
<<19, 64, 54, 21, 248, 12, 157, 41, 62, 215, 64, 38, 135, 249, 75, 34, 213, 142, 82, 155, 140, 199, 145, 111, 143, 172, 127, 221, 247, 251, 213, 175, 76, 247, 119, 211, 215, 149, 167, 160, 10, 22, 191, 126, 127, 63, 185, 86, 30, 233, 186, 174, 72, 13, 169, 254, 122, 24, 118, 158, 113, 136, 107, 3, 243, 21>>
"""
@spec sum(binary, Multihash.hash_type) :: binary
def sum(data, :sha1), do: :crypto.hash(:sha, data) |> create_multihash(:sha1)
Expand Down
5 changes: 5 additions & 0 deletions test/util_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Multihash.UtilTest do
use ExUnit.Case, async: true
doctest Multihash.Util

end

0 comments on commit 00f63c9

Please sign in to comment.