Ensuring the next character on learning finished is always a review one.

This commit is contained in:
sergiotarxz 2024-06-27 12:20:22 +02:00
parent cf9aaf3541
commit 54fc631fa8
2 changed files with 14 additions and 2 deletions

View File

@ -9,7 +9,7 @@ use Moo;
use Crypt::URandom qw( urandom );
sub get($min = 1, $max = 100) {
sub get($class, $min = 1, $max = 100) {
my $rng = urandom(4);
$rng = unpack 'L', $rng;
$rng = ($rng % $max) + $min;

View File

@ -5,7 +5,7 @@ use v5.38.2;
use strict;
use warnings;
use Test::Most tests => 2;
use Test::Most tests => 3;
use Test::MockModule;
use Path::Tiny;
@ -14,6 +14,7 @@ use File::Basename;
use lib dirname(dirname(__FILE__)).'/lib';
use JapaChar::DB;
use JapaChar::Random;
BEGIN {
use_ok 'JapaChar::Characters';
@ -24,5 +25,16 @@ BEGIN {
$mock_db->mock(_db_path => sub {
return path(__FILE__)->parent->child('all-learned-basic-characters.db');
});
my $mock_random = Test::MockModule->new('JapaChar::Random');
$mock_random->mock(get => sub {
return 100;
});
my $mock_characters = Test::MockModule->new('JapaChar::Characters');
my $called_next_review_char = 0;
$mock_characters->mock(_next_review_char => sub {
$called_next_review_char = 1;
return $mock_characters->original('_next_review_char')->(@_);
});
ok defined(JapaChar::Characters->new->next_char), 'The next char is defined.';
ok $called_next_review_char, 'The next char is a review.';
}