File: test_name_mx.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (190 lines) | stat: -rw-r--r-- 5,901 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# frozen_string_literal: true

require_relative 'helper'

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

  assert_methods_are_deterministic(
    FFaker::NameMX,
    :last_name, :first_name, :middle_name, :name, :male_prefix, :female_prefix,
    :prefix, :male_name, :female_name, :full_name, :full_name_no_prefix,
    :full_name_prefix
  )

  def setup
    @tester = FFaker::NameMX
    @all_names = @tester::MALE_FIRST_NAMES + @tester::FEMALE_FIRST_NAMES
  end

  def test_last_name
    assert_include @tester::LAST_NAMES, @tester.last_name
  end

  def test_first_name
    assert_include @all_names, @tester.first_name
  end

  def test_middle_name
    assert_include @all_names, @tester.middle_name
  end

  def test_name
    assert_include @all_names, @tester.name
  end

  def test_prefix_male
    assert_include @tester::MALE_PREFIXES, @tester.male_prefix
  end

  def test_prefix_female
    assert_include @tester::FEMALE_PREFIXES, @tester.female_prefix
  end

  def test_prefix
    assert_include @tester::PREFIXES, @tester.prefix
  end

  def test_male_name
    parts = @tester.male_name.split(' ')
    case parts.count
    when 1
      assert_include @tester::MALE_FIRST_NAMES, parts[0]
    when 2
      assert_include @tester::MALE_FIRST_NAMES, parts[0]
      assert_include @tester::MALE_FIRST_NAMES, parts[1]
    end
  end

  def test_female_name
    parts = @tester.female_name.split(' ')
    case parts.count
    when 1
      assert_include @tester::FEMALE_FIRST_NAMES, parts[0]
    when 2
      assert_include @tester::FEMALE_FIRST_NAMES, parts[0]
      assert_include @tester::FEMALE_FIRST_NAMES, parts[1]
    end
  end

  def test_full_name_male
    parts = @tester.full_name(:male).split(' ')
    case parts.count
    when 5
      assert_include @tester::MALE_PREFIXES, parts[0]
      assert_include @tester::MALE_FIRST_NAMES, parts[1]
      # Middle name
      assert_include @tester::MALE_FIRST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
      assert_include @tester::LAST_NAMES, parts[4]
    when 4
      prefix_or_first_name = @tester::MALE_PREFIXES.include?(parts[0]) ||
                             @tester::MALE_FIRST_NAMES.include?(parts[0])
      assert prefix_or_first_name
      assert_include @tester::MALE_FIRST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
    when 3
      assert_include @tester::MALE_FIRST_NAMES, parts[0]
      assert_include @tester::LAST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
    else
      flunk 'Invalid Male Name'
    end
  end

  def test_full_name_female
    parts = @tester.full_name(:female).split(' ')
    case parts.count
    when 5
      assert_include @tester::FEMALE_PREFIXES, parts[0]
      assert_include @tester::FEMALE_FIRST_NAMES, parts[1]
      # Middle name
      assert_include @tester::FEMALE_FIRST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
      assert_include @tester::LAST_NAMES, parts[4]
    when 4
      prefix_or_first_name = @tester::FEMALE_PREFIXES.include?(parts[0]) ||
                             @tester::FEMALE_FIRST_NAMES.include?(parts[0])
      assert prefix_or_first_name
      assert_include @tester::FEMALE_FIRST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
    when 3
      assert_include @tester::FEMALE_FIRST_NAMES, parts[0]
      assert_include @tester::LAST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
    else
      flunk 'Invalid Female Name'
    end
  end

  def test_full_name
    parts = @tester.full_name.split(' ')
    case parts.count
    when 5
      assert_include @tester::PREFIXES, parts[0]
      assert_include @all_names, parts[1]
      # Middle name
      assert_include @all_names, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
      assert_include @tester::LAST_NAMES, parts[4]
    when 4
      prefix_or_first_name = @tester::PREFIXES.include?(parts[0]) ||
                             @all_names.include?(parts[0])
      assert prefix_or_first_name
      assert_include @all_names, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
    when 3
      assert_include @all_names, parts[0]
      assert_include @tester::LAST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
    else
      flunk 'Invalid Name'
    end
  end

  def test_full_name_no_prefix
    parts = @tester.full_name_no_prefix.split(' ')
    case parts.count
    when 4
      assert_include @all_names, parts[0]
      assert_include @all_names, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
    when 3
      assert_include @all_names, parts[0]
      assert_include @tester::LAST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
    else
      flunk 'Invalid Name'
    end
  end

  def test_full_name_prefix
    parts = @tester.full_name_prefix.split(' ')
    case parts.count
    when 5
      assert_include @tester::PREFIXES, parts[0]
      assert_include @all_names, parts[1]
      # Middle name
      assert_include @all_names, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
      assert_include @tester::LAST_NAMES, parts[4]
    when 4
      prefix_or_first_name = @tester::PREFIXES.include?(parts[0]) ||
                             @all_names.include?(parts[0])
      assert prefix_or_first_name
      assert_include @all_names, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
      assert_include @tester::LAST_NAMES, parts[3]
    when 3
      assert_include @all_names, parts[0]
      assert_include @tester::LAST_NAMES, parts[1]
      assert_include @tester::LAST_NAMES, parts[2]
    else
      flunk 'Invalid Name'
    end
  end
end