houdini/spec/lib/numeric_spec.rb
Bradley M. Kuhn 6772312ea7 Relicense all .rb files under new project license.
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

with some specific files to be licensed under the one of two licenses:
   CC0-1.0
   LGPL-3.0-or-later

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

100 lines
2 KiB
Ruby

# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'
require 'numeric'
describe Numeric do
describe '#floor_for_delta' do
it 'rejects non integers' do
expect { 2.floor_for_delta("test")}.to raise_error(ArgumentError)
expect { 2.floor_for_delta(2.3)}.to raise_error(ArgumentError)
end
it 'rejects negative integers' do
expect { 2.floor_for_delta(-1)}.to raise_error(ArgumentError)
end
it 'handles on -25' do
expect(-25.floor_for_delta(25)).to eq -25
end
it 'handles on -24.5' do
expect(-24.5.floor_for_delta(25)).to eq -25
end
it 'handles on -1' do
expect(-1.floor_for_delta(25)).to eq -25
end
it 'handles on 0' do
expect(0.floor_for_delta(25)).to eq 0
end
it 'handles on .5' do
expect(0.5.floor_for_delta(25)).to eq 0
end
it 'handles on 1' do
expect(1.floor_for_delta(25)).to eq 0
end
it 'handles on 25' do
expect(25.floor_for_delta(25)).to eq 25
end
it 'handles on 25.5' do
expect(25.5.floor_for_delta(25)).to eq 25
end
end
describe '#ceil_for_delta' do
it 'rejects non integers' do
expect { 2.ceil_for_delta("test")}.to raise_error(ArgumentError)
expect { 2.ceil_for_delta(2.3)}.to raise_error(ArgumentError)
end
it 'rejects negative integers' do
expect { 2.ceil_for_delta(-1)}.to raise_error(ArgumentError)
end
it 'handles on -25.5' do
expect(-25.5.ceil_for_delta(25)).to eq -25
end
it 'handles on -25' do
expect(-25.ceil_for_delta(25)).to eq -25
end
it 'handles on -24.5' do
expect(-24.5.ceil_for_delta(25)).to eq 0
end
it 'handles on -1' do
expect(-1.ceil_for_delta(25)).to eq 0
end
it 'handles on 0' do
expect(0.ceil_for_delta(25)).to eq 0
end
it 'handles on .5' do
expect(0.5.ceil_for_delta(25)).to eq 25
end
it 'handles on 1' do
expect(1.ceil_for_delta(25)).to eq 25
end
it 'handles on 25' do
expect(25.ceil_for_delta(25)).to eq 25
end
it 'handles on 25.5' do
expect(25.ceil_for_delta(25)).to eq 25
end
end
end