Skip to content

Commit

Permalink
Add boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Aurélio committed Jul 13, 2022
1 parent 3796726 commit b683b3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format.

### Added
- `Faker.Fruits.En` - add english fruits [[@KevinDaSilvaS](https://github.com/KevinDaSilvaS)]
- `Faker.boolean/0` - add random boolean [@linomassarani](https://github.com/linomassarani)

### Changed
- `Faker.Commerce.PtBr` - add more products in product_name_product [[@igorgbr](https://github.com/igorgbr)]
Expand Down
14 changes: 14 additions & 0 deletions lib/faker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ defmodule Faker do
Application.get_env(:faker, :random_module).random_bytes(total)
end

@doc """
Returns a random boolean.
## Examples
iex> boolean()
true
iex> boolean()
false
"""
@spec boolean() :: boolean()
def boolean, do: Enum.random(0..1) == 0

defmacro localize(function) do
quote do
def unquote(function)() do
Expand Down
4 changes: 4 additions & 0 deletions test/faker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ defmodule FakerTest do
test :format do
assert Regex.match?(~r/\w{3}\d{4}@\w{4}\.\w{3}/, Faker.format("???####@????.???"))
end

test :boolean do
assert is_boolean(Faker.boolean())
end
end

0 comments on commit b683b3e

Please sign in to comment.