1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/bindings/ruby/spec/lib/kernaux/ntoa/utoa10_spec.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

2022-01-20 16:43:06 -05:00
# frozen_string_literal: true
require 'spec_helper'
2022-06-13 15:55:05 -04:00
KernAux::Version.with_ntoa? and RSpec.describe KernAux, '.utoa10' do
2022-06-07 15:41:05 -04:00
subject(:utoa10) { described_class.utoa10 number }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
let(:number) { rand 0..(2**64 - 1) }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
it { is_expected.to be_instance_of String }
it { is_expected.to be_frozen }
it { is_expected.to eq number.to_s }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
context 'when number is 0' do
let(:number) { 0 }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
it { is_expected.to eq '0' }
end
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
context 'when number is max uint64_t' do
let(:number) { 2**64 - 1 }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
it { is_expected.to eq number.to_s }
end
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
context 'when number is -1' do
let(:number) { -1 }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
specify do
expect { utoa10 }.to \
raise_error RangeError, 'can\'t convert negative number to uint64_t'
2022-01-20 16:43:06 -05:00
end
2022-06-07 15:41:05 -04:00
end
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
context 'when number is greater than max uint64_t' do
let(:number) { 2**64 }
2022-01-20 16:43:06 -05:00
2022-06-07 15:41:05 -04:00
specify do
expect { utoa10 }.to raise_error \
RangeError, 'bignum too big to convert into `unsigned long long\''
2022-01-20 16:43:06 -05:00
end
end
context 'when number is not numeric' do
let(:number) { rand(0..(2**64 - 1)).to_s }
specify do
expect { utoa10 }.to raise_error \
TypeError, 'no implicit conversion from string'
end
end
2022-01-20 16:43:06 -05:00
end