forked from ribbon-otter/evalmath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz.pl
More file actions
executable file
·40 lines (36 loc) · 1.25 KB
/
Copy pathfuzz.pl
File metadata and controls
executable file
·40 lines (36 loc) · 1.25 KB
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
#!/usr/bin/perl
#This fuzzer checks a bunch of syntax combinations and sees if they agree with
#perl's math engine
#This file is licensed under MIT-0
#Copyright 2026 Ribbon-otter
use warnings;
use strict;
use List::Util qw(first);
my $evalm_path = first {-f $_} ('./evalm', './build/evalm');
my $test_successful = "yes";
# this system isn't efficient, since it starts a new process for each generated
# forumla. However, it is good enough since I can just wait.
for my $i (0 .. 1_000_000) {
$_ = $i;
tr#0245678#.+\-*/()#;
#perl treats ++ and -- as special operation, so we skip those patterns
next if /\+\+|--/;
my $evalm = `$evalm_path '$_' 2> /dev/null`;
chomp $evalm;
if ($? == 0) {
my $evalp;
{
#local $SIG{__WARN__} = sub { }; #silense perl warnings
$evalp = eval "$_";
}
# unless (defined($evalp)) {next;} #skip ones perl can't parse
# print some samples to reassure me that tests are happening
print "$_\n" if rand() < 0.001;
unless ($evalp == $evalm) {
print "oh no: '$_' evalm '$evalm' vs perl '$evalp'\n";
$test_successful = "no";
}
}
}
print("was the test successful? $test_successful \n");
# vim: ts=4 sw=4 expandtab