File Coverage

blib/lib/App/Math/Tutor/Cmd/Roman/Cmd/Add.pm
Criterion Covered Total %
statement 45 46 97.8
branch 7 8 87.5
condition 5 6 83.3
subroutine 7 8 87.5
pod n/a
total 64 68 94.1


line stmt bran cond sub pod time code
1             package App::Math::Tutor::Cmd::Roman::Cmd::Add;
2              
3 1     1   4986 use warnings;
  1         3  
  1         38  
4 1     1   6 use strict;
  1         3  
  1         37  
5              
6 1     1   5 use vars qw(@ISA $VERSION);
  1         3  
  1         77  
7              
8             =head1 NAME
9              
10             App::Math::Tutor::Cmd::Roman::Cmd::Add - Plugin for addition and subtraction of roman numbers
11              
12             =cut
13              
14             our $VERSION = '0.004';
15              
16 1     1   5 use Moo;
  1         2  
  1         8  
17 1     1   338 use MooX::Cmd;
  1         3  
  1         10  
18 1     1   1878 use MooX::Options;
  1         3  
  1         7  
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_command_names
28             {
29 0     0   0 return qw(add sub);
30             }
31              
32             sub _build_exercises
33             {
34 1     1   39 my ($self) = @_;
35              
36 1         3 my (@tasks);
37 1         7 foreach my $i ( 1 .. $self->quantity )
38             {
39 15         17 my @line;
40 15         26 foreach my $j ( 0 .. 1 )
41             {
42 30         83 REDO:
43             my ( $a, $b ) = $self->get_natural_number(2);
44 30 50 66     94 $j and $a == $b and goto REDO;
45 30         99 push @line, [ $a, $b ];
46             }
47 15         37 push @tasks, \@line;
48             }
49              
50 1         12 my $exercises = {
51             section => "Roman number addition / subtraction",
52             caption => 'Roman Numeral Addition / Subtraction',
53             label => 'roman_numeral_addition',
54             header => [ [ 'Roman Number Addition', 'Roman Number Subtraction' ] ],
55             solutions => [],
56             challenges => [],
57             };
58              
59 1         3 foreach my $line (@tasks)
60             {
61 15         19 my ( @solution, @challenge );
62              
63 15         24 foreach my $i ( 0 .. 1 )
64             {
65 30         33 my ( $a, $b ) = @{ $line->[$i] };
  30         59  
66 30 100       57 my $op = $i ? '-' : '+';
67 30 100 100     100 $op eq '-' and $a < $b and ( $b, $a ) = ( $a, $b );
68 30         101 push @challenge, sprintf( '$ %s %s %s = $', $a, $op, $b );
69              
70 30         48 my @way; # remember Frank Sinatra :)
71 30         82 push @way, sprintf( '%s %s %s', $a, $op, $b );
72 30 100       152 push @way,
73             RomanNum->new(
74             value => $op eq "+" ? $a->_numify + $b->_numify : $a->_numify - $b->_numify );
75              
76 30         428 push( @solution, '$ ' . join( " = ", @way ) . ' $' );
77             }
78              
79 15         24 push( @{ $exercises->{solutions} }, \@solution );
  15         37  
80 15         20 push( @{ $exercises->{challenges} }, \@challenge );
  15         39  
81             }
82              
83 1         39 return $exercises;
84             }
85              
86             =head1 LICENSE AND COPYRIGHT
87              
88             Copyright 2010-2014 Jens Rehsack.
89              
90             This program is free software; you can redistribute it and/or modify it
91             under the terms of either: the GNU General Public License as published
92             by the Free Software Foundation; or the Artistic License.
93              
94             See http://dev.perl.org/licenses/ for more information.
95              
96             =cut
97              
98             1;