ffaker 2.23.0 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +25 -3
- data/README.md +1 -1
- data/REFERENCE.md +907 -867
- data/ffaker.gemspec +1 -1
- data/lib/ffaker/address.rb +1 -1
- data/lib/ffaker/bank.rb +12 -0
- data/lib/ffaker/bank_us.rb +5 -1
- data/lib/ffaker/boolean.rb +4 -0
- data/lib/ffaker/data/job_tw/job_nouns +201 -0
- data/lib/ffaker/data/lorem_tw/words +789 -0
- data/lib/ffaker/guid.rb +7 -1
- data/lib/ffaker/identification_fi.rb +73 -0
- data/lib/ffaker/identification_mx.rb +1 -1
- data/lib/ffaker/job_tw.rb +12 -0
- data/lib/ffaker/lorem_tw.rb +40 -0
- data/lib/ffaker/name_pl.rb +2 -2
- data/lib/ffaker/tweet.rb +1 -1
- data/lib/ffaker/utils/module_utils.rb +7 -16
- data/lib/ffaker/uuid.rb +175 -0
- data/lib/ffaker/version.rb +1 -1
- data/lib/ffaker.rb +1 -0
- data/test/helper.rb +4 -4
- data/test/test_address_ua.rb +1 -1
- data/test/test_array_utils.rb +1 -1
- data/test/test_bank.rb +15 -1
- data/test/test_bank_us.rb +2 -0
- data/test/test_boolean.rb +32 -1
- data/test/test_date.rb +4 -4
- data/test/test_guid.rb +1 -1
- data/test/test_identification_fi.rb +39 -0
- data/test/test_job_tw.rb +21 -0
- data/test/test_lorem_br.rb +3 -3
- data/test/test_lorem_tw.rb +54 -0
- data/test/test_module_utils.rb +9 -0
- data/test/test_music.rb +4 -4
- data/test/test_number.rb +1 -1
- data/test/test_ssn_se.rb +1 -1
- data/test/test_uuid.rb +73 -0
- data/test/test_vehicle.rb +0 -1
- metadata +16 -9
data/lib/ffaker/guid.rb
CHANGED
@@ -5,8 +5,14 @@ module FFaker
|
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
8
|
+
# Because this method uses arbitrary hexadecimal characters it is likely to
|
9
|
+
# generate invalid UUIDs--UUIDs must have a version (1-8) at bits 48-51,
|
10
|
+
# and bits 64-65 must be 0b10.
|
11
|
+
#
|
12
|
+
# @deprecated Often generates invalid UUIDs. Use {UUID} instead.
|
8
13
|
def guid
|
9
|
-
|
14
|
+
warn '[guid] is deprecated. Use the UUID.uuidv4 method instead.'
|
15
|
+
FFaker::UUID.uuidv4.upcase
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module IdentificationFI
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
CHECK_DIGITS = '0123456789ABCDEFHJKLMNPRSTUVWXY'
|
9
|
+
# Number ranges in real use
|
10
|
+
POSSIBLY_REAL_FEMALE_INDIVIDUAL_NUMBERS = (2..898).step(2).to_a.freeze
|
11
|
+
POSSIBLY_REAL_MALE_INDIVIDUAL_NUMBERS = (3..899).step(2).to_a.freeze
|
12
|
+
# Number ranges not in real use
|
13
|
+
FAKE_FEMALE_INDIVIDUAL_NUMBERS = (900..998).step(2).to_a.freeze
|
14
|
+
FAKE_MALE_INDIVIDUAL_NUMBERS = (901..999).step(2).to_a.freeze
|
15
|
+
|
16
|
+
def identity_number(gender: FFaker::Gender.binary, birthday: FFaker::Date.birthday, fake: true)
|
17
|
+
day = fetch_formatted_day(birthday)
|
18
|
+
month = fetch_formatted_month(birthday)
|
19
|
+
year = fetch_formatted_year(birthday)
|
20
|
+
separator = fetch_separator(birthday)
|
21
|
+
individual_number = fetch_individual_number(gender, fake)
|
22
|
+
check_digit = calculate_check_digit(birthday, individual_number)
|
23
|
+
"#{day}#{month}#{year}#{separator}#{individual_number}#{check_digit}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fetch_formatted_day(birthday)
|
29
|
+
format('%.2d', birthday.day)
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_formatted_month(birthday)
|
33
|
+
format('%.2d', birthday.month)
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch_formatted_year(birthday)
|
37
|
+
check_birth_year(birthday.year)
|
38
|
+
birthday.strftime('%y')
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_separator(birthday)
|
42
|
+
case birthday.year
|
43
|
+
when ..1899
|
44
|
+
'+'
|
45
|
+
when 1900..1999
|
46
|
+
'-'
|
47
|
+
else
|
48
|
+
'A'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def fetch_individual_number(gender, fake)
|
53
|
+
numbers_range = if gender == 'female'
|
54
|
+
fake ? FAKE_FEMALE_INDIVIDUAL_NUMBERS : POSSIBLY_REAL_FEMALE_INDIVIDUAL_NUMBERS
|
55
|
+
else
|
56
|
+
fake ? FAKE_MALE_INDIVIDUAL_NUMBERS : POSSIBLY_REAL_MALE_INDIVIDUAL_NUMBERS
|
57
|
+
end
|
58
|
+
format('%.3d', fetch_sample(numbers_range))
|
59
|
+
end
|
60
|
+
|
61
|
+
def calculate_check_digit(birthday, individual_number)
|
62
|
+
digit = "#{birthday.day}#{fetch_formatted_month(birthday)}#{fetch_formatted_year(birthday)}#{individual_number}"
|
63
|
+
.to_i % 31
|
64
|
+
CHECK_DIGITS[digit]
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_birth_year(birth_year)
|
68
|
+
return if birth_year.between?(1799, 2100)
|
69
|
+
|
70
|
+
raise ArgumentError, "Birth year: #{birth_year} is not between supported 1799 and 2100 range"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -27,7 +27,7 @@ module FFaker
|
|
27
27
|
def rfc_persona_moral
|
28
28
|
consonants_n_amp = CONSONANTS + ['Ñ', '&']
|
29
29
|
all_letters = consonants_n_amp + VOWELS
|
30
|
-
[fetch_sample(all_letters, count: 3), date, fetch_sample(HOMOCLAVE, count: 3)].
|
30
|
+
[*fetch_sample(all_letters, count: 3), date, *fetch_sample(HOMOCLAVE, count: 3)].join
|
31
31
|
end
|
32
32
|
|
33
33
|
# http://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module LoremTW
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def word
|
9
|
+
fetch_sample(WORDS)
|
10
|
+
end
|
11
|
+
|
12
|
+
def words(num = 3)
|
13
|
+
fetch_sample(WORDS, count: num)
|
14
|
+
end
|
15
|
+
|
16
|
+
def sentence(word_count = 4)
|
17
|
+
s = words(word_count + rand(0..5))
|
18
|
+
s = s.join
|
19
|
+
"#{s},"
|
20
|
+
end
|
21
|
+
|
22
|
+
def sentences(sentence_count = 3)
|
23
|
+
s = (1..sentence_count).map { sentence }
|
24
|
+
def s.to_s
|
25
|
+
result = join(' ')
|
26
|
+
result[-1] = '。'
|
27
|
+
result
|
28
|
+
end
|
29
|
+
s
|
30
|
+
end
|
31
|
+
|
32
|
+
def paragraph(sentence_count = 3)
|
33
|
+
sentences(sentence_count + rand(0..2)).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def paragraphs(paragraph_count = 3)
|
37
|
+
(1..paragraph_count).map { paragraph }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/ffaker/name_pl.rb
CHANGED
@@ -90,9 +90,9 @@ module FFaker
|
|
90
90
|
|
91
91
|
def name_for_gender(name_type, gender) # :nodoc:
|
92
92
|
raise(ArgumentError, "Gender must be one of: #{GENDERS}") unless GENDERS.include?(gender)
|
93
|
-
return send("#{gender}_#{name_type}") unless gender == :random
|
93
|
+
return send(:"#{gender}_#{name_type}") unless gender == :random
|
94
94
|
|
95
|
-
fetch_sample([send("female_#{name_type}"), send("male_#{name_type}")])
|
95
|
+
fetch_sample([send(:"female_#{name_type}"), send(:"male_#{name_type}")])
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
data/lib/ffaker/tweet.rb
CHANGED
@@ -19,7 +19,7 @@ module FFaker
|
|
19
19
|
}.merge(args)
|
20
20
|
|
21
21
|
my_reply = options[:reply] ? "#{mention} " : ''
|
22
|
-
my_mentions =
|
22
|
+
my_mentions = options[:num_mentions].positive? ? "#{mentions(options[:num_mentions])} " : ''
|
23
23
|
my_tags = tags(options[:num_hashtags])
|
24
24
|
|
25
25
|
remaining = [
|
@@ -14,7 +14,7 @@ module FFaker
|
|
14
14
|
|
15
15
|
def const_missing(const_name)
|
16
16
|
if const_name.match?(/[a-z]/) # Not a constant, probably a class/module name.
|
17
|
-
super
|
17
|
+
super
|
18
18
|
else
|
19
19
|
mod_name = ancestors.first.to_s.split('::').last
|
20
20
|
data_path = "#{FFaker::BASE_LIB_PATH}/ffaker/data/#{underscore(mod_name)}/#{underscore(const_name.to_s)}"
|
@@ -38,21 +38,12 @@ module FFaker
|
|
38
38
|
|
39
39
|
# http://en.wikipedia.org/wiki/Luhn_algorithm
|
40
40
|
def luhn_check(number)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
sum = 0
|
48
|
-
multiplications.each do |num|
|
49
|
-
num.to_s.each_byte do |character|
|
50
|
-
sum += character.chr.to_i
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
control_digit = (sum % 10).zero? ? 0 : (((sum / 10) + 1) * 10) - sum
|
55
|
-
control_digit.to_s
|
41
|
+
sum = number.chars
|
42
|
+
.map(&:to_i)
|
43
|
+
.reverse
|
44
|
+
.each_with_index
|
45
|
+
.sum { |digit, index| index.even? ? (2 * digit).digits.sum : digit }
|
46
|
+
((10 - (sum % 10)) % 10).to_s
|
56
47
|
end
|
57
48
|
end
|
58
49
|
end
|
data/lib/ffaker/uuid.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module FFaker
|
6
|
+
# UUIDs are a 128-bit value (16 bytes), often represented as a
|
7
|
+
# 32-character hexadecimal string in the format
|
8
|
+
# `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
|
9
|
+
#
|
10
|
+
# @note This generates lowercase strings, but UUIDs are case-insensitive.
|
11
|
+
#
|
12
|
+
# @see https://www.rfc-editor.org/rfc/rfc4122#section-4
|
13
|
+
# @see https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/
|
14
|
+
module UUID
|
15
|
+
extend ModuleUtils
|
16
|
+
extend self
|
17
|
+
|
18
|
+
# > UUID version 4 is meant for generating UUIDs from truly-random or
|
19
|
+
# > pseudo-random numbers.
|
20
|
+
def uuidv4
|
21
|
+
uuid = 0
|
22
|
+
# random_a
|
23
|
+
# > The first 48 bits of the layout that can be filled with random data
|
24
|
+
# > as specified in Section 6.9. Occupies bits 0 through 47 (octets 0-5).
|
25
|
+
uuid |= rand((2**48) - 1) << 80
|
26
|
+
# ver
|
27
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0100 (4).
|
28
|
+
# > Occupies bits 48 through 51 of octet 6.
|
29
|
+
uuid |= 0b0100 << 76
|
30
|
+
# random_b
|
31
|
+
# > 12 more bits of the layout that can be filled random data as per
|
32
|
+
# > Section 6.9. Occupies bits 52 through 63 (octets 6-7).
|
33
|
+
uuid |= rand((2**12) - 1) << 64
|
34
|
+
# var
|
35
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
36
|
+
# > Occupies bits 64 and 65 of octet 8.
|
37
|
+
uuid |= 0b10 << 62
|
38
|
+
# random_c
|
39
|
+
# > The final 62 bits of the layout immediately following the var field
|
40
|
+
# > field to be filled with random data as per Section 6.9. Occupies bits
|
41
|
+
# > 66 through 127 (octets 8-15).
|
42
|
+
uuid |= rand((2**62) - 1)
|
43
|
+
|
44
|
+
as_string(uuid)
|
45
|
+
end
|
46
|
+
|
47
|
+
# > UUID version 6 is a field-compatible version of UUIDv1 Section 5.1,
|
48
|
+
# > reordered for improved DB locality. It is expected that UUIDv6 will
|
49
|
+
# > primarily be used in contexts where UUIDv1 is used. Systems that do not
|
50
|
+
# > involve legacy UUIDv1 SHOULD use UUIDv7 instead.
|
51
|
+
def uuidv6
|
52
|
+
timestamp = rand((2**60) - 1)
|
53
|
+
|
54
|
+
uuid = 0
|
55
|
+
# time_high
|
56
|
+
# > The most significant 32 bits of the 60 bit starting timestamp.
|
57
|
+
# > Occupies bits 0 through 31 (octets 0-3).
|
58
|
+
# @note Shifts 28 bits to remove `time_mid` and `time_low`.
|
59
|
+
uuid |= (timestamp >> 28) << 96
|
60
|
+
# time_mid
|
61
|
+
# > The middle 16 bits of the 60 bit starting timestamp. Occupies bits 32
|
62
|
+
# > through 47 (octets 4-5).
|
63
|
+
# @note Shifts 12 bits to remove `time_low`.
|
64
|
+
uuid |= ((timestamp >> 12) & ((2**16) - 1)) << 80
|
65
|
+
# ver
|
66
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0110 (6).
|
67
|
+
# > Occupies bits 48 through 51 of octet 6.
|
68
|
+
uuid |= 0b0110 << 76
|
69
|
+
# time_low
|
70
|
+
# > 12 bits that will contain the least significant 12 bits from the 60
|
71
|
+
# > bit starting timestamp. Occupies bits 52 through 63 (octets 6-7).
|
72
|
+
uuid |= (timestamp & ((2**12) - 1)) << 64
|
73
|
+
# var
|
74
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
75
|
+
# > Occupies bits 64 and 65 of octet 8.
|
76
|
+
uuid |= 0b10 << 62
|
77
|
+
# clk_seq
|
78
|
+
# > The 14 bits containing the clock sequence. Occupies bits 66 through
|
79
|
+
# > 79 (octets 8-9).
|
80
|
+
#
|
81
|
+
# (earlier in the document)
|
82
|
+
# > The clock sequence and node bits SHOULD be reset to a pseudo-random
|
83
|
+
# > value for each new UUIDv6 generated; however, implementations MAY
|
84
|
+
# > choose to retain the old clock sequence and MAC address behavior from
|
85
|
+
# > Section 5.1.
|
86
|
+
uuid |= rand((2**14) - 1) << 48
|
87
|
+
# node
|
88
|
+
# > 48 bit spatially unique identifier. Occupies bits 80 through 127
|
89
|
+
# > (octets 10-15).
|
90
|
+
uuid |= rand((2**48) - 1)
|
91
|
+
|
92
|
+
as_string(uuid)
|
93
|
+
end
|
94
|
+
|
95
|
+
# > UUID version 7 features a time-ordered value field derived from the
|
96
|
+
# > widely implemented and well known Unix Epoch timestamp source, the
|
97
|
+
# > number of milliseconds since midnight 1 Jan 1970 UTC, leap seconds
|
98
|
+
# > excluded. UUIDv7 generally has improved entropy characteristics over
|
99
|
+
# > UUIDv1 Section 5.1 or UUIDv6 Section 5.6.
|
100
|
+
def uuidv7
|
101
|
+
timestamp = rand((2**48) - 1)
|
102
|
+
|
103
|
+
uuid = 0
|
104
|
+
# unix_ts_ms
|
105
|
+
# > 48 bit big-endian unsigned number of Unix epoch timestamp in
|
106
|
+
# > milliseconds as per Section 6.1. Occupies bits 0 through 47 (octets
|
107
|
+
# > 0-5).
|
108
|
+
uuid |= timestamp << 80
|
109
|
+
# ver
|
110
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0111 (7).
|
111
|
+
# > Occupies bits 48 through 51 of octet 6.
|
112
|
+
uuid |= 0b0111 << 76
|
113
|
+
# rand_a
|
114
|
+
# > 12 bits pseudo-random data to provide uniqueness as per Section 6.9
|
115
|
+
# > and/or optional constructs to guarantee additional monotonicity as
|
116
|
+
# > per Section 6.2. Occupies bits 52 through 63 (octets 6-7).
|
117
|
+
uuid |= rand((2**12) - 1) << 64
|
118
|
+
# var
|
119
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
120
|
+
# > Occupies bits 64 and 65 of octet 8.
|
121
|
+
uuid |= 0b10 << 62
|
122
|
+
# rand_b
|
123
|
+
# > The final 62 bits of pseudo-random data to provide uniqueness as per
|
124
|
+
# > Section 6.9 and/or an optional counter to guarantee additional
|
125
|
+
# > monotonicity as per Section 6.2. Occupies bits 66 through 127 (octets
|
126
|
+
# > 8-15).
|
127
|
+
uuid |= rand((2**62) - 1)
|
128
|
+
|
129
|
+
as_string(uuid)
|
130
|
+
end
|
131
|
+
|
132
|
+
# > UUID version 8 provides an RFC-compatible format for experimental or
|
133
|
+
# > vendor-specific use cases. The only requirement is that the variant and
|
134
|
+
# > version bits MUST be set as defined in Section 4.1 and Section 4.2.
|
135
|
+
# > UUIDv8's uniqueness will be implementation-specific and MUST NOT be
|
136
|
+
# > assumed.
|
137
|
+
# >
|
138
|
+
# > [...] To be clear: UUIDv8 is not a replacement for UUIDv4 Section 5.4
|
139
|
+
# > where all 122 extra bits are filled with random data.
|
140
|
+
def uuidv8
|
141
|
+
uuid = 0
|
142
|
+
# custom_a
|
143
|
+
# > The first 48 bits of the layout that can be filled as an
|
144
|
+
# > implementation sees fit. Occupies bits 0 through 47 (octets 0-5).
|
145
|
+
uuid |= rand((2**48) - 1) << 80
|
146
|
+
# ver
|
147
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b1000 (8).
|
148
|
+
# > Occupies bits 48 through 51 of octet 6.
|
149
|
+
uuid |= 0b1000 << 76
|
150
|
+
# custom_b
|
151
|
+
# > 12 more bits of the layout that can be filled as an implementation
|
152
|
+
# > sees fit. Occupies bits 52 through 63 (octets 6-7).
|
153
|
+
uuid |= rand((2**12) - 1) << 64
|
154
|
+
# var
|
155
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
156
|
+
# > Occupies bits 64 and 65 of octet 8.
|
157
|
+
uuid |= 0b10 << 62
|
158
|
+
# custom_c
|
159
|
+
# > The final 62 bits of the layout immediately following the var field
|
160
|
+
# > to be filled as an implementation sees fit. Occupies bits 66 through
|
161
|
+
# > 127 (octets 8-15).
|
162
|
+
uuid |= rand((2**62) - 1)
|
163
|
+
|
164
|
+
as_string(uuid)
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def as_string(uuid)
|
170
|
+
uuid.to_s(16)
|
171
|
+
.rjust(32, '0')
|
172
|
+
.gsub(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '\1-\2-\3-\4-\5')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
data/lib/ffaker/version.rb
CHANGED
data/lib/ffaker.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -35,7 +35,7 @@ module DeterministicHelper
|
|
35
35
|
end
|
36
36
|
operator_name += '_or_equal_to' if operator[1] == '='
|
37
37
|
|
38
|
-
define_method "assert_#{operator_name}" do |got, expected|
|
38
|
+
define_method :"assert_#{operator_name}" do |got, expected|
|
39
39
|
assert(
|
40
40
|
got.public_send(operator, expected),
|
41
41
|
"Expected #{operator} \"#{expected}\", but got #{got}"
|
@@ -56,8 +56,8 @@ module DeterministicHelper
|
|
56
56
|
end
|
57
57
|
|
58
58
|
%w[less_than_or_equal_to between].each do |method_name|
|
59
|
-
define_method "assert_random_#{method_name}" do |*args, &block|
|
60
|
-
assert_random(block) { send "assert_#{method_name}", block.call, *args }
|
59
|
+
define_method :"assert_random_#{method_name}" do |*args, &block|
|
60
|
+
assert_random(block) { send :"assert_#{method_name}", block.call, *args }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -76,7 +76,7 @@ module DeterministicHelper
|
|
76
76
|
# }
|
77
77
|
def assert_methods_are_deterministic(klass, *methods)
|
78
78
|
Array(methods).each do |meth|
|
79
|
-
define_method "test_#{meth}_is_deterministic" do
|
79
|
+
define_method :"test_#{meth}_is_deterministic" do
|
80
80
|
assert_deterministic(message: "Results from `#{klass}.#{meth}` are not repeatable") do
|
81
81
|
klass.send(meth)
|
82
82
|
end
|
data/test/test_address_ua.rb
CHANGED
data/test/test_array_utils.rb
CHANGED
@@ -89,7 +89,7 @@ class TestArrayUtils < Test::Unit::TestCase
|
|
89
89
|
|
90
90
|
private
|
91
91
|
|
92
|
-
#
|
92
|
+
# Suppress the deprecation warning that some methods output, so we get less
|
93
93
|
# noise in our test run.
|
94
94
|
def supress_warn_output
|
95
95
|
original_verbosity = $VERBOSE
|
data/test/test_bank.rb
CHANGED
@@ -7,7 +7,7 @@ class TestBank < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
assert_methods_are_deterministic(
|
9
9
|
FFaker::Bank,
|
10
|
-
:iban, :card_number, :card_expiry_date, :card_type
|
10
|
+
:iban, :card_number, :card_expiry_date, :card_type, :loan_interest_rate, :loan_term, :loan_amount
|
11
11
|
)
|
12
12
|
|
13
13
|
def setup
|
@@ -50,4 +50,18 @@ class TestBank < Test::Unit::TestCase
|
|
50
50
|
def test_card_type
|
51
51
|
assert_include @tester::CARD_TYPES, @tester.card_type
|
52
52
|
end
|
53
|
+
|
54
|
+
def test_loan_interest_rate
|
55
|
+
rate = FFaker::Bank.loan_interest_rate
|
56
|
+
assert(rate.to_f.between?(1.5, 15.0), "Rate #{rate} is out of bounds")
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_loan_term
|
60
|
+
assert_includes([12, 24, 36, 48, 60, 72, 84], FFaker::Bank.loan_term)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_loan_amount
|
64
|
+
amount = FFaker::Bank.loan_amount
|
65
|
+
assert(amount.between?(1_000, 100_000), "Amount #{amount} is out of bounds")
|
66
|
+
end
|
53
67
|
end
|
data/test/test_bank_us.rb
CHANGED
@@ -24,6 +24,8 @@ class TestBankUS < Test::Unit::TestCase
|
|
24
24
|
routing_number = @tester.routing_number
|
25
25
|
assert_match(/\A\d{9}\z/, routing_number)
|
26
26
|
|
27
|
+
assert_true(@tester::ROUTING_NUMBER_PREFIXES.include?(routing_number[0..1]))
|
28
|
+
|
27
29
|
checksum = (
|
28
30
|
(7 * (routing_number[0].to_i + routing_number[3].to_i + routing_number[6].to_i)) +
|
29
31
|
(3 * (routing_number[1].to_i + routing_number[4].to_i + routing_number[7].to_i)) +
|
data/test/test_boolean.rb
CHANGED
@@ -5,10 +5,41 @@ require_relative 'helper'
|
|
5
5
|
class TestBoolean < Test::Unit::TestCase
|
6
6
|
include DeterministicHelper
|
7
7
|
|
8
|
-
assert_methods_are_deterministic(FFaker::Boolean, :maybe)
|
8
|
+
assert_methods_are_deterministic(FFaker::Boolean, :maybe, :boolean)
|
9
9
|
|
10
10
|
def test_maybe
|
11
11
|
maybe = FFaker::Boolean.maybe
|
12
12
|
assert [true, false].include?(maybe)
|
13
13
|
end
|
14
|
+
|
15
|
+
def test_boolean_with_default_ratio
|
16
|
+
true_count = 0
|
17
|
+
1000.times do
|
18
|
+
true_count += 1 if FFaker::Boolean.boolean
|
19
|
+
end
|
20
|
+
assert_in_delta 0.5, true_count / 1000.0, 0.1
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_boolean_with_true_ratio
|
24
|
+
true_ratio = 0.8
|
25
|
+
true_count = 0
|
26
|
+
1000.times do
|
27
|
+
true_count += 1 if FFaker::Boolean.boolean(true_ratio: true_ratio)
|
28
|
+
end
|
29
|
+
assert_in_delta true_ratio, true_count / 1000.0, 0.1
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_boolean_with_true_ratio_zero
|
33
|
+
true_ratio = 0
|
34
|
+
100.times do
|
35
|
+
assert_equal false, FFaker::Boolean.boolean(true_ratio: true_ratio)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_boolean_with_true_ratio_one
|
40
|
+
true_ratio = 1
|
41
|
+
100.times do
|
42
|
+
assert_equal true, FFaker::Boolean.boolean(true_ratio: true_ratio)
|
43
|
+
end
|
44
|
+
end
|
14
45
|
end
|
data/test/test_date.rb
CHANGED
@@ -22,16 +22,16 @@ class TestFakerDate < Test::Unit::TestCase
|
|
22
22
|
def test_backward
|
23
23
|
today = Date.today
|
24
24
|
|
25
|
-
assert_random_between(today - 365..today - 1) { @tester.backward }
|
26
|
-
assert_random_between(today - 30..today - 1) { @tester.backward(30) }
|
25
|
+
assert_random_between((today - 365)..(today - 1)) { @tester.backward }
|
26
|
+
assert_random_between((today - 30)..(today - 1)) { @tester.backward(30) }
|
27
27
|
assert_instance_of Date, @tester.backward
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_forward
|
31
31
|
today = Date.today
|
32
32
|
|
33
|
-
assert_random_between(today + 1..today + 365) { @tester.forward }
|
34
|
-
assert_random_between(today + 1..today + 30) { @tester.forward(30) }
|
33
|
+
assert_random_between((today + 1)..(today + 365)) { @tester.forward }
|
34
|
+
assert_random_between((today + 1)..(today + 30)) { @tester.forward(30) }
|
35
35
|
assert_instance_of Date, @tester.forward
|
36
36
|
end
|
37
37
|
|
data/test/test_guid.rb
CHANGED
@@ -8,7 +8,7 @@ class TestGuid < Test::Unit::TestCase
|
|
8
8
|
assert_methods_are_deterministic(FFaker::Guid, :guid)
|
9
9
|
|
10
10
|
def test_guid
|
11
|
-
assert_match(
|
11
|
+
assert_match(/\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/,
|
12
12
|
FFaker::Guid.guid)
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class TestFakerIdentificationFI < Test::Unit::TestCase
|
6
|
+
include DeterministicHelper
|
7
|
+
|
8
|
+
assert_methods_are_deterministic(
|
9
|
+
FFaker::IdentificationFI,
|
10
|
+
:identity_number
|
11
|
+
)
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@tester = FFaker::IdentificationFI
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_identity_number
|
18
|
+
general_regex = /^(0[1-9]|[1-2]\d|3[01])(0[1-9]|1[0-2])(\d\d)([-+A-FU-Y])(\d\d\d)([0-9A-FHJ-NPR-Y])$/
|
19
|
+
assert_match(general_regex, @tester.identity_number)
|
20
|
+
random_far_past_date = rand(Date.civil(1700)..Date.civil(1800))
|
21
|
+
assert_raises ArgumentError do
|
22
|
+
@tester.identity_number(birthday: random_far_past_date)
|
23
|
+
end
|
24
|
+
random_far_future_date = rand(Date.civil(2100)..Date.civil(2200))
|
25
|
+
assert_raises ArgumentError do
|
26
|
+
@tester.identity_number(birthday: random_far_future_date)
|
27
|
+
end
|
28
|
+
date_match_regex = /^010100A(\d\d\d)([0-9A-FHJ-NPR-Y])$/
|
29
|
+
assert_match(date_match_regex, @tester.identity_number(birthday: Date.civil(2000, 1, 1)))
|
30
|
+
fake_number_match_regex = /^(0[1-9]|[1-2]\d|3[01])(0[1-9]|1[0-2])(\d\d)([-+A-FU-Y])9(\d\d)([0-9A-FHJ-NPR-Y])$/
|
31
|
+
assert_match(fake_number_match_regex, @tester.identity_number(fake: true))
|
32
|
+
real_number_match_regex = /^(0[1-9]|[1-2]\d|3[01])(0[1-9]|1[0-2])(\d\d)([-+A-FU-Y])([0-8])(\d\d)([0-9A-FHJ-NPR-Y])$/
|
33
|
+
assert_match(real_number_match_regex, @tester.identity_number(fake: false))
|
34
|
+
female_match_regex = /^(0[1-9]|[1-2]\d|3[01])(0[1-9]|1[0-2])(\d\d)([-+A-FU-Y])(\d\d)([02468])([0-9A-FHJ-NPR-Y])$/
|
35
|
+
assert_match(female_match_regex, @tester.identity_number(gender: 'female'))
|
36
|
+
male_match_regex = /^(0[1-9]|[1-2]\d|3[01])(0[1-9]|1[0-2])(\d\d)([-+A-FU-Y])(\d\d)([13579])([0-9A-FHJ-NPR-Y])$/
|
37
|
+
assert_match(male_match_regex, @tester.identity_number(gender: 'male'))
|
38
|
+
end
|
39
|
+
end
|
data/test/test_job_tw.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class TestFakerJobTW < Test::Unit::TestCase
|
6
|
+
include DeterministicHelper
|
7
|
+
|
8
|
+
assert_methods_are_deterministic(FFaker::JobTW, :title)
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@tester = FFaker::JobTW
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_title
|
15
|
+
assert_greater_than_or_equal_to @tester.title.length, 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_nouns
|
19
|
+
assert_kind_of Array, @tester::JOB_NOUNS
|
20
|
+
end
|
21
|
+
end
|
data/test/test_lorem_br.rb
CHANGED
@@ -10,9 +10,9 @@ class TestLoremBR < Test::Unit::TestCase
|
|
10
10
|
:paragraph, :sentence, :phrase, :paragraphs, :sentences, :phrases, :words, :word, :characters
|
11
11
|
)
|
12
12
|
|
13
|
-
CHARACTERS = /\A[A-zÀ-ü0-9]+\z/i
|
14
|
-
WORD = /\A[A-zÀ-ü-]+\z/i
|
15
|
-
WORDS = /[ A-zÀ-ü\-.]+/i
|
13
|
+
CHARACTERS = /\A[A-Za-zÀ-ü0-9]+\z/i
|
14
|
+
WORD = /\A[A-Za-zÀ-ü-]+\z/i
|
15
|
+
WORDS = /[ A-Za-zÀ-ü\-.]+/i
|
16
16
|
|
17
17
|
def test_paragraph
|
18
18
|
assert_match(WORDS, FFaker::LoremBR.paragraph)
|