File: test_seeding.rb

package info (click to toggle)
ruby-faker 2.21.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,076 kB
  • sloc: ruby: 19,088; makefile: 6
file content (22 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

require_relative 'test_helper'

class TestSeeding < Test::Unit::TestCase
  def setup; end

  def test_deterministic
    Faker::Config.random = Random.new(5)
    first_random = Faker::Number.number(digits: 100_000)
    Faker::Config.random = Random.new(5)
    second_random = Faker::Number.number(digits: 100_000)
    Faker::Config.random = Random.new
    Faker::Config.random = nil
    third_random = Faker::Number.number(digits: 100_000)

    assert first_random == second_random
    # Tiny chance this will fail randomly if the unseeded Random just so
    # happen generates the same number as Random.new(5)
    assert first_random != third_random
  end
end