File: test_boolean.rb

package info (click to toggle)
ruby-ffaker 2.25.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,852 kB
  • sloc: ruby: 13,136; makefile: 8; sh: 1
file content (45 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require_relative 'helper'

class TestBoolean < Test::Unit::TestCase
  include DeterministicHelper

  assert_methods_are_deterministic(FFaker::Boolean, :maybe, :boolean)

  def test_maybe
    maybe = FFaker::Boolean.maybe
    assert [true, false].include?(maybe)
  end

  def test_boolean_with_default_ratio
    true_count = 0
    1000.times do
      true_count += 1 if FFaker::Boolean.boolean
    end
    assert_in_delta 0.5, true_count / 1000.0, 0.1
  end

  def test_boolean_with_true_ratio
    true_ratio = 0.8
    true_count = 0
    1000.times do
      true_count += 1 if FFaker::Boolean.boolean(true_ratio: true_ratio)
    end
    assert_in_delta true_ratio, true_count / 1000.0, 0.1
  end

  def test_boolean_with_true_ratio_zero
    true_ratio = 0
    100.times do
      assert_equal false, FFaker::Boolean.boolean(true_ratio: true_ratio)
    end
  end

  def test_boolean_with_true_ratio_one
    true_ratio = 1
    100.times do
      assert_equal true, FFaker::Boolean.boolean(true_ratio: true_ratio)
    end
  end
end