Sha256: 579cbe76e45e9aa76724e0749ecaaf3c4811528b36ce012a2466a074dc9004b8

Contents?: true

Size: 1.86 KB

Versions: 36

Compression:

Stored size: 1.86 KB

Contents

require 'test_helper'

module Schemacop
  module V2
    class ValidatorNumberTest < V2Test
      def test_basic
        s = Schema.new do
          type :number
        end
        assert_nothing_raised { s.validate!(-3) }
        assert_nothing_raised { s.validate!(-3.123) }
        assert_nothing_raised { s.validate!(0) }
        assert_nothing_raised { s.validate!(15) }
        assert_nothing_raised { 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_nothing_raised { s.validate!(-2) }
        assert_nothing_raised { s.validate!(-1.99999) }
        assert_nothing_raised { s.validate!(0) }
        assert_nothing_raised { 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_nothing_raised { s.validate!(-2) }
        assert_nothing_raised { s.validate!(-1.9) }
        assert_nothing_raised { s.validate!(0) }
        assert_nothing_raised { s.validate!(5.19999) }
        assert_nothing_raised { 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_nothing_raised { s.validate!(-2) }
        assert_nothing_raised { s.validate!(-1.99999) }
        assert_nothing_raised { s.validate!(0) }
        assert_nothing_raised { s.validate!(1.2) }
        assert_nothing_raised { 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
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
schemacop-3.0.29 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.28 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.27 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.26 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.25 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.24 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.23 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.22 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.21 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.20 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.19 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.18 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.17 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.16 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.15 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.14 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.13 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.12 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.11 test/unit/schemacop/v2/validator_number_test.rb
schemacop-3.0.10 test/unit/schemacop/v2/validator_number_test.rb