File: TkTest.pm

package info (click to toggle)
perl-tk 1%3A804.027-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 30,204 kB
  • ctags: 33,761
  • sloc: ansic: 340,354; perl: 44,606; sh: 8,869; makefile: 5,658; asm: 996; yacc: 883; cpp: 570; pascal: 536
file content (48 lines) | stat: -rw-r--r-- 932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (C) 2003 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

package TkTest;

use strict;
use vars qw(@EXPORT $eps $VERSION);
$VERSION = sprintf '4.%03d', q$Revision: #3 $ =~ /\D(\d+)\s*$/;

use base qw(Exporter);
@EXPORT = qw(ok_float);

use POSIX qw(DBL_EPSILON);
use Test qw(ok);
$eps = DBL_EPSILON;


sub ok_float ($$;$) {
    my($value, $expected, $diag) = @_;
    my @value    = split /[\s,]+/, $value;
    my @expected = split /[\s,]+/, $expected;
    my $ok = 1;
    for my $i (0 .. $#value) {
	if ($expected[$i] =~ /^[\d+-]/) {
	    if (abs($value[$i]-$expected[$i]) > $eps) {
		$ok = 0;
		last;
	    }
	} else {
	    if ($value[$i] ne $expected[$i]) {
		$ok = 0;
		last;
	    }
	}
    }
    if ($ok) {
	@_ = (1, 1, $diag);
	goto &ok;
    } else {
	@_ = ($value, $expected, $diag);
	goto &ok;
    }
}

1;

__END__