camper/test/percentage.sql

44 lines
850 B
MySQL
Raw Normal View History

-- Test percentage
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(10);
set search_path to camper, public;
select has_domain('percentage');
select domain_type_is('percentage', 'numeric');
select lives_ok($$ select 1.0::percentage $$);
select lives_ok($$ select 0.0::percentage $$);
select lives_ok($$ select 0.5::percentage $$);
select lives_ok($$ select 0.33::percentage $$);
select lives_ok($$ select 0.89::percentage $$);
select throws_ok(
$$ select 1.01::percentage $$,
23514, null,
'Maximum percentage is 100 %'
);
select throws_ok(
$$ select (-0.01)::percentage $$,
23514, null,
'Minimum percentage is 0 %'
);
select is(
0.001::percentage,
0.00::percentage,
'Percentage precission is 1 % (i.e., no decimals)'
);
select *
from finish();
rollback;