use Test::Fatal instead of Test::Exception
[gitmo/MooseX-Types-Common.git] / t / 02-numeric.t
CommitLineData
ac73ab52 1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
d52d9696 5use Test::More tests => 34;
3d272255 6use Test::Fatal;
ac73ab52 7
8{
9 package FooTest;
10 use Moose;
5b561c82 11 use MooseX::Types::Common::Numeric (
d52d9696 12 qw(PositiveNum PositiveOrZeroNum
13 PositiveInt PositiveOrZeroInt
14 NegativeNum NegativeOrZeroNum
15 NegativeInt NegativeOrZeroInt
16 SingleDigit)
ac73ab52 17 );
18
19 has digit => ( is => 'rw', isa => SingleDigit);
20 has posnum => ( is => 'rw', isa => PositiveNum);
21 has posint => ( is => 'rw', isa => PositiveInt);
22 has negnum => ( is => 'rw', isa => NegativeNum);
23 has negint => ( is => 'rw', isa => NegativeInt);
d52d9696 24 has posorzeronum => ( is => 'rw', isa => PositiveOrZeroNum);
25 has posorzeroint => ( is => 'rw', isa => PositiveOrZeroInt);
26 has negorzeronum => ( is => 'rw', isa => NegativeOrZeroNum);
27 has negorzeroint => ( is => 'rw', isa => NegativeOrZeroInt);
ac73ab52 28}
29
30my $ins = FooTest->new;
31
3d272255 32isnt(exception { $ins->digit(100); }, undef, 'SingleDigit');
33is(exception { $ins->digit(1); }, undef, 'SingleDigit 2');
ac73ab52 34
3d272255 35isnt(exception { $ins->posint(-100); }, undef, 'PositiveInt (-100)');
36isnt(exception { $ins->posint(0); }, undef, 'PositiveInt (0)');
37isnt(exception { $ins->posint(100.885); }, undef, 'PositiveInt (100.885)');
38is(exception { $ins->posint(100); }, undef, 'PositiveInt (100)');
39isnt(exception { $ins->posnum(0); }, undef, 'PositiveNum (0)');
40is(exception { $ins->posnum(100.885); }, undef, 'PositiveNum (100.885)');
41isnt(exception { $ins->posnum(-100.885); }, undef, 'PositiveNum (-100.885)');
42is(exception { $ins->posnum(0.0000000001); }, undef, 'PositiveNum (0.0000000001)');
ac73ab52 43
3d272255 44isnt(exception { $ins->posorzeroint(-100); }, undef, 'PositiveOrZeroInt (-100)');
45is(exception { $ins->posorzeroint(0); }, undef, 'PositiveOrZeroInt (0)');
46isnt(exception { $ins->posorzeroint(100.885); }, undef, 'PositiveOrZeroInt (100.885)');
47is(exception { $ins->posorzeroint(100); }, undef, 'PositiveOrZeroInt (100)');
48is(exception { $ins->posorzeronum(0); }, undef, 'PositiveOrZeroNum (0)');
49is(exception { $ins->posorzeronum(100.885); }, undef, 'PositiveOrZeroNum (100.885)');
50isnt(exception { $ins->posorzeronum(-100.885); }, undef, 'PositiveOrZeroNum (-100.885)');
51is(exception { $ins->posorzeronum(0.0000000001); }, undef, 'PositiveOrZeroNum (0.0000000001)');
d52d9696 52
3d272255 53isnt(exception { $ins->negint(100); }, undef, 'NegativeInt (100)');
54isnt(exception { $ins->negint(-100.885); }, undef, 'NegativeInt (-100.885)');
55is(exception { $ins->negint(-100); }, undef, 'NegativeInt (-100)');
56isnt(exception { $ins->negint(0); }, undef, 'NegativeInt (0)');
57is(exception { $ins->negnum(-100.885); }, undef, 'NegativeNum (-100.885)');
58isnt(exception { $ins->negnum(100.885); }, undef, 'NegativeNum (100.885)');
59isnt(exception { $ins->negnum(0); }, undef, 'NegativeNum (0)');
60is(exception { $ins->negnum(-0.0000000001); }, undef, 'NegativeNum (-0.0000000001)');
d52d9696 61
3d272255 62isnt(exception { $ins->negorzeroint(100); }, undef, 'NegativeOrZeroInt (100)');
63isnt(exception { $ins->negorzeroint(-100.885); }, undef, 'NegativeOrZeroInt (-100.885)');
64is(exception { $ins->negorzeroint(-100); }, undef, 'NegativeOrZeroInt (-100)');
65is(exception { $ins->negorzeroint(0); }, undef, 'NegativeOrZeroInt (0)');
66is(exception { $ins->negorzeronum(-100.885); }, undef, 'NegativeOrZeroNum (-100.885)');
67isnt(exception { $ins->negorzeronum(100.885); }, undef, 'NegativeOrZeroNum (100.885)');
68is(exception { $ins->negorzeronum(0); }, undef, 'NegativeOrZeroNum (0)');
69is(exception { $ins->negorzeronum(-0.0000000001); }, undef, 'NegativeOrZeroNum (-0.0000000001)');