Class: JSON::Fuzz::Generator::Keyword::Maximum

Inherits:
Object
  • Object
show all
Defined in:
lib/json/fuzz/generator/keyword/maximum.rb

Class Method Summary collapse

Class Method Details

.invalid_params(attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/json/fuzz/generator/keyword/maximum.rb', line 7

def invalid_params(attributes)
  maximum_value = attributes["maximum"]
  raise "No maximum keyword given: #{attributes}" unless maximum_value

  generated_params = []
  unit_value = (attributes.key?("type") && attributes["type"] == "integer") ? 1 : 0.1

  if attributes["exclusiveMaximum"]
    generated_params.push(maximum_value)
  else
    generated_params.push(maximum_value + unit_value)
  end

  return generated_params
end

.valid_param(attributes) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/json/fuzz/generator/keyword/maximum.rb', line 23

def valid_param(attributes)
  maximum_value = attributes["maximum"]
  raise "No maximum keyword given: #{attributes}" unless maximum_value

  unit_value = (attributes.key?("type") && attributes["type"] == "integer") ? 1 : 0.1
  maximum_value -= unit_value if attributes["exclusiveMaximum"]

  if minimum_value = attributes["minimum"]
    minimum_value += unit_value if attributes["exclusiveMinimum"]
    if attributes["exclusiveMaximum"]
      return Random.rand(minimum_value...maximum_value)
    else
      return Random.rand(minimum_value..maximum_value)
    end
  else
    return maximum_value
  end
end