PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Perl | 51 lines | 28 code | 16 blank | 7 comment | 2 complexity | 79451090e3deccdff2f7cd027d3e9830 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More tests => 9;
 4# member_pointer using pointers to member functions
 5
 6BEGIN { use_ok('member_pointer') }
 7require_ok('member_pointer');
 8
 9sub check($;$;$) {
10  my($what, $expected, $actual) = @_;
11  if ($expected != $actual) {
12    die ("Failed: $what Expected: $expected Actual: $actual");
13  }
14}
15
16# Get the pointers
17
18my $area_pt = member_pointer::areapt();
19my $perim_pt = member_pointer::perimeterpt();
20
21# Create some objects
22
23my $s = new member_pointer::Square(10);
24
25# Do some calculations
26
27is(100.0, member_pointer::do_op($s,$area_pt), "Square area");
28is(40.0, member_pointer::do_op($s,$perim_pt), "Square perim");
29no strict;
30
31my $memberPtr = $member_pointer::areavar;
32$memberPtr = $member_pointer::perimetervar;
33
34# Try the variables
35is(100.0, member_pointer::do_op($s,$member_pointer::areavar), "Square area");
36is(40.0, member_pointer::do_op($s,$member_pointer::perimetervar), "Square perim");
37
38# Modify one of the variables
39$member_pointer::areavar = $perim_pt;
40
41is(40.0, member_pointer::do_op($s,$member_pointer::areavar), "Square perimeter");
42
43# Try the constants
44
45$memberPtr = $member_pointer::AREAPT;
46$memberPtr = $member_pointer::PERIMPT;
47$memberPtr = $member_pointer::NULLPT;
48
49is(100.0, member_pointer::do_op($s,$member_pointer::AREAPT), "Square area");
50is(40.0, member_pointer::do_op($s,$member_pointer::PERIMPT), "Square perim");
51