1#!/usr/bin/perl 2use strict; 3use warnings; 4use Test::More tests => 8; 5 6use Finance::Currency::Convert; 7 8# test object creation 9my $converter = new Finance::Currency::Convert; 10ok($converter, 'object creation'); 11 12# test conversion to self 13my $amount0 = $converter->convert(456, "EUR", "EUR"); 14is($amount0, 456, 'convert EUR to self'); 15 16# test build in exchange rate 17my $amount1 = $converter->convert(1, "EUR", "DEM"); 18is($amount1, 1.95583, 'test build in exchange rate'); 19 20# test convertFromEUR 21my $amount2 = $converter->convert(1, "EUR", "DEM"); 22my $amount3 = $converter->convertFromEUR(1, "DEM"); 23is($amount2, $amount3, 'convertFromEUR'); 24 25# test convertToEUR 26my $amount4 = $converter->convert(1, "DEM", "EUR"); 27my $amount5 = $converter->convertToEUR(1, "DEM"); 28is($amount4, $amount5, 'convertToEUR'); 29 30# test conversion to self 31my $e = 0.0000001; # error tolerance for float comparison 32 33my $amount6 = $converter->convertToEUR(456.22, "MTL"); 34my $amount7 = $converter->convertFromEUR($amount6, "MTL"); 35ok(abs($amount7 - 456.22) <= $e, 'convert MTL to self'); 36 37my $amount8 = $converter->convertToEUR(789.74, "SKK"); 38my $amount9 = $converter->convertFromEUR($amount8, "SKK"); 39ok(abs($amount9 - 789.74) <= $e, 'convert SKK to self'); 40 41my $amount10 = $converter->convertToEUR(789.74, "EEK"); 42my $amount11 = $converter->convertFromEUR($amount10, "EEK"); 43ok(abs($amount11 - 789.74) <= $e, 'convert EEK to self'); 44 45