2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'numeric'
|
|
|
|
|
|
|
|
describe Numeric do
|
2019-07-30 21:29:24 +00:00
|
|
|
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
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'rejects negative integers' do
|
|
|
|
expect { 2.floor_for_delta(-1) }.to raise_error(ArgumentError)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -25' do
|
|
|
|
expect(-25.floor_for_delta(25)).to eq -25
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -24.5' do
|
|
|
|
expect(-24.5.floor_for_delta(25)).to eq -25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
it 'handles on -1' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(-1.floor_for_delta(25)).to eq -25
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles on 0' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(0.floor_for_delta(25)).to eq 0
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on .5' do
|
|
|
|
expect(0.5.floor_for_delta(25)).to eq 0
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
it 'handles on 1' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(1.floor_for_delta(25)).to eq 0
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles on 25' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(25.floor_for_delta(25)).to eq 25
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on 25.5' do
|
|
|
|
expect(25.5.floor_for_delta(25)).to eq 25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#ceil_for_delta' do
|
|
|
|
it 'rejects non integers' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { 2.ceil_for_delta('test') }.to raise_error(ArgumentError)
|
|
|
|
expect { 2.ceil_for_delta(2.3) }.to raise_error(ArgumentError)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'rejects negative integers' do
|
|
|
|
expect { 2.ceil_for_delta(-1) }.to raise_error(ArgumentError)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -25.5' do
|
|
|
|
expect(-25.5.ceil_for_delta(25)).to eq -25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -25' do
|
|
|
|
expect(-25.ceil_for_delta(25)).to eq -25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -24.5' do
|
|
|
|
expect(-24.5.ceil_for_delta(25)).to eq 0
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on -1' do
|
|
|
|
expect(-1.ceil_for_delta(25)).to eq 0
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on 0' do
|
|
|
|
expect(0.ceil_for_delta(25)).to eq 0
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on .5' do
|
|
|
|
expect(0.5.ceil_for_delta(25)).to eq 25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on 1' do
|
|
|
|
expect(1.ceil_for_delta(25)).to eq 25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'handles on 25' do
|
|
|
|
expect(25.ceil_for_delta(25)).to eq 25
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles on 25.5' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(25.ceil_for_delta(25)).to eq 25
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|