Sha256: 6fc654e786413d9c4c9981a95a595842c8c92cfcfd9931ef794406d890555aaa

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require 'test_helper'

module Schemacop
  class ValidatorNumberTest < Minitest::Test
    def test_basic
      s = Schema.new do
        type :number
      end
      assert_nil s.validate!(-3)
      assert_nil s.validate!(-3.123)
      assert_nil s.validate!(0)
      assert_nil s.validate!(15)
      assert_nil s.validate!(15.13)
      assert_verr { s.validate!('0.12') }
    end

    def test_option_min
      s = Schema.new do
        type :number, min: -2
      end

      assert_nil s.validate!(-2)
      assert_nil s.validate!(-1.99999)
      assert_nil s.validate!(0)
      assert_nil s.validate!(1.2)
      assert_verr { s.validate!(-3) }
      assert_verr { s.validate!(-2.00001) }
    end

    def test_option_max
      s = Schema.new do
        type :number, max: 5.2
      end

      assert_nil s.validate!(-2)
      assert_nil s.validate!(-1.9)
      assert_nil s.validate!(0)
      assert_nil s.validate!(5.19999)
      assert_nil s.validate!(5.2)
      assert_verr { s.validate!(5.200001) }
      assert_verr { s.validate!(6) }
    end

    def test_options_min_max
      s = Schema.new do
        type :number, min: -2, max: 5.2
      end

      assert_nil s.validate!(-2)
      assert_nil s.validate!(-1.99999)
      assert_nil s.validate!(0)
      assert_nil s.validate!(1.2)
      assert_nil s.validate!(5.2)
      assert_verr { s.validate!(-3) }
      assert_verr { s.validate!(-2.00001) }
      assert_verr { s.validate!(5.200001) }
      assert_verr { s.validate!(6) }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
schemacop-2.3.2 test/validator_number_test.rb
schemacop-2.3.1 test/validator_number_test.rb
schemacop-2.3.0 test/validator_number_test.rb
schemacop-2.2.0 test/validator_number_test.rb
schemacop-2.1.0 test/validator_number_test.rb
schemacop-2.0.0 test/validator_number_test.rb