Primero copiamos recursivamente el directorio original:
pp2@nereida:/tmp/$ cp -Rp Algorithm-Knap01DP-0.01 Algorithm-Knap01DP-0.01.new/
Luego hacemos los cambios y mejoras que consideremos necesarios:
pp2@nereida:/tmp/Algorithm-Knap01DP-0.01.new/lib/Algorithm$ vi Knap01DP.pm ......................................................................
Por supuesto, comprobamos que todo funciona correctamente y que las modificaciones corrigen los errores que hemos detectado:
pp2@nereida:/tmp/Algorithm-Knap01DP-0.01.new/lib/Algorithm$ perl -c Knap01DP.pm Knap01DP.pm syntax OK pp2@nereida:/tmp/Algorithm-Knap01DP-0.01.new/lib/Algorithm$ cd ../.. pp2@nereida:/tmp/Algorithm-Knap01DP-0.01.new$ make test TEST_VERBOSE=1 Skip blib/lib/Algorithm/newknap.patch (unchanged) cp lib/Algorithm/Knap01DP.pm blib/lib/Algorithm/Knap01DP.pm Skip blib/lib/Algorithm/Knap01DP.pm.original (unchanged) PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(1, 'blib/lib', 'blib/arch')" t/*.t t/01MartelloAndTothBook....1..12 ok 1 - use Algorithm::Knap01DP; ok 2 - ReadKnap knap21.dat ok 3 - Knap01DP knap21.dat ............................ All tests successful. Files=1, Tests=12, 0 wallclock secs ( 0.07 cusr + 0.01 csys = 0.08 CPU)
Entonces procedemos a crear el patch usando el programa diff
pp2@nereida:/tmp$ diff -ur Algorithm-Knap01DP-0.01 Algorithm-Knap01DP-0.01.new/ > newknap.patchLa opción
-u
indica que usaremos formato unificado para la representación de
las diferencias. Este es el formato mas usado en el intercambio de código entre desarrolladores.
La opción -r
indica que queremos que se analizen toda la jerarquía de ficehros y directorios
y se establezcan las diferencias entre ficheros, si estas existen.
El fichero newknap.patch
contiene una descripción de las diferencias
entre la vieja y la nueva versión:
pp2@nereida:/tmp$ cat -n newknap.patch 1 Sólo en Algorithm-Knap01DP-0.01.new/: blib 2 diff -ur Algorithm-Knap01DP-0.01/lib/Algorithm/Knap01DP.pm Algorithm-Knap01DP-0.01.new/lib/Algorithm/Knap01DP.pm 3 --- Algorithm-Knap01DP-0.01/lib/Algorithm/Knap01DP.pm 2005-05-20 07:40:28.000000000 +0100 4 +++ Algorithm-Knap01DP-0.01.new/lib/Algorithm/Knap01DP.pm 2008-05-16 08:04:12.000000000 +0100 5 @@ -4,6 +4,7 @@ 6 use warnings; 7 use Carp; 8 use IO::File; 9 +use List::Util qw{first}; 10 11 use Exporter; 12 our @ISA = qw(Exporter); 13 @@ -20,6 +21,7 @@ 14 my @f; 15 16 croak "Profits and Weights don't have the same size" unless scalar(@w) == scalar(@p); 17 + croak "Invalid weight/profit $_" if defined($_ = first { $_ <= 0 } (@w, @p)); 18 19 for my $c (0..$M) { 20 $f[0][$c] = ($w[0] <= $c)? $p[0] : 0; 21 Sólo en Algorithm-Knap01DP-0.01.new/lib/Algorithm: Knap01DP.pm.original 22 Sólo en Algorithm-Knap01DP-0.01.new/lib/Algorithm: newknap.patch 23 Sólo en Algorithm-Knap01DP-0.01.new/: Makefile 24 Sólo en Algorithm-Knap01DP-0.01.new/: pm_to_blib 25 diff -ur Algorithm-Knap01DP-0.01/t/01MartelloAndTothBook.t Algorithm-Knap01DP-0.01.new/t/01MartelloAndTothBook.t 26 --- Algorithm-Knap01DP-0.01/t/01MartelloAndTothBook.t 2005-05-20 07:40:04.000000000 +0100 27 +++ Algorithm-Knap01DP-0.01.new/t/01MartelloAndTothBook.t 2008-05-16 07:55:17.000000000 +0100 28 @@ -3,7 +3,7 @@ 29 30 ######################### 31 use strict; 32 -use Test::More tests => 11; 33 +use Test::More tests => 12; 34 35 BEGIN { use_ok('Algorithm::Knap01DP', qw/Knap01DP ReadKnap/); } 36 37 @@ -39,6 +39,11 @@ 38 eval { Knap01DP($M, $w, $p) }; 39 like $@, qr/Profits and Weights don't have the same size/; 40 41 +# test to check when weights and profits have negative value 42 +$M = 100; @$w = @$p = (1,7,-2,3..8); 43 +eval { Knap01DP($M, $w, $p) }; 44 +like $@, qr/Invalid weight/; 45 + 46 TODO: { # I plan to provide a function to find the vector solution ... 47 local $TODO = "Randomly generated problem"; 48 can_ok('Algorithm::Knap01DP', 'GenKnap');La cabecera
2 diff -ur Algorithm-Knap01DP-0.01/lib/Algorithm/Knap01DP.pm Algorithm-Knap01DP-0.01.new/lib/Algorithm/Knap01DP.pm 3 --- Algorithm-Knap01DP-0.01/lib/Algorithm/Knap01DP.pm 2005-05-20 07:40:28.000000000 +0100 4 +++ Algorithm-Knap01DP-0.01.new/lib/Algorithm/Knap01DP.pm 2008-05-16 08:04:12.000000000 +0100indica que las diferencias que siguen se refieren a los ficheros
Knap01DP.pm
.
Un rango como @@ -4,6 +4,7 @@
establece un trozo que ha cambiado.
Nos indica que las líneas de la 4 a la 4+6 del original han sido cambiadas
por las líneas de la 4 a la 4+7 en el nuevo.
La presencia del prefijo +
indica que se ha insertado una nueva línea:
+use List::Util qw{first};
Las restantes líneas son 'de contexto'.
Otro trozo que ha cambiado es @@ -20,6 +21,7 @@
17 + croak "Invalid weight/profit $_" if defined($_ = first { $_ <= 0 } (@w, @p));
Otro fichero que ha cambiado es 01MartelloAndTothBook.t
:
25 diff -ur Algorithm-Knap01DP-0.01/t/01MartelloAndTothBook.t Algorithm-Knap01DP-0.01.new/t/01MartelloAndTothBook.t 26 --- Algorithm-Knap01DP-0.01/t/01MartelloAndTothBook.t 2005-05-20 07:40:04.000000000 +0100 27 +++ Algorithm-Knap01DP-0.01.new/t/01MartelloAndTothBook.t 2008-05-16 07:55:17.000000000 +0100El trozo:
28 @@ -3,7 +3,7 @@ 29 30 ######################### 31 use strict; 32 -use Test::More tests => 11; 33 +use Test::More tests => 12; 34 35 BEGIN { use_ok('Algorithm::Knap01DP', qw/Knap01DP ReadKnap/); }indica que se cambió la línea
use Test::More tests => 11;
por use Test::More tests => 12;
Parece que se ha añadido una prueba. En efecto, vemos que se han insertado 5 nuevas líneas
que comprueban el buen funcionamiento de la función Knap01DP
cuando
se le pasan pesos/beneficios negativos:
37 @@ -39,6 +39,11 @@ 38 eval { Knap01DP($M, $w, $p) }; 39 like $@, qr/Profits and Weights don't have the same size/; 40 41 +# test to check when weights and profits have negative value 42 +$M = 100; @$w = @$p = (1,7,-2,3..8); 43 +eval { Knap01DP($M, $w, $p) }; 44 +like $@, qr/Invalid weight/; 45 + 46 TODO: { # I plan to provide a function to find the vector solution ... 47 local $TODO = "Randomly generated problem"; 48 can_ok('Algorithm::Knap01DP', 'GenKnap');
El último paso es enviar los cambios al autor del módulo. Via email o http://rt.cpan.org/.