albertogoffi / toradocu

Toradocu - automated generation of test oracles from Javadoc documentation
Other
42 stars 21 forks source link

Translation for "an array of size n"; use type information #130

Open mernst opened 7 years ago

mernst commented 7 years ago

Consider this code from commons-math:

    /**
     * Utility function for allocating an array and filling it with {@code n}
     * samples generated by the given {@code sampler}.
     *
     * @param n Number of samples.
     * @param sampler Sampler.
     * @return an array of size {@code n}.
     */
    public static int[] sample(int n,
                               IntegerDistribution.Sampler sampler) {
        final int[] samples = new int[n];
        for (int i = 0; i < n; i++) {
            samples[i] = sampler.sample();
        }
        return samples;
    }

Toradocu generates, as the postcondition, return.equals(n).

There are two problems here (which I should have submitted as two separate issues!):

mernst commented 7 years ago

Here is another example of a type-incorrect assertion. Toradocu produces the post-condition return.equals(c) for this routine.

    /**
     * Converts a {@code Complex[]} array to a {@code double[]} array for the
     * range {@code start} - {@code end}.
     *
     * @param c {@code Complex} array
     * @param start start index
     * @param end end index
     * @return array of the real component
     *
     * @since 4.0
     */
    public static double[] complex2Real(Complex[] c, int start, int end) {
        final Range range = IntegerSequence.range(start, end);
        int index = 0;
        final double d[] = new double[range.size()];
        for (Integer i : range) {
            d[index] = extractRealFromComplexArray(c, i);
            index++;
        }
        return d;
    }