[gnumeric] fuzzxml: sometimes permute attributes.



commit 59add4ecd51d353807857cb23a19e002bdd72829
Author: Morten Welinder <terra gnome org>
Date:   Thu Aug 12 09:50:49 2010 -0400

    fuzzxml: sometimes permute attributes.

 test/fuzzxml |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/test/fuzzxml b/test/fuzzxml
index 151cf85..f43c6a0 100755
--- a/test/fuzzxml
+++ b/test/fuzzxml
@@ -24,6 +24,7 @@ my $remove_tag_prob = 0.1 * $base_prob;
 my $remove_attr_prob = 0.1 * $base_prob;
 my $change_int_prob = $base_prob;
 my $copy_attr_value_prob = $base_prob;
+my $permute_attrs_prob = $base_prob;
 
 my %attr_range;
 
@@ -100,6 +101,14 @@ sub fuzz_attrs {
     my ($pa) = @_;
 
     my @l = @$pa;
+    if (@l > 2 && &doit ($permute_attrs_prob)) {
+	my @p = &random_permutation (@l / 2);
+	my @l2 = ();
+	foreach my $i (@p) {
+	    push @l2, $l[$i * 2], $l[$i * 2 + 1];
+	}
+	@l = @l2;
+    }
     for (my $i = 0; $i + 1 < @l; $i += 2) {
 	if (&doit ($remove_attr_prob)) {
 	    splice @l, $i, 2;
@@ -190,6 +199,22 @@ sub looks_like_int {
 }
 
 # -----------------------------------------------------------------------------
+# Return a random permutation of (0 ... $n-1)
+
+sub random_permutation {
+    my ($n) = @_;
+
+    my @src = (0 ... $n-1);
+    my @dst;
+    while (@src) {
+	my $i = int (rand() * @src);
+	push @dst, $src[$i];
+	splice @src, $i, 1;
+    }
+    return @dst;
+}
+
+# -----------------------------------------------------------------------------
 # Just like XML::Parse::Style::Tree::start, except attrs as list.
 
 sub MyStart {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]