App-Math-Tutor
view release on metacpan or search on metacpan
lib/App/Math/Tutor/Cmd/Unit/Cmd/Cast.pm view on Meta::CPAN
package App::Math::Tutor::Cmd::Unit::Cmd::Cast;
use warnings;
use strict;
use vars qw(@ISA $VERSION);
=head1 NAME
App::Math::Tutor::Cmd::Unit::Cmd::Cast - Plugin for casting of numbers with units
=cut
our $VERSION = '0.005';
use Moo;
use MooX::Cmd;
use MooX::Options;
use Carp qw(croak);
use File::ShareDir ();
use Template ();
use Scalar::Util qw(looks_like_number);
has template_filename => (
is => "ro",
default => "twocols"
);
with "App::Math::Tutor::Role::UnitExercise", "App::Math::Tutor::Role::DecFracExercise";
sub _get_castable_numbers
{
my ( $self, $quantity ) = @_;
my @result;
while ( $quantity-- )
{
my ( $un, $base, $ut );
do
{
($un) = $self->get_unit_numbers( 1, $ut );
my $rng = $un->end - $un->begin;
$base = int( rand($rng) ) + $un->begin;
defined $ut or $ut = $un->type;
} while ( !$self->_check_decimal_fraction( $un->_numify($base) ) );
push @result,
[
$un,
Unit->new(
parts => [ $un->_numify($base) ],
begin => $base,
end => $base,
type => $un->type
)
];
}
@result;
}
sub _build_exercises
{
my ($self) = @_;
my (@tasks);
foreach my $i ( 1 .. $self->quantity )
{
my @line;
foreach my $j ( 0 .. 1 )
{
push @line, $self->_get_castable_numbers(1);
}
push @tasks, \@line;
}
my $exercises = {
section => "Unit casting",
caption => 'Units',
label => 'unit_castings',
header => [ [ 'Multiple entity => Single entity', 'Single entity => Multiple entity' ] ],
solutions => [],
( run in 2.211 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )