From d039db6f4d722e6ce82e17ce767e38db3cc6469a Mon Sep 17 00:00:00 2001 From: nick_battle Date: Tue, 12 Sep 2023 17:25:24 +0100 Subject: [PATCH] Fix for range creators with single field records --- .../visitors/FixedRangeCreator.java | 24 +++++++++++------ .../visitors/RandomRangeCreator.java | 26 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/examples/quickcheck/src/main/java/quickcheck/visitors/FixedRangeCreator.java b/examples/quickcheck/src/main/java/quickcheck/visitors/FixedRangeCreator.java index ff5e89472..fc6df6e54 100644 --- a/examples/quickcheck/src/main/java/quickcheck/visitors/FixedRangeCreator.java +++ b/examples/quickcheck/src/main/java/quickcheck/visitors/FixedRangeCreator.java @@ -317,15 +317,19 @@ public ValueSet caseRecordType(TCRecordType node, Integer limit) // so that it will just exceed this. int limit2 = 1; + int fcount = node.fields.size(); - while (Math.pow(node.fields.size(), limit2) < limit) + if (fcount > 1) { - limit2++; + while (Math.pow(fcount, limit2) < limit) + { + limit2++; + } } ValueSet records = new ValueSet(); - List fvalues = new Vector(node.fields.size()); - int[] fsizes = new int[node.fields.size()]; + List fvalues = new Vector(fcount); + int[] fsizes = new int[fcount]; int f = 0; for (TCField field: node.fields) @@ -509,15 +513,19 @@ public ValueSet caseProductType(TCProductType node, Integer limit) // so that it will just exceed this. int limit2 = 1; + int tcount = node.types.size(); - while (Math.pow(node.types.size(), limit2) < limit) + if (tcount > 1) { - limit2++; + while (Math.pow(tcount, limit2) < limit) + { + limit2++; + } } ValueSet records = new ValueSet(); - List fvalues = new Vector(node.types.size()); - int[] fsizes = new int[node.types.size()]; + List fvalues = new Vector(tcount); + int[] fsizes = new int[tcount]; int f = 0; for (TCType field: node.types) diff --git a/examples/quickcheck/src/main/java/quickcheck/visitors/RandomRangeCreator.java b/examples/quickcheck/src/main/java/quickcheck/visitors/RandomRangeCreator.java index 90b5d1c71..8c6acd017 100644 --- a/examples/quickcheck/src/main/java/quickcheck/visitors/RandomRangeCreator.java +++ b/examples/quickcheck/src/main/java/quickcheck/visitors/RandomRangeCreator.java @@ -326,7 +326,7 @@ public ValueSet caseRecordType(TCRecordType node, Integer limit) { if (done.contains(node)) { - // return new ValueSet(); // recursing + return new ValueSet(); // recursing } done.add(node); @@ -335,15 +335,19 @@ public ValueSet caseRecordType(TCRecordType node, Integer limit) // so that it will just exceed this. int limit2 = 1; + int fcount = node.fields.size(); - while (Math.pow(node.fields.size(), limit2) < limit) + if (fcount > 1) { - limit2++; + while (Math.pow(fcount, limit2) < limit) + { + limit2++; + } } ValueSet records = new ValueSet(); - List fvalues = new Vector(node.fields.size()); - int[] fsizes = new int[node.fields.size()]; + List fvalues = new Vector(fcount); + int[] fsizes = new int[fcount]; int f = 0; for (TCField field: node.fields) @@ -526,15 +530,19 @@ public ValueSet caseProductType(TCProductType node, Integer limit) // so that it will just exceed this. int limit2 = 1; + int tcount = node.types.size(); - while (Math.pow(node.types.size(), limit2) < limit) + if (tcount > 1) { - limit2++; + while (Math.pow(tcount, limit2) < limit) + { + limit2++; + } } ValueSet records = new ValueSet(); - List fvalues = new Vector(node.types.size()); - int[] fsizes = new int[node.types.size()]; + List fvalues = new Vector(tcount); + int[] fsizes = new int[tcount]; int f = 0; for (TCType field: node.types)