File Coverage

blib/lib/App/Math/Tutor/Cmd/Roman/Cmd/Cast.pm
Criterion Covered Total %
statement 48 48 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 55 55 100.0


line stmt bran cond sub pod time code
1             package App::Math::Tutor::Cmd::Roman::Cmd::Cast;
2              
3 1     1   27330 use warnings;
  1         3  
  1         44  
4 1     1   6 use strict;
  1         2  
  1         45  
5              
6 1     1   6 use vars qw(@ISA $VERSION);
  1         2  
  1         80  
7              
8             =head1 NAME
9              
10             App::Math::Tutor::Cmd::Roman::Cmd::Cast - Plugin for casting of roman numerals into natural numbers and vice versa
11              
12             =cut
13              
14             our $VERSION = '0.004';
15              
16 1     1   6 use Moo;
  1         2  
  1         11  
17 1     1   438 use MooX::Cmd;
  1         2  
  1         13  
18 1     1   2309 use MooX::Options;
  1         2  
  1         10  
19              
20             has template_filename => (
21             is => "ro",
22             default => "twocols"
23             );
24              
25             with "App::Math::Tutor::Role::Roman", "App::Math::Tutor::Role::NaturalExercise";
26              
27             sub _build_exercises
28             {
29 1     1   38 my ($self) = @_;
30              
31 1         2 my (@tasks);
32 1         8 foreach my $i ( 1 .. $self->quantity )
33             {
34 15         15 my @line;
35 15         21 foreach my $j ( 0 .. 1 )
36             {
37 30         83 my ( $a, $b ) = $self->get_natural_number(2);
38 30         88 push @line, [ $a, $b ];
39             }
40 15         57 push @tasks, \@line;
41             }
42              
43 1         10 my $exercises = {
44             section => "Roman number cast from/to natural number",
45             caption => 'Roman Numerals Casting',
46             label => 'roman_number_cast',
47             header => [ [ 'Cast From Roman Number', 'Cast Into Roman Number' ] ],
48             solutions => [],
49             challenges => [],
50             };
51              
52 1         3 foreach my $line (@tasks)
53             {
54 15         15 my ( @solution, @challenge );
55              
56             # cast roman into natural number
57 15         20 my ($a) = @{ $line->[0] };
  15         26  
58 15         143 push @challenge, sprintf( '$ %s = $', $a );
59              
60 15         20 my @way; # remember Frank Sinatra :)
61 15         42 push @way, "" . $a;
62 15         39 push @way, int($a);
63 15         51 push( @solution, '$ ' . join( " = ", @way ) . ' $' );
64              
65             # cast natural number into roman
66 15         25 @way = ();
67 15         13 ($a) = @{ $line->[1] };
  15         34  
68 15         44 push @challenge, sprintf( '$ %d = $', $a );
69 15         36 push @way, int($a);
70 15         38 push @way, "" . $a;
71 15         39 push( @solution, '$ ' . join( " = ", @way ) . ' $' );
72              
73 15         16 push( @{ $exercises->{solutions} }, \@solution );
  15         36  
74 15         14 push( @{ $exercises->{challenges} }, \@challenge );
  15         48  
75             }
76              
77 1         38 return $exercises;
78             }
79              
80             =head1 LICENSE AND COPYRIGHT
81              
82             Copyright 2010-2014 Jens Rehsack.
83              
84             This program is free software; you can redistribute it and/or modify it
85             under the terms of either: the GNU General Public License as published
86             by the Free Software Foundation; or the Artistic License.
87              
88             See http://dev.perl.org/licenses/ for more information.
89              
90             =cut
91              
92             1;