From b683b3e2e870eb821aa7faf43de6a8f464458e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio?= <> Date: Wed, 13 Jul 2022 17:53:26 -0300 Subject: [PATCH] Add boolean --- CHANGELOG.md | 1 + lib/faker.ex | 14 ++++++++++++++ test/faker_test.exs | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 588b1cc9a..77ce6c6ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)] diff --git a/lib/faker.ex b/lib/faker.ex index 337a4ec11..fdf945c20 100644 --- a/lib/faker.ex +++ b/lib/faker.ex @@ -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 diff --git a/test/faker_test.exs b/test/faker_test.exs index 688d717ba..16c22a276 100644 --- a/test/faker_test.exs +++ b/test/faker_test.exs @@ -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