File tree Expand file tree Collapse file tree 3 files changed +15
-17
lines changed
Expand file tree Collapse file tree 3 files changed +15
-17
lines changed Original file line number Diff line number Diff line change 11# Faker::NationalHealthService
22
3- ``` ruby
4- Faker ::NationalHealthService .british_number # => "403 958 5577"
3+ The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999 for
4+ test purposes. For more details, see [ NHS Digital documentation about
5+ synthetic data] ( https://digital.nhs.uk/services/e-referral-service/document-library/synthetic-data-in-live-environments#synthetic-data-naming-convention ) .
56
6- # Keyword arguments: number
7- Faker ::NationalHealthService .check_digit( number: 400_012_114 ) # => 6
7+ ``` ruby
8+ Faker ::NationalHealthService .british_number # => "999 464 0232"
89```
Original file line number Diff line number Diff line change @@ -6,14 +6,17 @@ class << self
66 ##
77 # Produces a random British NHS number.
88 #
9+ # The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999
10+ # for test purposes.
11+ #
912 # @return [String]
1013 #
1114 # @example
12- # Faker::NationalHealthService.british_number #=> "403 958 5577 "
15+ # Faker::NationalHealthService.british_number #=> "999 464 0232 "
1316 #
1417 # @faker.version 1.9.2
1518 def british_number
16- base_number = rand ( 400_000_001 ...499_999_999 )
19+ base_number = rand ( 999_000_001 ...999_999_999 )
1720 # If the check digit is equivalent to 10, the number is invalid.
1821 # See https://en.wikipedia.org/wiki/NHS_number
1922 base_number -= 1 if check_digit ( number : base_number ) == 10
@@ -24,6 +27,8 @@ def british_number
2427 . join
2528 end
2629
30+ private
31+
2732 ##
2833 # Produces a random British NHS number's check digit.
2934 #
Original file line number Diff line number Diff line change @@ -8,20 +8,12 @@ def setup
88 end
99
1010 def test_nhs_british_number
11- assert_match ( /\A \d {3}\s \d {3}\s \d {4}\z / , @tester . british_number )
11+ assert_match ( /\A 9 {3}\s \d {3}\s \d {4}\z / , @tester . british_number )
1212 end
1313
1414 def test_check_digit_equals_10
15- Faker ::NationalHealthService . stub ( :rand , 458_617_434 ) do
16- assert_match ( '458 617 4331 ' , @tester . british_number )
15+ Faker ::NationalHealthService . stub ( :rand , 999_464_033 ) do
16+ assert_match ( '999 464 0321 ' , @tester . british_number )
1717 end
1818 end
19-
20- def test_check_digit
21- assert_equal 6 , @tester . check_digit ( number : 400_012_114 )
22- end
23-
24- def test_check_digit_11
25- assert_equal 0 , @tester . check_digit ( number : 418_513_625 )
26- end
2719end
You can’t perform that action at this time.
0 commit comments