PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/perl5/virtual_poly_runme.pl

#
Perl | 36 lines | 19 code | 10 blank | 7 comment | 0 complexity | 4e7dbd1c5f8ec5a86440206c9bc1c210 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Test::More tests => 8;
  5. BEGIN { use_ok('virtual_poly') }
  6. require_ok('virtual_poly');
  7. my $d = virtual_poly::NDouble->new(3.5);
  8. my $i = virtual_poly::NInt->new(2);
  9. #
  10. # the copy methods return the right polymorphic types
  11. #
  12. my $dc = $d->copy();
  13. my $ic = $i->copy();
  14. is($d->get(), $dc->get());
  15. is($i->get(), $ic->get());
  16. virtual_poly::incr($ic);
  17. is($i->get() + 1, $ic->get());
  18. my $dr = $d->ref_this();
  19. is($d->get(), $dr->get());
  20. #
  21. # 'narrowing' also works
  22. #
  23. my $ddc = virtual_poly::NDouble::narrow($d->nnumber());
  24. is($d->get, $ddc->get());
  25. my $dic = virtual_poly::NInt::narrow($i->nnumber());
  26. is($i->get(), $dic->get());