-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalues_helper.rb
55 lines (47 loc) · 1.55 KB
/
values_helper.rb
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
require_relative '../base_classes/base_class'
require_relative 'string_helper'
# Class to provide values for testing.
#
# Each method returns a hash of symbol/value pairs.
#
# Use hash.each_pair to loop through the hash.
#
# For each, construct a verdict using the value in the expected value,
# and the symbol in the verdict's message.
class ValuesHelper < BaseClass
include Contracts
Contract RangeOf[Integer] => HashOf[Symbol, Integer]
# Return hash of integers in range.
def self.integers_in_range(range)
{
:min => range.first,
:max => range.last,
}
end
Contract RangeOf[Integer] => HashOf[Symbol, Integer]
# Return hash of integers not in range.
def self.integers_not_in_range(range)
{
:too_small => range.first.pred,
:too_large => range.last.succ,
}
end
Contract Range, Maybe[String] => HashOf[Symbol, Maybe[String]]
# Return hash of strings in range.
def self.strings_in_length_range(range, base_string=nil)
{
:max_length => StringHelper.string_of_max_length(range, base_string),
:min_length => StringHelper.string_of_min_length(range, base_string),
}
end
Contract Range, Maybe[String] => HashOf[Symbol, Maybe[String]]
# Return hash of strings out of range.
def self.strings_not_in_length_range(range, base_string=nil)
values = {
:too_short => StringHelper.string_too_short(range, base_string),
:too_long => StringHelper.string_too_long(range, base_string),
}
values.delete(:too_short) unless values.fetch(:too_short)
values
end
end