File Coverage

blib/lib/App/Math/Tutor/Cmd/Unit/Cmd/Compare.pm
Criterion Covered Total %
statement 56 56 100.0
branch 5 6 83.3
condition n/a
subroutine 11 11 100.0
pod n/a
total 72 73 98.6


line stmt bran cond sub pod time code
1             package App::Math::Tutor::Cmd::Unit::Cmd::Compare;
2              
3 1     1   41559 use warnings;
  1         3  
  1         40  
4 1     1   8 use strict;
  1         3  
  1         49  
5              
6 1     1   7 use vars qw(@ISA $VERSION);
  1         2  
  1         87  
7              
8             =head1 NAME
9              
10             App::Math::Tutor::Cmd::Unit::Cmd::Compare - Plugin for comparing numbers with units
11              
12             =cut
13              
14             our $VERSION = '0.004';
15              
16 1     1   6 use Moo;
  1         3  
  1         10  
17 1     1   387 use MooX::Cmd;
  1         4  
  1         10  
18 1     1   2082 use MooX::Options;
  1         2  
  1         9  
19              
20 1     1   1459 use Carp qw(croak);
  1         2  
  1         64  
21 1     1   5 use File::ShareDir ();
  1         2  
  1         15  
22 1     1   5 use Template ();
  1         2  
  1         19  
23 1     1   6 use Scalar::Util qw(looks_like_number);
  1         1  
  1         487  
24              
25             has template_filename => (
26             is => "ro",
27             default => "twocols"
28             );
29              
30             with "App::Math::Tutor::Role::UnitExercise";
31              
32             sub _build_exercises
33             {
34 1     1   30 my ($self) = @_;
35              
36 1         2 my (@tasks);
37              
38 1         6 foreach my $i ( 1 .. $self->quantity )
39             {
40 15         14 my @line;
41 15         26 foreach my $j ( 0 .. 1 )
42             {
43 30         79 my ( $a, $b ) = $self->get_unit_numbers(2);
44 30         87 push @line, [ $a, $b ];
45             }
46 15         42 push @tasks, \@line;
47             }
48              
49 1         17 my $exercises = {
50             section => "Unit comparison",
51             caption => 'Units',
52             label => 'unit_comparison',
53             header => [ [ 'Unit Comparison', 'Unit Comparison' ] ],
54             solutions => [],
55             challenges => [],
56             };
57              
58 1         3 foreach my $line (@tasks)
59             {
60 15         15 my ( @solution, @challenge );
61              
62 15         21 foreach my $i ( 0 .. 1 )
63             {
64 30         29 my ( $a, $b ) = @{ $line->[$i] };
  30         55  
65 30         167 push( @challenge, "\$ $a \\underbracket[0.5pt]{\\texttt{ }}\\text{ } $b \$" );
66              
67 30         41 my @way; # remember Frank Sinatra :)
68 30         67 my $op = $a <=> $b;
69 30 100       87 $op < 0 and push( @way, "$a < $b" );
70 30 100       82 $op > 0 and push( @way, "$a > $b" );
71 30 50       55 $op == 0 and push( @way, "$a = $b" );
72              
73 30         140 push( @solution, '$ ' . join( " = ", @way ) . ' $' );
74             }
75              
76 15         19 push( @{ $exercises->{solutions} }, \@solution );
  15         30  
77 15         16 push( @{ $exercises->{challenges} }, \@challenge );
  15         33  
78             }
79              
80 1         334 return $exercises;
81             }
82              
83             =head1 LICENSE AND COPYRIGHT
84              
85             Copyright 2010-2014 Jens Rehsack.
86              
87             This program is free software; you can redistribute it and/or modify it
88             under the terms of either: the GNU General Public License as published
89             by the Free Software Foundation; or the Artistic License.
90              
91             See http://dev.perl.org/licenses/ for more information.
92              
93             =cut
94              
95             1;