Skip to content

spec: test sort_remove_margin function #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions spec/sort_remove_margin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'
require "#{LKP_SRC}/lib/stats"

describe 'sort_remove_margin' do
# MARGIN_SHIFT = 5
arr = [*1..70]

context 'when an input array is empty' do
it 'returns an empty array' do
expect(sort_remove_margin([])).to eq([])
end
end

context 'when an input array is not empty and no max_margin is provided' do
it 'sorts the array and remove the margin from both ends' do
expect(sort_remove_margin(arr)).to eq([*3..68])
end
end

context 'when an input array is not empty and a max_margin is provided' do
it 'sorts the array and remove the margin (based on the min of calculated margin and max margin) from both ends' do
expect(sort_remove_margin(arr, 1)).to eq([*2..69])
end
end

context 'when an input array is not empty and margin value is too large' do
it 'returns an empty array' do
stub_const('MARGIN_SHIFT', 1)
expect(sort_remove_margin(arr)).to eq([])
end
end
end
Loading