test.pl 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. use strict;
  2. use Text::WagnerFischer qw(distance);
  3. my $ko=0;
  4. my $test=1;
  5. my $first_distance=distance("foo","four");
  6. if ($first_distance == 2) {
  7. print $test.". ok\n"
  8. } else {
  9. print $test.". NO <--\n";
  10. $ko=1;
  11. }
  12. my $second_distance=distance("foo","foo");
  13. $test++;
  14. if ($second_distance == 0) {
  15. print $test.". ok\n"
  16. } else {
  17. print $test.". NO <--\n";
  18. $ko=1;
  19. }
  20. my $third_distance=distance([0,1,2],"foo","four");
  21. $test++;
  22. if ($third_distance == 3) {
  23. print $test.". ok\n"
  24. } else {
  25. print $test.". NO <--\n";
  26. $ko=1;
  27. }
  28. my @words=("four","foo","bar");
  29. my @distances=distance("foo",@words);
  30. $test++;
  31. if (($distances[0] == 2) and ($distances[1] == 0) and ($distances[2] == 3)) {
  32. print $test.". ok\n"
  33. } else {
  34. print $test.". NO <--\n";
  35. $ko=1;
  36. }
  37. @distances=distance([0,5,3],"foo",@words);
  38. $test++;
  39. if (($distances[0] == 8) and ($distances[1] == 0) and ($distances[2] == 9)) {
  40. print $test.". ok\n"
  41. } else {
  42. print $test.". NO <--\n";
  43. $ko=1;
  44. }
  45. if ($ko) {print "\nTest suite failed\n"} else {print "\nTest suite ok\n"}